コード例 #1
0
 @Test
 public void testLifecycleInEndpointWithMessageSource() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "lifecycle-source.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
   assertEquals(0, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null);
   assertEquals(1, names.size());
   MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
   String startName = null;
   for (MBeanOperationInfo info : operations) {
     String name = info.getName();
     if (name.startsWith("start")) {
       startName = name;
     }
   }
   // Lifecycle method name
   assertEquals("start", startName);
   assertTrue((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
   messageChannelsMonitor.stopActiveComponents(false, 3000);
   assertFalse((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
   ActiveChannel activeChannel = context.getBean("activeChannel", ActiveChannel.class);
   assertTrue(activeChannel.isStopCalled());
   OtherActiveComponent otherActiveComponent = context.getBean(OtherActiveComponent.class);
   assertTrue(otherActiveComponent.isBeforeCalled());
   assertTrue(otherActiveComponent.isAfterCalled());
 }
コード例 #2
0
  public void testTwoManagedCamelContextNoClashDefault() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    camel1 = createCamelContext("foo", null);
    camel2 = createCamelContext("foo", null);

    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());

    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on =
        ObjectName.getInstance(
            "org.apache.camel:context="
                + camel1.getManagementName()
                + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    // the default name pattern will ensure the JMX names is unique
    camel2.start();
    ObjectName on2 =
        ObjectName.getInstance(
            "org.apache.camel:context="
                + camel2.getManagementName()
                + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));

    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
  }
コード例 #3
0
 @Test
 public void testLifecycleInEndpointWithoutMessageSource() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
   assertEquals(1, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
   assertEquals(1, names.size());
   MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
   String startName = null;
   for (MBeanOperationInfo info : operations) {
     String name = info.getName();
     if (name.startsWith("start")) {
       startName = name;
     }
   }
   // Lifecycle method name
   assertEquals("start", startName);
 }
コード例 #4
0
  public void testTwoManagedCamelContextNoClashCustomPattern() throws Exception {
    camel1 = createCamelContext("foo", "killer-#counter#");
    camel2 = createCamelContext("foo", "killer-#counter#");

    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());

    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on =
        ObjectName.getInstance(
            "org.apache.camel:context="
                + camel1.getManagementName()
                + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    // the pattern has a counter so no clash
    camel2.start();
    ObjectName on2 =
        ObjectName.getInstance(
            "org.apache.camel:context="
                + camel2.getManagementName()
                + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));

    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
  }
コード例 #5
0
  public void testManageStatistics() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());

    ObjectName on = set.iterator().next();

    // use route to get the total time
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());

    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(5);

    // send in 5 messages
    template.sendBody("direct:start", "A");
    template.sendBody("direct:start", "B");
    template.sendBody("direct:start", "C");
    template.sendBody("direct:start", "D");
    template.sendBody("direct:start", "E");

    assertMockEndpointsSatisfied();

    // should be 5 on the route
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(5, completed.longValue());

    String first = (String) mbeanServer.getAttribute(on, "FirstExchangeCompletedExchangeId");
    assertEquals(result.getReceivedExchanges().get(0).getExchangeId(), first);

    String firstFail = (String) mbeanServer.getAttribute(on, "FirstExchangeFailureExchangeId");
    assertNull(firstFail);

    String last = (String) mbeanServer.getAttribute(on, "LastExchangeCompletedExchangeId");
    assertEquals(result.getReceivedExchanges().get(4).getExchangeId(), last);

    String lastFail = (String) mbeanServer.getAttribute(on, "LastExchangeFailureExchangeId");
    assertNull(lastFail);

    // should be 5 on the processors
    ObjectName foo =
        ObjectName.getInstance(
            "org.apache.camel:context=localhost/camel-1,type=processors,name=\"foo\"");
    completed = (Long) mbeanServer.getAttribute(foo, "ExchangesCompleted");
    assertEquals(5, completed.longValue());

    ObjectName mock =
        ObjectName.getInstance(
            "org.apache.camel:context=localhost/camel-1,type=processors,name=\"mock\"");
    completed = (Long) mbeanServer.getAttribute(mock, "ExchangesCompleted");
    assertEquals(5, completed.longValue());
  }
