<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
	xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0"
	xsi:schemaLocation="
		http://www.osgi.org/xmlns/blueprint/v1.0.0 
		http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

		http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
		http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd

		http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0
		http://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.1.xsd
">

	<bean id="queueNameFactory" class="org.opennms.core.camel.JmsQueueNameFactory">
		<argument value="Syslogd"/>
		<argument value="BroadcastSyslog"/>
	</bean>

	<cm:property-placeholder id="syslogHandlerDefaultProperties" persistent-id="org.opennms.netmgt.syslog.handler.default" update-strategy="none">
		<cm:default-properties>
			<cm:property name="queueName">
				<bean factory-ref="queueNameFactory" factory-method="getName"/>
			</cm:property>
		</cm:default-properties>
	</cm:property-placeholder>

	<bean id="syslogConnectionHandlerDefault" class="org.opennms.netmgt.syslogd.SyslogConnectionHandlerDefaultImpl"/>

	<!-- Don't register this as a service: we're only using it internally -->
	<!--
	<service interface="org.opennms.netmgt.syslogd.SyslogConnectionHandler" ref="syslogConnectionHandlerDefault"/>
	-->

	<!-- Camel Event marshalling processor -->
	<bean id="unmarshaller" class="org.opennms.core.camel.JaxbUtilsUnmarshalProcessor">
		<argument value="org.opennms.netmgt.syslogd.SyslogConnection" />
	</bean>

	<reference id="syslogdConfig" interface="org.opennms.netmgt.config.SyslogdConfig" />
	
	<bean id="syslogdConfigProcessor" class="org.opennms.netmgt.syslogd.SyslogdConfigProcessor">
		<argument ref="syslogdConfig"/>
	</bean>

	<reference id="queuingservice" interface="org.apache.camel.Component" filter="(alias=onms.broker)"/>

	<!-- @see http://www.davsclaus.com/2012/06/locking-down-jmx-naming-now-easier-with.html -->
	<camelContext id="syslogdHandlerDefaultContext" managementNamePattern="#name#" xmlns="http://camel.apache.org/schema/blueprint">
		<propertyPlaceholder id="properties" location="blueprint:syslogHandlerDefaultProperties" />

		<route id="receiveSyslogConnection">
			<from uri="queuingservice:{{queueName}}?concurrentConsumers=8"/>
			<!-- No performance improvement with asyncConsumer -->
			<!-- <from uri="activemq:{{queueName}}?asyncConsumer=true&amp;concurrentConsumers=8"/> -->
			<to uri="seda:unmarshalMessage"/>
		</route>

		<route id="unmarshalSyslogConnection">
			<from uri="seda:unmarshalMessage?concurrentConsumers=8"/>
			<process ref="unmarshaller"/>
			<!-- Update the SyslogdConfig on the message to the local config value -->
			<bean ref="syslogdConfigProcessor"/>
			<to uri="seda:syslogHandler"/>
		</route>

		<route id="handleSyslogConnection">
			<from uri="seda:syslogHandler?concurrentConsumers=8"/>
			<!-- 
				Pass the message to the default handler which will convert it into
				an event and broadcast the event.
			-->
			<bean ref="syslogConnectionHandlerDefault"/>
		</route>
	</camelContext>

</blueprint>
