Search in sources :

Example 91 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project midpoint by Evolveum.

the class RemoteNodesManager method getSchedulerBean.

private QuartzSchedulerMBean getSchedulerBean(NodeType node, Holder<JMXConnector> connectorHolder, OperationResult result) {
    String nodeName = node.getNodeIdentifier();
    String address = node.getHostname() + ":" + node.getJmxPort();
    try {
        JMXConnector connector = connectViaJmx(address);
        connectorHolder.setValue(connector);
        MBeanServerConnection serverConnection = connector.getMBeanServerConnection();
        QuartzSchedulerMBean bean = getMBeanProxy(nodeName, serverConnection);
        if (bean == null) {
            String message = "Cannot connect to the Quartz Scheduler bean at remote node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node.";
            LOGGER.warn("{}", message);
            result.recordFatalError(message);
        }
        return bean;
    } catch (IOException | MalformedObjectNameException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the quartz scheduler bean at remote node {} at {}", e, nodeName, address);
        result.recordFatalError("Cannot connect to the quartz scheduler bean at remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
        return null;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) QuartzSchedulerMBean(org.quartz.core.jmx.QuartzSchedulerMBean)

Example 92 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project midpoint by Evolveum.

the class RemoteNodesManager method stopRemoteScheduler.

public void stopRemoteScheduler(String nodeIdentifier, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".stopRemoteScheduler");
    result.addParam("nodeIdentifier", nodeIdentifier);
    NodeType node = getNode(nodeIdentifier, result);
    if (node == null) {
        return;
    }
    String nodeName = node.getNodeIdentifier();
    String address = node.getHostname() + ":" + node.getJmxPort();
    JMXConnector connector = null;
    try {
        MBeanServerConnection mbsc;
        try {
            connector = connectViaJmx(address);
            mbsc = connector.getMBeanServerConnection();
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeName, address);
            result.recordFatalError("Cannot connect to the remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
            return;
        }
        try {
            QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeName, mbsc);
            if (mbeanProxy != null) {
                mbeanProxy.standby();
                result.recordSuccess();
            } else {
                result.recordWarning("Cannot stop the scheduler on node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node.");
            }
            return;
        } catch (Exception e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot put remote scheduler into standby mode; remote node {} at {}", e, nodeName, address);
            result.recordFatalError("Cannot put remote scheduler " + nodeName + " at " + address + " into standby mode: " + e.getMessage());
            return;
        }
    } finally {
        try {
            if (connector != null) {
                connector.close();
            }
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
        }
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SystemException(com.evolveum.midpoint.util.exception.SystemException) QuartzSchedulerMBean(org.quartz.core.jmx.QuartzSchedulerMBean)

Example 93 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jdk8u_jdk by JetBrains.

the class RMIConnector method getConnectionWithSubject.

private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) {
    MBeanServerConnection conn = null;
    if (delegationSubject == null) {
        if (nullSubjectConnRef == null || (conn = nullSubjectConnRef.get()) == null) {
            conn = new RemoteMBeanServerConnection(null);
            nullSubjectConnRef = new WeakReference(conn);
        }
    } else {
        WeakReference<MBeanServerConnection> wr = rmbscMap.get(delegationSubject);
        if (wr == null || (conn = wr.get()) == null) {
            conn = new RemoteMBeanServerConnection(delegationSubject);
            rmbscMap.put(delegationSubject, new WeakReference(conn));
        }
    }
    return conn;
}
Also used : WeakReference(java.lang.ref.WeakReference) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 94 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jdk8u_jdk by JetBrains.

the class TestUtils method makeNotificationEmitter.

/**
     * Transfroms a proxy implementing T in a proxy implementing T plus
     * NotificationEmitter
     *
     **/
public static <T> T makeNotificationEmitter(T proxy, Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null)
        return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a " + Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler = Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h = (MBeanServerInvocationHandler) handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs, name, mbeanInterface, true);
    else
        newProxy = JMX.newMBeanProxy(mbs, name, mbeanInterface, true);
    return newProxy;
}
Also used : Proxy(java.lang.reflect.Proxy) NotificationEmitter(javax.management.NotificationEmitter) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 95 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jdk8u_jdk by JetBrains.

the class Client method run.

public static void run(String url) throws Exception {
    final int notifEmittedCnt = 10;
    final CountDownLatch counter = new CountDownLatch(notifEmittedCnt);
    final Set<Long> seqSet = Collections.synchronizedSet(new HashSet<Long>());
    final AtomicBoolean duplNotification = new AtomicBoolean();
    JMXServiceURL serverUrl = new JMXServiceURL(url);
    ObjectName name = new ObjectName("test", "foo", "bar");
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serverUrl);
    System.out.println("client connected");
    jmxConnector.addConnectionNotificationListener(new NotificationListener() {

        @Override
        public void handleNotification(Notification notification, Object handback) {
            System.out.println("connection notification: " + notification);
            if (!seqSet.add(notification.getSequenceNumber())) {
                duplNotification.set(true);
            }
            if (notification.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
                long lostNotifs = ((Long) ((JMXConnectionNotification) notification).getUserData()).longValue();
                for (int i = 0; i < lostNotifs; i++) {
                    counter.countDown();
                }
            }
        }
    }, null, null);
    MBeanServerConnection jmxServer = jmxConnector.getMBeanServerConnection();
    jmxServer.addNotificationListener(name, new NotificationListener() {

        @Override
        public void handleNotification(Notification notification, Object handback) {
            System.out.println("client got: " + notification);
            if (!seqSet.add(notification.getSequenceNumber())) {
                duplNotification.set(true);
            }
            counter.countDown();
        }
    }, null, null);
    System.out.println("client invoking foo (" + notifEmittedCnt + " times)");
    for (int i = 0; i < notifEmittedCnt; i++) {
        System.out.print(".");
        jmxServer.invoke(name, "foo", new Object[] {}, new String[] {});
    }
    System.out.println();
    try {
        System.out.println("waiting for " + notifEmittedCnt + " notifications to arrive");
        if (!counter.await(30, TimeUnit.SECONDS)) {
            throw new InterruptedException();
        }
        if (duplNotification.get()) {
            System.out.println("ERROR: received duplicated notifications");
            throw new Error("received duplicated notifications");
        }
        System.out.println("\nshutting down client");
    } catch (InterruptedException e) {
        System.out.println("ERROR: notification processing thread interrupted");
        throw new Error("notification thread interrupted unexpectedly");
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) CountDownLatch(java.util.concurrent.CountDownLatch) Notification(javax.management.Notification) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification) ObjectName(javax.management.ObjectName) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JMXConnector(javax.management.remote.JMXConnector) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification) MBeanServerConnection(javax.management.MBeanServerConnection) NotificationListener(javax.management.NotificationListener)

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