コード例 #6
0
 @Test
 public void testCircularReferenceWithChannelInFactoryBean() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "oref-factory-channel.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   assertTrue(Arrays.asList(messageChannelsMonitor.getChannelNames()).contains("anonymous"));
   MBeanServer server = context.getBean(MBeanServer.class);
   assertEquals(1, server.queryNames(ObjectName.getInstance("com.foo:*"), null).size());
   assertEquals(
       1,
       server
           .queryNames(
               ObjectName.getInstance("org.springframework.integration:name=anonymous,*"), null)
           .size());
 }
コード例 #7
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testRegisterNotificationListenerWithWildcard() throws Exception {
    ObjectName objectName = ObjectName.getInstance("spring:name=Test");
    JmxTestBean bean = new JmxTestBean();

    Map<String, Object> beans = new HashMap<String, Object>();
    beans.put(objectName.getCanonicalName(), bean);

    CountingAttributeChangeNotificationListener listener =
        new CountingAttributeChangeNotificationListener();

    Map notificationListeners = new HashMap();
    notificationListeners.put("*", listener);

    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.setNotificationListenerMappings(notificationListeners);
    exporter.afterPropertiesSet();

    // update the attribute
    String attributeName = "Name";
    server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
    assertEquals("Listener not notified", 1, listener.getCount(attributeName));
  }
コード例 #8
0
  public void testNotificationListenerRegistrar() throws Exception {
    ObjectName objectName = ObjectName.getInstance("spring:name=Test");
    JmxTestBean bean = new JmxTestBean();

    Map<String, Object> beans = new HashMap<String, Object>();
    beans.put(objectName.getCanonicalName(), bean);

    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.afterPropertiesSet();

    CountingAttributeChangeNotificationListener listener =
        new CountingAttributeChangeNotificationListener();

    NotificationListenerRegistrar registrar = new NotificationListenerRegistrar();
    registrar.setServer(server);
    registrar.setNotificationListener(listener);
    registrar.setMappedObjectName(objectName);
    registrar.afterPropertiesSet();

    // update the attribute
    String attributeName = "Name";
    server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
    assertEquals("Listener not notified", 1, listener.getCount(attributeName));

    registrar.destroy();

    // try to update the attribute again
    server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
    assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
  }
コード例 #9
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance()
      throws Exception {
    String beanName = "testBean";
    ObjectName objectName = ObjectName.getInstance("spring:name=Test");

    SelfNamingTestBean testBean = new SelfNamingTestBean();
    testBean.setObjectName(objectName);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerSingleton(beanName, testBean);

    Map<String, Object> beans = new HashMap<String, Object>();
    beans.put(beanName, testBean);

    Map listenerMappings = new HashMap();
    CountingAttributeChangeNotificationListener listener =
        new CountingAttributeChangeNotificationListener();
    listenerMappings.put(objectName, listener);
    listenerMappings.put(beanName, listener);

    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.setNotificationListenerMappings(listenerMappings);
    exporter.setBeanFactory(factory);
    exporter.afterPropertiesSet();
    assertIsRegistered("Should have registered MBean", objectName);

    server.setAttribute(objectName, new Attribute("Age", new Integer(77)));
    assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
  }
コード例 #10
0
  public void testTwoManagedCamelContextClash() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    camel1 = createCamelContext("foo", "myFoo");
    camel2 = createCamelContext("foo", "myFoo");

    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());

    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on =
        ObjectName.getInstance(
            "org.apache.camel:context="
                + camel1.getManagementName()
                + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    // we use fixed names, so we will get a clash
    try {
      camel2.start();
      fail("Should have thrown an exception");
    } catch (VetoCamelContextStartException e) {
      assertTrue(e.getMessage().contains("is already registered"));
    }
  }
