<?xml version="1.0" encoding="UTF-8"?>
<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - JASMINe
 - Copyright (C) 2007-2010 Bull S.A.S.
 - Contact: jasmine@ow2.org
 -
 - This library is free software; you can redistribute it and/or
 - modify it under the terms of the GNU Lesser General Public
 - License as published by the Free Software Foundation; either
 - version 2.1 of the License, or any later version.
 -
 - This library is distributed in the hope that it will be useful,
 - but WITHOUT ANY WARRANTY; without even the implied warranty of
 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 - Lesser General Public License for more details.
 -
 - You should have received a copy of the GNU Lesser General Public
 - License along with this library; if not, write to the Free Software
 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 - USA
 -
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - $Id: eventswitch-config.xml 6306 2010-04-12 21:19:48Z alitokmen $
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-->
<!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN"
                                "http://mule.mulesource.org/dtds/mule-configuration.dtd">
<mule-configuration id="JASMINe_Event_Switch" version="1.0">

  <!--
    Set the serverUrl to an empty string to avoid
    multiple Mule instances fighting over port 60504
    -->
  <mule-environment-properties workingDirectory="work/mule"
    recoverableMode="true" serverUrl="" synchronous="false" >
    <!--
      The queue-profile also has an attribute called maxOutstandingMessages
      for limiting the number of messages in the queue
      -->
    <queue-profile persistent="true"/>
    <persistence-strategy className="org.mule.util.queue.FilePersistenceStrategy"/>
  </mule-environment-properties>

  <agents>
    <agent name="JmxAgent" className="org.mule.management.agents.JmxAgent"/>
  </agents>

  <connector name="JMSConnector" className="org.mule.providers.jms.JmsConnector">
    <properties>
      <property name="connectionFactoryJndiName" value="JTCF"/>
      <property name="jndiProviderUrl" value="rmi://localhost:1099"/>
      <property name="jndiInitialFactory" value="org.ow2.carol.jndi.spi.MultiOrbInitialContextFactory"/>
      <property name="specification" value="1.1"/>
      <property name="jndiDestinations" value="true"/>
      <property name="username" value="anonymous"/>
      <property name="password" value="anonymous"/>
    </properties>

    <!--
      By default, the events switch will NOT start as long as JMS
      resource unavailable. To avoid this and retry JMS connectivity
      after startup, use the following configuration options:

      <connection-strategy className="org.mule.providers.SimpleRetryConnectionStrategy">
        <properties>
          <property name="retryCount" value="-1"/>
          <property name="frequency" value="30000"/>
        </properties>
      </connection-strategy>
    -->
  </connector>

  <!-- log
  <connector name="FileConnector" className="org.mule.providers.file.FileConnector">
    <properties>
      <property name="writeToDirectory" value="__INSTALL_PATH__/csv" />
      <property name="outputPattern" value="jasmine-monitoring" />
      <property name="outputAppend" value="true" />
    </properties>
  </connector>
  log -->

  <transformers>
    <transformer name="JasmineEventToString"
      className="org.ow2.jasmine.monitoring.eventswitch.transformers.JasmineEventToString" />
    <transformer name="JasmineEventToCSV"
      className="org.ow2.jasmine.monitoring.eventswitch.transformers.JasmineEventToCSV" />
    <transformer name="JasmineEventNotificationToString"
      className="org.ow2.jasmine.monitoring.eventswitch.transformers.JasmineEventNotificationToString" />
    <transformer name="JasmineEventNotificationToCSV"
      className="org.ow2.jasmine.monitoring.eventswitch.transformers.JasmineEventNotificationToCSV" />

    <!-- This transformer takes a JMSTextMessage and convert it in a JasmineEventEB -->
    <transformer name="JMSTextMessageToJasmineEvent"
      className="org.ow2.jasmine.monitoring.eventswitch.transformers.JMSTextMessageToJasmineEvent" >
      <properties>
        <property name="sourceName" value="eventSwitchIn"/>
        <property name="domainName" value="sampleDomain"/>
        <property name="serverName" value="sampleServer"/>
        <property name="sname" value="vm://JasmineEventDispatcher"/>
      </properties>
    </transformer>
  </transformers>

  <model name="EventSwitch">

    <!--
      MBeanCmd dispatcher get MBeandCmd messages (local or remote) and routes them to I/O or a database
      -->
    <mule-descriptor name="MBeanCmd_dispatcher"
     implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.MBeanCmdDispatcher">

      <inbound-router>

        <!-- This endpoint receives MBeanCmd messages from an embedded MBeanCmd -->
        <endpoint address="vm://MBeanCmd_dispatcher" />

        <!--
          This endpoint receives MBeanCmd messages from a remote MBeanCmd.
          You can configure the TCP port.
          -->
        <endpoint address="tcp://localhost:18564/MBeanCmd" />

      </inbound-router>

      <outbound-router>
        <router className="org.mule.routing.outbound.MulticastingRouter">

          <!-- This endpoint displays MBeanCmd messages on the console -->
          <!-- console
          <endpoint address="stream://System.out" transformers="JasmineEventToCSV" />
          console -->

          <!-- This endpoint write MBeanCmd messages on a file in the CSV format -->
          <!-- log
          <endpoint address="file://__INSTALL_PATH__/csv" connector="FileConnector" transformers="JasmineEventToCSV" />
          log -->

          <!-- This endpoint dispatches MBeanCmd messages to a stateless session bean -->
          <!-- database
          <endpoint address="vm://JasmineEventEJB3Wrapper" />
          database -->

          <!-- This endpoint dispatches MBeanCmd messages to a JMS topic -->
          <!-- eos
          <endpoint address="jms://jasmine" connector="JMSConnector"/>
          eos -->

          <!-- This endpoint dispatches MBeanCmd messages to a stateless session bean -->
          <!-- drools
          <endpoint address="vm://DroolsUMOComponent" />
          drools -->

          <!-- This endpoint dispatches MBeanCmd messages to a WildCAT context -->
          <!-- wildcat
          <endpoint address="vm://WildCATUMOComponent" />
          wildcat -->

          <filter
           expectedType="org.ow2.jasmine.event.messages.JasmineEvent"
           className="org.mule.routing.filters.PayloadTypeFilter" />
        </router>
      </outbound-router>

    </mule-descriptor>

    <!--
      JASMINe Events dispatcher
      -->
    <mule-descriptor name="JasmineEvent_dispatcher"
     implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.JasmineEventDispatcher">
      <inbound-router>

        <!-- This endpoint receives MBeanCmd messages from an embedded MBeanCmd -->
        <endpoint address="vm://JasmineEventDispatcher" />

        <!--
          This endpoint receives MBeanCmd messages from a remote MBeanCmd.
          You can configure the TCP port.
          -->
        <endpoint address="tcp://localhost:18565/JasmineEventDispatcher" />

      </inbound-router>

      <outbound-router>
        <router className="org.mule.routing.outbound.MulticastingRouter">

          <!-- This endpoint displays MBeanCmd messages on the console -->
          <!-- console
          <endpoint address="stream://System.out" transformers="JasmineEventToCSV" />
          console -->

          <!-- This endpoint dispatches MBeanCmd messages to a stateless session bean -->
          <!-- database
          <endpoint address="vm://JasmineEventEJB3Wrapper" />
          database -->

          <!-- This endpoint dispatches MBeanCmd messages to a JMS topic -->
          <!-- eos
          <endpoint address="jms://jasmine" connector="JMSConnector"/>
          eos -->

          <!-- This endpoint dispatches MBeanCmd messages to a stateless session bean -->
          <!-- drools
          <endpoint address="vm://DroolsUMOComponent" />
          drools -->

          <!-- This endpoint dispatches MBeanCmd messages to a WildCAT context -->
          <!-- wildcat
          <endpoint address="vm://WildCATUMOComponent" />
          wildcat -->

          <filter
           expectedType="org.ow2.jasmine.event.messages.JasmineEvent"
           className="org.mule.routing.filters.PayloadTypeFilter" />
        </router>
      </outbound-router>

    </mule-descriptor>

    <!--
      Description of the embedded MBeanCmd instance(s)
      -->
    <mule-descriptor name="MBeanCmd_wrapper"
     implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.MBeanCmdWrapper">

      <!--
        Set MBeanCmd arguments here

        See the MBeanCmd documentation on:
        http://wiki.jasmine.objectweb.org/xwiki/bin/view/Documentation/MBeanCmd
        -->
      <properties>
        <text-property name="configuration">
          <!--
            Each new MBeanCmd command has to be on separated lines, as a new
            command is set on each new line.

            In this embedded version of MBeanCmd, we can use a Resource Adapter
            which provides a pool of JMX connections to reach the server to
            monitor with MBeanCmd. If the RA corresponding to the target is not
            deployed, a non managed JMX connection is opened.

            To build and deploy the specific RA, refer to the JMXConnectionRA.
            Just know that the JNDI name of the RA has to be specific, so
            MBeanCmd will automatically find it and use it. The entire way to
            set it is described in the JMXConnectionRA subproject.
            -->

          stat -p 5 -name "*:j2eeType=JVM,*" -a allThreadsCount -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"
          poll -p 10 -jcacf "*:j2eeType=JCAConnectionFactory,name=jdbc_1,*" -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"
          poll -p 5 -cpusun -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"
          stat -p 10 -name "java.lang:type=Memory" -a HeapMemoryUsage -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"
          stat -p 10 -name "java.lang:type=Memory" -a NonHeapMemoryUsage -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"
          stat -p 2 -name Mule.JASMINe_Event_Switch:type=org.mule.Component,name="MBeanCmd_dispatcher" -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jasmine-monitoring -jasmine "vm://MBeanCmd_dispatcher"

          <!--
            Other examples :

            stat -p 10 -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas -name "*:j2eeType=JVM,*" -a allThreadsCount -jasmine "vm://MBeanCmd_dispatcher"
            stat -p 10 -name "joramClient:type=queue,*" -jasmine "vm://MBeanCmd_dispatcher"
            poll -p 10 -ds "*:j2eeType=JDBCDataSource,*" -jasmine "vm://MBeanCmd_dispatcher"
            poll -p 5 -cpusun -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas -jasmine "vm://MBeanCmd_dispatcher"
            monologjmx -target service:jmx:rmi:///jndi/rmi://localhost:1099/jrmpconnector_jonas -jasmine "vm://MBeanCmd_dispatcher"
            -->
        </text-property>
      </properties>

    </mule-descriptor>

    <!--
      Description of the EJB3 which persists MBeanCmd messages in a database
      -->
    <!-- database
    <mule-descriptor name="JasmineEventEJB3Wrapper"
     implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.JasmineEventEJB3Wrapper">
      <inbound-router>
        <endpoint address="vm://JasmineEventEJB3Wrapper" />
      </inbound-router>
      <properties>
        <map name="configuration">
          <property name="Wrapper.LOOKUP_BEAN"
           value="db-ejb/event" />
        </map>
      </properties>
    </mule-descriptor>
    database -->

    <!--
      Description of the EJB3 which inserts events in the Drools working memory
      -->
    <!-- drools
    <mule-descriptor name="DroolsUMOComponent"
      implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.DroolsUMOComponent">
      <inbound-router>
        <endpoint address="vm://DroolsUMOComponent" />
      </inbound-router>
      <properties>
        <map name="configuration">
          <property name="Wrapper.LOOKUP_BEAN"
            value="org.ow2.jasmine.monitoring.eventswitch.beans.impl.JasmineEventSFBImpl_org.ow2.jasmine.monitoring.eventswitch.beans.JasmineEventSFBRemote@Remote" />
        </map>
      </properties>
    </mule-descriptor>
    drools -->

    <!--
      Description of the EJB3 which inserts events in the WildCAT context
      -->
    <!-- wildcat
    <mule-descriptor name="WildCATUMOComponent"
      implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.WildCATUMOComponent">

      <inbound-router>
        <endpoint address="vm://WildCATUMOComponent" />
      </inbound-router>

      <properties>
        <map name="configuration">
          <property name="Wrapper.LOOKUP_BEAN"
            value="org.ow2.jasmine.monitoring.eventswitch.beans.impl.JasmineEventWildCAT_org.ow2.jasmine.monitoring.eventswitch.beans.JasmineEventWildCATRemote@Remote" />
        </map>
      </properties>
    </mule-descriptor>
    wildcat -->

    <!--
      JasmineEventNotificationMailWrapper provides a wrapper that sends
      notification as a mail
      -->
    <!-- drools
    <mule-descriptor name="JasmineEventNotificationMailWrapper" implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.MailSenderWrapper">
      <inbound-router>
        <endpoint address="vm://JasmineEventNotificationMailWrapper" />
      </inbound-router>
      <properties>
        <map name="configuration">
          <property name="Wrapper.LOOKUP_BEAN" value="JASMINeMailSession" />
        </map>
      </properties>
    </mule-descriptor>
    drools -->

    <!--
      JMSNotification_dispatcher describes how to send a received JMS messages
      on differents outgoing endpoints
      -->
    <mule-descriptor name="JMSNotification_dispatcher" implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.JasmineEventNotificationDispatcher">
      <inbound-router>
        <endpoint address="jms://topic:jasmineNotification" connector="JMSConnector"/>
      </inbound-router>
      <outbound-router>
        <router className="org.mule.routing.outbound.MulticastingRouter">
          <endpoint address="vm://JasmineEventNotificationEJB3Wrapper" />
          <filter
           expectedType="org.ow2.jasmine.event.beans.JasmineEventNotification"
           className="org.mule.routing.filters.PayloadTypeFilter" />
        </router>
      </outbound-router>
    </mule-descriptor>

    <!--
      Description of the EJB3 which persists a notification in a database
      -->
    <mule-descriptor name="JasmineEventNotificationEJB3Wrapper" implementation="org.ow2.jasmine.monitoring.eventswitch.endpoints.JasmineEventNotificationEJB3Wrapper">
      <inbound-router>
        <endpoint address="vm://JasmineEventNotificationEJB3Wrapper" />
      </inbound-router>
      <properties>
        <map name="configuration">
          <property name="Wrapper.LOOKUP_BEAN" value="db-ejb/notification" />
        </map>
      </properties>
    </mule-descriptor>

  </model>

</mule-configuration>
