Search in sources :

Example 1 with RemotingMBeanServerConnection

use of org.jboss.remotingjmx.RemotingMBeanServerConnection in project wildfly-core by wildfly.

the class JConsoleCLIPlugin method connectUsingRemoting.

private boolean connectUsingRemoting(CommandContext cmdCtx, RemotingMBeanServerConnection rmtMBeanSvrConn) throws IOException, CliInitializationException {
    Connection conn = rmtMBeanSvrConn.getConnection();
    Channel channel;
    final IoFuture<Channel> futureChannel = conn.openChannel("management", OptionMap.EMPTY);
    IoFuture.Status result = futureChannel.await(5, TimeUnit.SECONDS);
    if (result == IoFuture.Status.DONE) {
        channel = futureChannel.get();
    } else {
        futureChannel.cancel();
        return false;
    }
    ModelControllerClient modelCtlrClient = ExistingChannelModelControllerClient.createReceiving(channel, createExecutor());
    cmdCtx.bindClient(modelCtlrClient);
    return true;
}
Also used : ExistingChannelModelControllerClient(org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) MBeanServerConnection(javax.management.MBeanServerConnection) RemotingMBeanServerConnection(org.jboss.remotingjmx.RemotingMBeanServerConnection) IoFuture(org.xnio.IoFuture)

Example 2 with RemotingMBeanServerConnection

use of org.jboss.remotingjmx.RemotingMBeanServerConnection 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)

Aggregations

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