コード例 #11
0
  public void testManagedCamelContextExplainEndpointUri() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on =
        ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");

    // get the json
    String json =
        (String)
            mbeanServer.invoke(
                on,
                "explainEndpointJson",
                new Object[] {"log:foo?groupDelay=2000&groupSize=5", false},
                new String[] {"java.lang.String", "boolean"});
    assertNotNull(json);

    assertEquals(5, StringHelper.countChar(json, '{'));
    assertEquals(5, StringHelper.countChar(json, '}'));
    assertTrue(
        json.contains(
            "\"groupDelay\": { \"kind\": \"parameter\", \"type\": \"integer\", \"javaType\": \"java.lang.Long\", \"value\": \"2000\","
                + " \"description\": \"Set the initial delay for stats (in millis)\" },"));
    assertTrue(
        json.contains(
            "\"groupSize\": { \"kind\": \"parameter\", \"type\": \"integer\", \"javaType\": \"java.lang.Integer\", \"value\": \"5\","
                + " \"description\": \"An integer that specifies a group size for throughput logging.\" }"));
    assertTrue(
        json.contains(
            "\"loggerName\": { \"kind\": \"path\", \"type\": \"string\", \"javaType\": \"java.lang.String\","
                + " \"value\": \"foo\", \"description\": \"The logger name to use\" }"));
  }
コード例 #12
0
ファイル: ManagedRoute.java プロジェクト: vaidyakrish/camel
  public void reset(boolean includeProcessors) throws Exception {
    reset();

    // and now reset all processors for this route
    if (includeProcessors) {
      MBeanServer server =
          getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
      if (server != null) {
        // get all the processor mbeans and sort them accordingly to their index
        String prefix =
            getContext().getManagementStrategy().getManagementAgent().getIncludeHostName()
                ? "*/"
                : "";
        ObjectName query =
            ObjectName.getInstance(
                "org.apache.camel:context="
                    + prefix
                    + getContext().getManagementName()
                    + ",type=processors,*");
        QueryExp queryExp =
            Query.match(new AttributeValueExp("RouteId"), new StringValueExp(getRouteId()));
        Set<ObjectName> names = server.queryNames(query, queryExp);
        for (ObjectName name : names) {
          server.invoke(name, "reset", null, null);
        }
      }
    }
  }
コード例 #13
0
  public void reset(boolean includeRoutes) throws Exception {
    reset();

    // and now reset all routes for this route
    if (includeRoutes) {
      MBeanServer server =
          getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
      if (server != null) {
        String prefix =
            getContext().getManagementStrategy().getManagementAgent().getIncludeHostName()
                ? "*/"
                : "";
        ObjectName query =
            ObjectName.getInstance(
                "org.apache.camel:context="
                    + prefix
                    + getContext().getManagementName()
                    + ",type=routes,*");
        Set<ObjectName> names = server.queryNames(query, null);
        for (ObjectName name : names) {
          server.invoke(name, "reset", new Object[] {true}, new String[] {"boolean"});
        }
      }
    }
  }
コード例 #14
0
  public void testUnregisterCamelContext() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    // The camel context already started by ContextTestSupport in the startup method

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on =
        ObjectName.getInstance(
            "org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");

    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);

    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);

    String version = (String) mbeanServer.getAttribute(on, "CamelVersion");
    assertNotNull(version);

    Map<?, ?> properties = (Map<?, ?>) mbeanServer.getAttribute(on, "Properties");
    assertNull(properties);

    Integer num = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
    assertEquals(0, num.intValue());

    context.stop();

    assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
  }
