<?xml version="1.0" encoding="UTF-8"?>
<!--
    R Service Bus
    
    Copyright (c) Copyright of OpenAnalytics BVBA, 2010-2014
 
    ===========================================================================
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program 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 Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
        
    @author rsb.development@openanalytics.eu
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Uncomment to enable security
    <bean id="jmxAuthenticator" class="eu.openanalytics.rsb.security.JmxSecurityAuthenticator"
        c:configuration-ref="configuration" />
    -->
    <util:map id="jmxEnvironment">
        <!-- Uncomment to enable security
        <entry key="jmx.remote.authenticator" value-ref="jmxAuthenticator" />
        -->
    </util:map>

    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"
        p:locateExistingServerIfPossible="true" />

    <bean id="mx4jXsltProcessor" class="mx4j.tools.adaptor.http.XSLTProcessor" />
    <bean id="mx4jHttpAdaptor" class="eu.openanalytics.rsb.security.SecurableMx4JHttpAdaptor"
        c:configuration-ref="configuration" init-method="start" destroy-method="stop"
        p:host="0.0.0.0" p:port="#{configuration.jmxConfiguration.httpPort}"
        p:processor-ref="mx4jXsltProcessor">
    </bean>

    <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter"
        lazy-init="false">
        <property name="beans">
            <map>
                <entry key="rsb:name=Configuration" value-ref="configuration" />
                <entry key="rsb:domain=jms,name=GlobalJobMessageListener"
                    value-ref="globalJobMessageListener" />
                <entry key="rsb:domain=jms,name=RestResultMessageListener"
                    value-ref="restResultMessageListener" />
                <entry key="rsb:domain=jms,name=DirectoryResultMessageListener"
                    value-ref="directoryResultMessageListener" />
                <entry key="rsb:domain=jms,name=EmailResultMessageListener"
                    value-ref="emailResultMessageListener" />
                <entry key="rsb:domain=jms,name=DlqMessageListener"
                    value-ref="dlqMessageListener" />
                <entry key="rsb:domain=service,name=JaxwsMtomJobEndpoint"
                    value-ref="jaxwsMtomJobEndpoint" />
                <entry key="rsb:domain=service,name=JaxrsRestServer"
                    value-ref="jaxrsRestServer" />
                <entry
                    key="rsb:domain=service,name=DirectoryDepositServiceActivator"
                    value-ref="directoryDepositServiceActivator" />
                <entry key="rsb:domain=service,name=EmailDepositServiceActivator"
                    value-ref="emailDepositServiceActivator" />
                <entry key="mx4j:name=HttpAdaptor" value-ref="mx4jHttpAdaptor" />
            </map>
        </property>
        <property name="server" ref="mbeanServer" />
    </bean>

    <bean class="org.springframework.jmx.support.ConnectorServerFactoryBean"
        p:objectName="connector:name=rmi"
        p:serviceUrl="service:jmx:rmi://localhost:#{configuration.jmxConfiguration.stubPort}/jndi/rmi://localhost:#{configuration.jmxConfiguration.registryPort}/jmxRMIConnector"
        p:environmentMap-ref="jmxEnvironment"
        p:registrationPolicy="IGNORE_EXISTING" depends-on="rmiRegistry" />

    <bean id="rmiRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"
        p:port="#{configuration.jmxConfiguration.registryPort}" />
</beans>
