Search in sources :

Example 1 with MessageProcessor

use of com.adaptris.interlok.management.MessageProcessor in project interlok by adaptris.

the class MessageMetricsStatisticsByMetadataTest method testGetMessageStatistics.

@Override
public void testGetMessageStatistics() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    String payload = "SomePayload";
    MessageMetricsInterceptorByMetadata interceptor = createInterceptor();
    interceptor.setUniqueId(getName());
    Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
        MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class);
        MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        workflow.processAsync(createMessageForInjection(payload));
        assertEquals(1, stats.getStatistics().size());
        assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
        MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
        MessageStatistic mbeanStat = stats.getStatistics().get(0);
        // They're not objectively equals (not clones), and no equals method.
        assertNotSame(interceptorStat, mbeanStat);
        assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
        assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
        assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
        assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName)

Example 2 with MessageProcessor

use of com.adaptris.interlok.management.MessageProcessor in project interlok by adaptris.

the class MessageMetricsStatisticsTest method testGetMessageStatistics.

@Test
public void testGetMessageStatistics() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    String payload = "SomePayload";
    MessageMetricsInterceptor interceptor = (MessageMetricsInterceptor) createInterceptor();
    interceptor.setUniqueId(getName());
    Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
        MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class);
        MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        workflow.processAsync(createMessageForInjection(payload));
        assertEquals(1, stats.getStatistics().size());
        assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
        MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
        MessageStatistic mbeanStat = stats.getStatistics().get(0);
        // They're not objectively equals (not clones), and no equals method.
        assertNotSame(interceptorStat, mbeanStat);
        assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
        assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
        assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
        assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with MessageProcessor

use of com.adaptris.interlok.management.MessageProcessor in project interlok by adaptris.

the class WorkflowManagerTest method testProcess.

@Test
public void testProcess() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableMessage msg = createSM(msgUniqueId);
    try {
        register(mBeans);
        MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        adapterManager.requestStart();
        SerializableMessage reply = workflowManagerProxy.process(msg);
        assertEquals(msgUniqueId, reply.getUniqueId());
        assertEquals(PAYLOAD, reply.getContent());
        assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
        Map<String, String> headers = reply.getMessageHeaders();
        assertTrue(headers.containsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, headers.get(METADATA_KEY));
        assertTrue(headers.containsKey(getName()));
        assertEquals(getName(), headers.get(getName()));
        assertEquals("", reply.getNextServiceId());
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) ObjectName(javax.management.ObjectName) StubSerializableMessage(com.adaptris.core.stubs.StubSerializableMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 4 with MessageProcessor

use of com.adaptris.interlok.management.MessageProcessor in project interlok by adaptris.

the class WorkflowManagerTest method testProcessAsync.

@Test
public void testProcessAsync() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    MockMessageProducer mockProducer = new MockMessageProducer();
    workflow.setProducer(mockProducer);
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableMessage msg = createSM(msgUniqueId);
    try {
        register(mBeans);
        MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        adapterManager.requestStart();
        workflowManagerProxy.processAsync(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage procMsg = mockProducer.getMessages().get(0);
        assertEquals(msgUniqueId, procMsg.getUniqueId());
        assertEquals(PAYLOAD, procMsg.getContent());
        assertEquals(PAYLOAD_ENCODING, procMsg.getContentEncoding());
        assertTrue(procMsg.headersContainsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, procMsg.getMetadataValue(METADATA_KEY));
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) StubSerializableMessage(com.adaptris.core.stubs.StubSerializableMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 5 with MessageProcessor

use of com.adaptris.interlok.management.MessageProcessor in project interlok by adaptris.

the class InterlokJmxClient method findWorkflow.

private MessageProcessor findWorkflow(MessageTarget target) throws InterlokException {
    MessageProcessor workflowProxy = null;
    try {
        ObjectName queryName = ObjectName.getInstance(String.format(JMX_WORKFLOW_MANAGER_NAME, target.getAdapter(), target.getChannel(), target.getWorkflow()));
        MBeanServerConnection mbeanServer = getConnection();
        ArrayList<ObjectName> names = new ArrayList(mbeanServer.queryNames(queryName, null));
        if (names.size() == 0 || names.size() > 1) {
            throw new InterlokException(queryName + " does not narrow to a single workflow");
        }
        workflowProxy = JMX.newMBeanProxy(mbeanServer, names.get(0), MessageProcessor.class);
    } catch (Exception e) {
        rethrowInterlokException(e);
    }
    return workflowProxy;
}
Also used : InterlokException(com.adaptris.interlok.InterlokException) ExceptionHelper.rethrowInterlokException(com.adaptris.interlok.client.jmx.ExceptionHelper.rethrowInterlokException) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) MBeanServerConnection(javax.management.MBeanServerConnection) InterlokException(com.adaptris.interlok.InterlokException) IOException(java.io.IOException) ExceptionHelper.rethrowInterlokException(com.adaptris.interlok.client.jmx.ExceptionHelper.rethrowInterlokException) ObjectName(javax.management.ObjectName)

Aggregations

MessageProcessor (com.adaptris.interlok.management.MessageProcessor)5 ObjectName (javax.management.ObjectName)5 Adapter (com.adaptris.core.Adapter)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Channel (com.adaptris.core.Channel)2 StandardWorkflow (com.adaptris.core.StandardWorkflow)2 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)2 StubSerializableMessage (com.adaptris.core.stubs.StubSerializableMessage)2 SerializableMessage (com.adaptris.interlok.types.SerializableMessage)2 GuidGenerator (com.adaptris.util.GuidGenerator)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 MetadataElement (com.adaptris.core.MetadataElement)1 SerializableAdaptrisMessage (com.adaptris.core.SerializableAdaptrisMessage)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)1 InterlokException (com.adaptris.interlok.InterlokException)1 ExceptionHelper.rethrowInterlokException (com.adaptris.interlok.client.jmx.ExceptionHelper.rethrowInterlokException)1 IOException (java.io.IOException)1 MBeanServerConnection (javax.management.MBeanServerConnection)1