コード例 #15
0
  @Override
  public List<CamelProcessorMBean> getProcessors(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=processors,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelProcessorMBean> answer = new ArrayList<CamelProcessorMBean>();
    for (ObjectInstance on : names) {
      CamelProcessorMBean processor;
      if (ManagedSendProcessor.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelSendProcessorMBean.class, true);
      } else if (ManagedDelayer.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelDelayProcessorMBean.class, true);
      } else if (ManagedThrottler.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelThrottleProcessorMBean.class, true);
      } else {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelProcessorMBean.class, true);
      }
      answer.add(processor);
    }
    return answer;
  }
コード例 #16
0
  @Override
  public String getRouteStatsAsXml(
      String routeId, String camelContextName, boolean fullStats, boolean includeProcessors)
      throws Exception {
    if (jolokia == null) {
      throw new IllegalStateException("Need to connect to remote jolokia first");
    }

    ObjectName found = lookupCamelContext(camelContextName);
    if (found != null) {
      String pattern =
          String.format(
              "%s:context=%s,type=routes,name=\"%s\"",
              found.getDomain(), found.getKeyProperty("context"), routeId);
      ObjectName on = ObjectName.getInstance(pattern);
      J4pExecResponse response =
          jolokia.execute(
              new J4pExecRequest(
                  on, "dumpRouteStatsAsXml(boolean,boolean)", fullStats, includeProcessors));
      if (response != null) {
        String xml = response.getValue();
        return xml;
      }
    }

    return null;
  }
コード例 #17
0
 @Test
 public void testComponentNames() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "excluded-components.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=MessageChannel,*"), null);
   // Only one registered (out of >2 available)
   assertEquals(1, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=MessageHandler,*"), null);
   assertEquals(0, names.size());
 }
コード例 #18
0
 public static ObjectName createRootObjectName(String domain) {
   try {
     return ObjectName.getInstance(domain, "management-root", "server");
   } catch (MalformedObjectNameException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #19
0
  @Override
  public List<CamelEndpointMBean> getEndpoints(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=endpoints,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelEndpointMBean> answer = new ArrayList<CamelEndpointMBean>();
    for (ObjectInstance on : names) {
      CamelEndpointMBean endpoint;
      if (ManagedBrowsableEndpoint.class.getName().equals(on.getClassName())
          || SedaEndpoint.class.getName().equals(on.getClassName())) {
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true);
      } else if (on.getClassName().startsWith("org.apache.camel.component.jms")) {
        // special for JMS endpoints as they are browsable as well
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true);
      } else {
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelEndpointMBean.class, true);
      }
      answer.add(endpoint);
    }
    return answer;
  }
コード例 #20
0
  public void initialize() {
    Properties passwordProps = new Properties();
    String jmxrmi_password = null;

    try {
      // throws exception when there's no password file to be found.
      InputStream is = new FileInputStream(passwordFile_);
      try {
        passwordProps.load(is);
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (IOException e) {
          }
        }
      }

      jmxrmi_password = passwordProps.getProperty("controlRole");
      env_ = new HashMap<String, Object>();
      String[] cred = new String[] {"controlRole", jmxrmi_password};
      env_.put("jmx.remote.credentials", cred);
      virtWebappRegistry_ =
          ObjectName.getInstance("Alfresco:Name=VirtWebappRegistry,Type=VirtWebappRegistry");
    } catch (Exception e) {
      if (log.isWarnEnabled()) {
        log.warn(
            "WCM virtualization disabled "
                + "(alfresco-jmxrmi.password and/or "
                + "alfresco-jmxrmi.access isn't on classpath) due to: "
                + e);
      }
    }
  }
コード例 #21
0
  public void testFindComponentsInClasspath() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on =
        ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");

    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    @SuppressWarnings("unchecked")
    Map<String, Properties> info =
        (Map<String, Properties>) mbeanServer.invoke(on, "findComponents", null, null);
    assertNotNull(info);

    assertEquals(23, info.size());
    Properties prop = info.get("seda");
    assertNotNull(prop);
    assertEquals("seda", prop.get("name"));
    assertEquals("org.apache.camel", prop.get("groupId"));
    assertEquals("camel-core", prop.get("artifactId"));
  }
