Search in sources :

Example 1 with ConnectionState

use of com.sun.tools.jconsole.JConsoleContext.ConnectionState in project wildfly-core by wildfly.

the class JConsoleCLIPlugin method connect.

private void connect() throws Exception {
    JConsoleContext jcCtx = this.getContext();
    MBeanServerConnection mbeanServerConn = jcCtx.getMBeanServerConnection();
    if (mbeanServerConn instanceof RemotingMBeanServerConnection) {
        final CommandContext cmdCtx = CommandContextFactory.getInstance().newCommandContext();
        if (connectUsingRemoting(cmdCtx, (RemotingMBeanServerConnection) mbeanServerConn)) {
            // Set a listener for connection state change.
            jcCtx.addPropertyChangeListener((PropertyChangeEvent evt) -> {
                log.tracef("Received property change %s value %s", evt.getPropertyName(), evt.getNewValue());
                if (JConsoleContext.CONNECTION_STATE_PROPERTY.equals(evt.getPropertyName())) {
                    ConnectionState state = (ConnectionState) evt.getNewValue();
                    if (state == ConnectionState.CONNECTED) {
                        try {
                            // Rebuild the ModelControllerClient
                            RemotingMBeanServerConnection rmbsc = (RemotingMBeanServerConnection) getContext().getMBeanServerConnection();
                            connectUsingRemoting(cmdCtx, rmbsc);
                            connectedClient = cmdCtx.getModelControllerClient();
                            isConnected = true;
                        } catch (Exception ex) {
                            log.error(null, ex);
                        }
                    } else {
                        isConnected = false;
                    }
                }
            });
            connectedClient = cmdCtx.getModelControllerClient();
            Supplier<ModelControllerClient> client = () -> {
                return connectedClient;
            };
            init(cmdCtx, client);
        } else {
            JOptionPane.showInternalMessageDialog(jconsolePanel, MSG_CANNOT_ESTABLISH_CONNECTION);
        }
    } else {
        // show dialog
        dialog.start();
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) CommandContext(org.jboss.as.cli.CommandContext) ExistingChannelModelControllerClient(org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) JConsoleContext(com.sun.tools.jconsole.JConsoleContext) RemotingMBeanServerConnection(org.jboss.remotingjmx.RemotingMBeanServerConnection) ConnectionState(com.sun.tools.jconsole.JConsoleContext.ConnectionState) MBeanServerConnection(javax.management.MBeanServerConnection) RemotingMBeanServerConnection(org.jboss.remotingjmx.RemotingMBeanServerConnection) CliInitializationException(org.jboss.as.cli.CliInitializationException) IOException(java.io.IOException)

Example 2 with ConnectionState

use of com.sun.tools.jconsole.JConsoleContext.ConnectionState in project visualgc_java8 by beansoft.

the class JTopPlugin method propertyChange.

// You can implement the dispose() method if you need to release
// any resource when the plugin instance is disposed when the JConsole
// window is closed.
// 
// public void dispose() {
// }
/*
     * Property listener to reset the MBeanServerConnection
     * at reconnection time.
     */
public void propertyChange(PropertyChangeEvent ev) {
    String prop = ev.getPropertyName();
    if (prop == JConsoleContext.CONNECTION_STATE_PROPERTY) {
        ConnectionState oldState = (ConnectionState) ev.getOldValue();
        ConnectionState newState = (ConnectionState) ev.getNewValue();
        // created at reconnection time.
        if (newState == ConnectionState.CONNECTED && jtop != null) {
            jtop.setMBeanServerConnection(getContext().getMBeanServerConnection());
        }
    }
}
Also used : ConnectionState(com.sun.tools.jconsole.JConsoleContext.ConnectionState)

Example 3 with ConnectionState

use of com.sun.tools.jconsole.JConsoleContext.ConnectionState in project narayana by jbosstm.

the class TxPerfPlugin method propertyChange.

public void propertyChange(PropertyChangeEvent ev) {
    String prop = ev.getPropertyName();
    if (prop == null ? JConsoleContext.CONNECTION_STATE_PROPERTY == null : prop.equals(JConsoleContext.CONNECTION_STATE_PROPERTY)) {
        ConnectionState oldState = (ConnectionState) ev.getOldValue();
        ConnectionState newState = (ConnectionState) ev.getNewValue();
        // created at reconnection time.
        if (newState == ConnectionState.CONNECTED && graph != null) {
            graph.setMBeanServerConnection(getContext().getMBeanServerConnection());
        }
    }
}
Also used : ConnectionState(com.sun.tools.jconsole.JConsoleContext.ConnectionState)

Aggregations

ConnectionState (com.sun.tools.jconsole.JConsoleContext.ConnectionState)3 JConsoleContext (com.sun.tools.jconsole.JConsoleContext)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 IOException (java.io.IOException)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 CliInitializationException (org.jboss.as.cli.CliInitializationException)1 CommandContext (org.jboss.as.cli.CommandContext)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 ExistingChannelModelControllerClient (org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient)1 RemotingMBeanServerConnection (org.jboss.remotingjmx.RemotingMBeanServerConnection)1