<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="Trapd"/>
		<argument value="BroadcastTrap"/>
	</bean>

	<cm:property-placeholder id="trapHandlerDefaultProperties" persistent-id="org.opennms.netmgt.trapd.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>

	<!-- Get a reference to the org.opennms.netmgt.dao.api.InterfaceToNodeCache -->
	<reference id="interfaceToNodeCache" interface="org.opennms.netmgt.dao.api.InterfaceToNodeCache" availability="mandatory"/>

	<!-- Get a reference to the org.opennms.netmgt.events.api.EventForwarder -->
	<reference id="eventForwarder" interface="org.opennms.netmgt.events.api.EventForwarder" availability="mandatory"/>

	<!-- Get a reference to the org.opennms.netmgt.config.api.EventConfDao -->
	<reference id="eventConfDao" interface="org.opennms.netmgt.config.api.EventConfDao" availability="mandatory"/>

	<!-- Get a reference to the org.opennms.netmgt.config.TrapdConfig -->
	<reference id="trapdConfig" interface="org.opennms.netmgt.config.TrapdConfig" availability="mandatory"/>

	<bean id="newSuspectOnTrap" factory-ref="trapdConfig" factory-method="getNewSuspectOnTrap"/>

	<bean id="processorFactory" class="org.opennms.netmgt.trapd.TrapQueueProcessorFactory">
		<property name="eventConfDao" ref="eventConfDao"/>
		<property name="eventForwarder" ref="eventForwarder"/>
		<property name="newSuspect" ref="newSuspectOnTrap"/>
	</bean>

	<bean id="trapNotificationHandlerDefault" class="org.opennms.netmgt.trapd.TrapNotificationHandlerDefaultImpl">
		<property name="interfaceToNodeCache" ref="interfaceToNodeCache"/>
		<property name="processorFactory" ref="processorFactory"/>
	</bean>

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

	<!-- Reduces the graceful shutdown time from 300 to 15 seconds. -->
	<bean id="shutdownStrategy" class="org.apache.camel.impl.DefaultShutdownStrategy">
		<property name="timeout" value="15"/>
	</bean>

	<bean id="unmarshaller" class="org.opennms.core.camel.JaxbUtilsUnmarshalProcessor">
		<argument value="org.opennms.netmgt.trapd.TrapDTO" />
	</bean>

	<bean id="mapper" class="org.opennms.netmgt.trapd.TrapDTOToObjectProcessor"/>

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

		<route id="receiveTrapConnection">
			<from uri="queuingservice:{{queueName}}?disableReplyTo=true" />
			<!-- TODO: Change these to <process> tags once Trapd is loaded from inside Karaf -->
			<bean ref="unmarshaller"/>
			<bean ref="mapper"/>
			<to uri="seda:trapHandler?size=25000"/>
		</route>

		<route id="trapHandler">
			<from uri="seda:trapHandler?concurrentConsumers=8&amp;size=25000&amp;blockWhenFull=true" />
			<convertBodyTo type="org.opennms.netmgt.snmp.TrapNotification" />
			<!--
				Pass the message to the default handler which will convert it into 
				an event and broadcast the event.
			-->
			<bean ref="trapNotificationHandlerDefault" />
		</route>
	</camelContext>

</blueprint>