コード例 #22
0
  public void testManagedCamelContextRemoveEndpoint() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on =
        ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");

    assertNull(context.hasEndpoint("seda:bar"));

    // create a new endpoint
    Object reply =
        mbeanServer.invoke(
            on, "createEndpoint", new Object[] {"seda:bar"}, new String[] {"java.lang.String"});
    assertEquals(Boolean.TRUE, reply);

    assertNotNull(context.hasEndpoint("seda:bar"));

    ObjectName seda =
        ObjectName.getInstance(
            "org.apache.camel:context=19-camel-1,type=endpoints,name=\"seda://bar\"");
    boolean registered = mbeanServer.isRegistered(seda);
    assertTrue("Should be registered " + seda, registered);

    // remove it
    Object num =
        mbeanServer.invoke(
            on, "removeEndpoints", new Object[] {"seda:*"}, new String[] {"java.lang.String"});
    assertEquals(1, num);

    assertNull(context.hasEndpoint("seda:bar"));
    registered = mbeanServer.isRegistered(seda);
    assertFalse("Should not be registered " + seda, registered);

    // remove it again
    num =
        mbeanServer.invoke(
            on, "removeEndpoints", new Object[] {"seda:*"}, new String[] {"java.lang.String"});
    assertEquals(0, num);

    assertNull(context.hasEndpoint("seda:bar"));
    registered = mbeanServer.isRegistered(seda);
    assertFalse("Should not be registered " + seda, registered);
  }
コード例 #23
0
  public void testManagedThreadPool() throws Exception {
    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on =
        ObjectName.getInstance(
            "org.apache.camel:context=localhost/camel-1,type=threadpools,name=\"threads1(threads)\"");

    Integer corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
    assertEquals(5, corePoolSize.intValue());

    Integer maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
    assertEquals(15, maxPoolSize.intValue());

    String id = (String) mbeanServer.getAttribute(on, "Id");
    assertEquals("threads1", id);

    String source = (String) mbeanServer.getAttribute(on, "SourceId");
    assertEquals("threads", source);

    String route = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", route);

    String profile = (String) mbeanServer.getAttribute(on, "ThreadPoolProfileId");
    assertEquals("custom", profile);

    on =
        ObjectName.getInstance(
            "org.apache.camel:context=localhost/camel-1,type=threadpools,name=\"threads2(threads)\"");

    corePoolSize = (Integer) mbeanServer.getAttribute(on, "CorePoolSize");
    assertEquals(5, corePoolSize.intValue());

    maxPoolSize = (Integer) mbeanServer.getAttribute(on, "MaximumPoolSize");
    assertEquals(15, maxPoolSize.intValue());

    id = (String) mbeanServer.getAttribute(on, "Id");
    assertEquals("threads2", id);

    source = (String) mbeanServer.getAttribute(on, "SourceId");
    assertEquals("threads", source);

    route = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route2", route);

    profile = (String) mbeanServer.getAttribute(on, "ThreadPoolProfileId");
    assertEquals("custom", profile);
  }
