Search in sources :

Example 66 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jetty.project by eclipse.

the class JavaMonitorAction method getHttpPort.

/* ------------------------------------------------------------ */
public Integer getHttpPort() {
    Collection<ObjectName> connectors = null;
    MBeanServerConnection service;
    try {
        service = JMXMonitor.getServiceConnection();
        connectors = service.queryNames(new ObjectName("org.eclipse.jetty.nio:type=selectchannelconnector,*"), null);
        if (connectors != null && connectors.size() > 0) {
            Integer lowest = Integer.MAX_VALUE;
            for (final ObjectName connector : connectors) {
                lowest = (Integer) service.getAttribute(connector, "port");
            }
            if (lowest < Integer.MAX_VALUE)
                return lowest;
        }
    } catch (Exception ex) {
        LOG.debug(ex);
    }
    return 0;
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 67 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jetty.project by eclipse.

the class AttrEventTrigger method match.

/* ------------------------------------------------------------ */
/**
     * Verify if the event trigger conditions are in the 
     * appropriate state for an event to be triggered.
     * This event trigger uses the match(Comparable&lt;TYPE&gt;)
     * method to compare the value of the MXBean attribute
     * to the conditions specified by the subclasses.
     * 
     * @see org.eclipse.jetty.monitor.jmx.EventTrigger#match(long)
     */
@SuppressWarnings("unchecked")
public final boolean match(long timestamp) throws Exception {
    MBeanServerConnection serverConnection = JMXMonitor.getServiceConnection();
    TYPE value = null;
    try {
        int pos = _attributeName.indexOf('.');
        if (pos < 0)
            value = (TYPE) serverConnection.getAttribute(_nameObject, _attributeName);
        else
            value = getValue((CompositeData) serverConnection.getAttribute(_nameObject, _attributeName.substring(0, pos)), _attributeName.substring(pos + 1));
    } catch (Exception ex) {
        LOG.debug(ex);
    }
    boolean result = false;
    if (value != null) {
        result = match(value);
        if (result || getSaveAll()) {
            _states.put(timestamp, new EventState<TYPE>(this.getID(), this.getNameString(), value));
        }
    }
    return result;
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 68 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jetty.project by eclipse.

the class JavaMonitorAction method queryNames.

/* ------------------------------------------------------------ */
/**
     * @param param
     * @return
     * @throws IOException
     * @throws NullPointerException 
     * @throws MalformedObjectNameException 
     */
private ObjectName[] queryNames(ObjectName param) throws IOException, MalformedObjectNameException {
    ObjectName[] result = null;
    MBeanServerConnection connection = JMXMonitor.getServiceConnection();
    Set names = connection.queryNames(param, null);
    if (names != null && names.size() > 0) {
        result = new ObjectName[names.size()];
        int idx = 0;
        for (Object name : names) {
            if (name instanceof ObjectName)
                result[idx++] = (ObjectName) name;
            else
                result[idx++] = new ObjectName(name.toString());
        }
    }
    return result;
}
Also used : Set(java.util.Set) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 69 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jetty.project by eclipse.

the class DeploymentManagerLifeCyclePathTest method testStateTransition_DeployedToUndeployed.

@Test
public void testStateTransition_DeployedToUndeployed() throws Exception {
    DeploymentManager depman = new DeploymentManager();
    // no default
    depman.setDefaultLifeCycleGoal(null);
    AppLifeCyclePathCollector pathtracker = new AppLifeCyclePathCollector();
    MockAppProvider mockProvider = new MockAppProvider();
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    depman.addBean(mbContainer);
    depman.addLifeCycleBinding(pathtracker);
    depman.addAppProvider(mockProvider);
    depman.setContexts(new ContextHandlerCollection());
    // Start DepMan
    depman.start();
    // Trigger new App
    mockProvider.findWebapp("foo-webapp-1.war");
    App app = depman.getAppByOriginId("mock-foo-webapp-1.war");
    // Request Deploy of App
    depman.requestAppGoal(app, "deployed");
    JmxServiceConnection jmxConnection = new JmxServiceConnection();
    jmxConnection.connect();
    MBeanServerConnection mbsConnection = jmxConnection.getConnection();
    ObjectName dmObjName = new ObjectName("org.eclipse.jetty.deploy:type=deploymentmanager,id=0");
    String[] params = new String[] { "mock-foo-webapp-1.war", "undeployed" };
    String[] signature = new String[] { "java.lang.String", "java.lang.String" };
    mbsConnection.invoke(dmObjName, "requestAppGoal", params, signature);
    // Setup Expectations.
    List<String> expected = new ArrayList<String>();
    // SHOULD NOT SEE THIS NODE VISITED - expected.add("undeployed");
    expected.add("deploying");
    expected.add("deployed");
    expected.add("undeploying");
    expected.add("undeployed");
    pathtracker.assertExpected("Test JMX StateTransition / Deployed -> Undeployed", expected);
}
Also used : ArrayList(java.util.ArrayList) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ObjectName(javax.management.ObjectName) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 70 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.

the class JMXConnectionTest method nullConnectorIsNotClosed.

@Test
public void nullConnectorIsNotClosed() throws IOException {
    MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
    JMXConnection jmxConnection = new JMXConnection(null, mBeanServerConnection);
    jmxConnection.close();
}
Also used : JMXConnection(com.googlecode.jmxtrans.connections.JMXConnection) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7