Search in sources :

Example 16 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class StatisticsMBeanCase method register.

protected void register(Collection<BaseComponentMBean> mBeans) throws Exception {
    for (BaseComponentMBean bean : mBeans) {
        ObjectName name = bean.createObjectName();
        registeredObjects.add(name);
        mBeanServer.registerMBean(bean, name);
        log.trace("MBean [" + bean + "] registered");
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) ObjectName(javax.management.ObjectName)

Example 17 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class StatisticsMBeanCase method testGetTimesliceDuration.

@Test
public void testGetTimesliceDuration() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName);
        MetricsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MetricsMBean.class);
        WorkflowManagerMBean workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        assertEquals(10, stats.getTimeSliceDurationSeconds());
    } finally {
        stop(adapter);
    }
}
Also used : WorkflowManagerMBean(com.adaptris.core.runtime.WorkflowManagerMBean) BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 18 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class StatisticsMBeanCase method testGet_NoTimeslicesAvailable.

@Test
public void testGet_NoTimeslicesAvailable() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName);
        MetricsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MetricsMBean.class);
        WorkflowManagerMBean workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        assertEquals(0, stats.getNumberOfTimeSlices());
    } finally {
        stop(adapter);
    }
}
Also used : WorkflowManagerMBean(com.adaptris.core.runtime.WorkflowManagerMBean) BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 19 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_ErrorThresholdExceeded.

@Test
public void testNotification_ErrorThresholdExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setErrorThreshold(0L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new AlwaysFailService());
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        workflow.onAdaptrisMessage(msg);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals("11", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_SIZE));
        assertEquals("1", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_COUNT));
        assertEquals("1", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_ERROR));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 20 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_CountThresholdExceeded.

@Test
public void testNotification_CountThresholdExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setCountThreshold(0L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        workflow.onAdaptrisMessage(msg);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals("11", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_SIZE));
        assertEquals("1", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_COUNT));
        assertEquals("0", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_ERROR));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)29 ObjectName (javax.management.ObjectName)26 Adapter (com.adaptris.core.Adapter)25 Test (org.junit.Test)24 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)16 StandardWorkflow (com.adaptris.core.StandardWorkflow)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 Notification (javax.management.Notification)10 TimeInterval (com.adaptris.util.TimeInterval)9 Properties (java.util.Properties)6 WorkflowManagerMBean (com.adaptris.core.runtime.WorkflowManagerMBean)5 SerializableAdaptrisMessage (com.adaptris.core.SerializableAdaptrisMessage)3 AdapterManager (com.adaptris.core.runtime.AdapterManager)3 AlwaysFailService (com.adaptris.core.services.AlwaysFailService)3 WaitService (com.adaptris.core.services.WaitService)3 MessageProcessor (com.adaptris.interlok.management.MessageProcessor)2 ArrayList (java.util.ArrayList)2 ChildRuntimeInfoComponent (com.adaptris.core.runtime.ChildRuntimeInfoComponent)1