コード例 #24
0
  @Override
  public List<Map<String, String>> getEndpointRuntimeStatistics(String camelContextName)
      throws Exception {
    if (jolokia == null) {
      throw new IllegalStateException("Need to connect to remote jolokia first");
    }

    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();

    ObjectName found = lookupCamelContext(camelContextName);
    if (found != null) {
      String pattern =
          String.format(
              "%s:context=%s,type=services,name=DefaultRuntimeEndpointRegistry",
              found.getDomain(), found.getKeyProperty("context"));
      ObjectName on = ObjectName.getInstance(pattern);

      J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "endpointStatistics()"));
      if (response != null) {
        JSONObject data = response.getValue();
        for (Object obj : data.values()) {
          JSONObject data2 = (JSONObject) obj;
          JSONObject service = (JSONObject) data2.values().iterator().next();

          Map<String, String> row = new LinkedHashMap<String, String>();
          row.put("index", asString(service.get("index")));
          row.put("url", asString(service.get("url")));
          row.put("routeId", asString(service.get("routeId")));
          row.put("direction", asString(service.get("direction")));
          row.put("static", asString(service.get("static")));
          row.put("dynamic", asString(service.get("dynamic")));
          row.put("hits", asString(service.get("hits")));
          answer.add(row);
        }
      }

      // sort the list
      Collections.sort(
          answer,
          new Comparator<Map<String, String>>() {
            @Override
            public int compare(Map<String, String> endpoint1, Map<String, String> endpoint2) {
              // sort by route id
              String route1 = endpoint1.get("routeId");
              String route2 = endpoint2.get("routeId");
              int num = route1.compareTo(route2);
              if (num == 0) {
                // we want in before out
                String dir1 = endpoint1.get("direction");
                String dir2 = endpoint2.get("direction");
                num = dir1.compareTo(dir2);
              }
              return num;
            }
          });
    }

    return answer;
  }
コード例 #25
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testRegisterNotificationListenerWithTwoBeanNamesMappedToDifferentBeanInstances()
      throws Exception {
    String beanName1 = "testBean1";
    String beanName2 = "testBean2";

    ObjectName objectName1 = ObjectName.getInstance("spring:name=Test1");
    ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2");

    SelfNamingTestBean testBean1 = new SelfNamingTestBean();
    testBean1.setObjectName(objectName1);

    SelfNamingTestBean testBean2 = new SelfNamingTestBean();
    testBean2.setObjectName(objectName2);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerSingleton(beanName1, testBean1);
    factory.registerSingleton(beanName2, testBean2);

    Map<String, Object> beans = new HashMap<String, Object>();
    beans.put(beanName1, testBean1);
    beans.put(beanName2, testBean2);

    Map listenerMappings = new HashMap();
    CountingAttributeChangeNotificationListener listener =
        new CountingAttributeChangeNotificationListener();
    listenerMappings.put(beanName1, listener);
    listenerMappings.put(beanName2, listener);

    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.setNotificationListenerMappings(listenerMappings);
    exporter.setBeanFactory(factory);
    exporter.afterPropertiesSet();
    assertIsRegistered("Should have registered MBean", objectName1);
    assertIsRegistered("Should have registered MBean", objectName2);

    server.setAttribute(
        ObjectNameManager.getInstance(objectName1), new Attribute("Age", new Integer(77)));
    assertEquals("Listener not notified for testBean1", 1, listener.getCount("Age"));

    server.setAttribute(
        ObjectNameManager.getInstance(objectName2), new Attribute("Age", new Integer(33)));
    assertEquals("Listener not notified for testBean2", 2, listener.getCount("Age"));
  }
コード例 #26
0
  @Override
  public List<Map<String, String>> getRestServices(String camelContextName) throws Exception {
    if (jolokia == null) {
      throw new IllegalStateException("Need to connect to remote jolokia first");
    }

    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();

    ObjectName found = lookupCamelContext(camelContextName);
    if (found != null) {
      String pattern =
          String.format(
              "%s:context=%s,type=services,name=DefaultRestRegistry",
              found.getDomain(), found.getKeyProperty("context"));
      ObjectName on = ObjectName.getInstance(pattern);

      J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "listRestServices()"));
      if (response != null) {
        JSONObject data = response.getValue();
        if (data != null) {
          for (Object obj : data.values()) {
            JSONObject data2 = (JSONObject) obj;
            JSONObject service = (JSONObject) data2.values().iterator().next();

            Map<String, String> row = new LinkedHashMap<String, String>();
            row.put("basePath", asString(service.get("basePath")));
            row.put("baseUrl", asString(service.get("baseUrl")));
            row.put("consumes", asString(service.get("consumes")));
            row.put("description", asString(service.get("description")));
            row.put("inType", asString(service.get("inType")));
            row.put("method", asString(service.get("method")));
            row.put("outType", asString(service.get("outType")));
            row.put("produces", asString(service.get("produces")));
            row.put("routeId", asString(service.get("routeId")));
            row.put("state", asString(service.get("state")));
            row.put("uriTemplate", asString(service.get("uriTemplate")));
            row.put("url", asString(service.get("url")));
            answer.add(row);
          }
        }
      }

      // sort the list
      Collections.sort(
          answer,
          new Comparator<Map<String, String>>() {
            @Override
            public int compare(Map<String, String> service1, Map<String, String> service2) {
              String url1 = service1.get("url");
              String url2 = service2.get("url");
              return url1.compareTo(url2);
            }
          });
    }

    return answer;
  }
コード例 #27
0
 public ObjectName getObjectName() throws MalformedObjectNameException {
   String domain = "org.apache.river.examples";
   String projectId;
   if (System.getProperty("project.id") != null)
     projectId = String.format(",projectId=%s", System.getProperty("project.id"));
   else projectId = "";
   String objectName = String.format("%s:name=Greeter%s", domain, projectId);
   return ObjectName.getInstance(objectName);
 }
コード例 #28
0
  public void testManageMarshal() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(1);

    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");

    assertMockEndpointsSatisfied();

    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();

    // get the object name for the delayer
    ObjectName on =
        ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");

    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);

    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);

    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);

    String name = (String) mbeanServer.getAttribute(on, "DataFormatName");
    assertEquals("string", name);

    String xml = (String) mbeanServer.invoke(on, "dumpProcessorAsXml", null, null);
    assertTrue(xml.contains("<marshal"));
    assertTrue(xml.contains("</marshal>"));
    assertTrue(xml.contains("<string charset=\"iso-8859-1\"/>"));

    TabularData data =
        (TabularData)
            mbeanServer.invoke(on, "explain", new Object[] {false}, new String[] {"boolean"});
    assertNotNull(data);
    assertEquals(2, data.size());

    data =
        (TabularData)
            mbeanServer.invoke(on, "explain", new Object[] {true}, new String[] {"boolean"});
    assertNotNull(data);
    assertEquals(4, data.size());

    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(
        json.contains(
            "\"description\": \"Marshals data into a specified format for transmission over a transport or component"));
  }
コード例 #29
0
  public void testManagedCamelContext() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
      return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on =
        ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");

    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);

    String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
    assertNotNull(uptime);

    long uptimeMillis = (Long) mbeanServer.getAttribute(on, "UptimeMillis");
    assertTrue(uptimeMillis > 0);

    String status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Started", status);

    // invoke operations
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");

    Object reply =
        mbeanServer.invoke(
            on,
            "requestBody",
            new Object[] {"direct:foo", "Hello World"},
            new String[] {"java.lang.String", "java.lang.Object"});
    assertEquals("Bye World", reply);

    // suspend Camel
    mbeanServer.invoke(on, "suspend", null, null);

    status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Suspended", status);

    // resume Camel
    mbeanServer.invoke(on, "resume", null, null);

    status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Started", status);

    reply =
        mbeanServer.invoke(
            on,
            "requestBody",
            new Object[] {"direct:foo", "Hello Camel"},
            new String[] {"java.lang.String", "java.lang.Object"});
    assertEquals("Bye World", reply);
  }
コード例 #30
0
ファイル: TestDriver.java プロジェクト: clonegod/app-samples
  private static void init() throws Exception {
    // 初始化MBeanServer
    ThreadPoolStatus status = new ThreadPoolStatus(trackingPool);
    // MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer(); // 不支持jconsole
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); // 支持jconsole
    ObjectName objName = ObjectName.getInstance("myapp:type=webserver,name=port 8088");

    // 将被托管MBean注册到MBServer中
    mBeanServer.registerMBean(status, objName);
  }