@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("Begin"); WrappedMBeanServerConnection mbeanServer = mbeanServerManager.getMBeanServer(keyPairs); if (mbeanServer != null) { ServerProxy server = new ServerProxy(channel, mbeanServer, executor, serverMessageInterceptor); server.start(); String connectionId = server.getConnectionId(); writeResponse(connectionId, BEGIN, correlationId); } else { // No MBeanServer was located ;-( throw new IOException("No MBeanServer identified from the specified parameters."); } }
ServerProxy(final Channel channel, final WrappedMBeanServerConnection server, final Executor executor, final ServerMessageInterceptor serverMessageInterceptor) { super(channel, executor, serverMessageInterceptor); this.channel = channel; this.server = server; handlerRegistry = createHandlerRegistry(); this.remoteNotificationManager = new RemoteNotificationManager(); this.executor = executor; }
@Override public void write(DataOutput output) throws IOException { output.writeByte(inResponseTo ^ RESPONSE_MASK); output.writeInt(correlationId); output.writeByte(SUCCESS); output.writeByte(type); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(response); marshaller.finish(); } });
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("GetObjectInstance"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { ObjectInstance objectInstance = server.getMBeanServerConnection().getObjectInstance(objectName); writeResponse(objectInstance, OBJECT_INSTANCE, GET_OBJECT_INSTANCE, correlationId); log.tracef("[%d] GetObjectInstance - Success Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, GET_OBJECT_INSTANCE, correlationId); log.tracef("[%d] GetObjectInstance - Failure Response Sent", correlationId); } }
private void writeResponse(final Integer response, final byte inResponseTo, final int correlationId) throws IOException { write(new MessageWriter() { @Override public void write(DataOutput output) throws IOException { output.writeByte(inResponseTo ^ RESPONSE_MASK); output.writeInt(correlationId); output.writeByte(SUCCESS); output.writeByte(INTEGER); output.writeInt(response); } }); }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("IsRegistered"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } boolean registered = server.getMBeanServerConnection().isRegistered(objectName); writeResponse(registered, IS_REGISTERED, correlationId); log.tracef("[%d] IsRegistered - Success Response Sent", correlationId); } }
@Override public void handle(DataInput input, final int correlationId) throws IOException { log.trace("GetDefaultDomain"); final String defaultDomain = server.getMBeanServerConnection().getDefaultDomain(); writeResponse(defaultDomain, GET_DEFAULT_DOMAIN, correlationId); log.tracef("[%d] CreateMBean - Success Response Sent", correlationId); } }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("UnregisterMBean"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { server.getMBeanServerConnection().unregisterMBean(objectName); writeResponse(UNREGISTER_MBEAN, correlationId); log.tracef("[%d] UnregisterMBean - Success Response Sent", correlationId); } catch (MBeanRegistrationException e) { writeResponse(e, UNREGISTER_MBEAN, correlationId); log.tracef("[%d] UnregisterMBean - Failure Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, UNREGISTER_MBEAN, correlationId); log.tracef("[%d] UnregisterMBean - Failure Response Sent", correlationId); } }
private void writeResponse(final boolean response, final byte inResponseTo, final int correlationId) throws IOException { write(new MessageWriter() { @Override public void write(DataOutput output) throws IOException { output.writeByte(inResponseTo ^ RESPONSE_MASK); output.writeInt(correlationId); output.writeByte(SUCCESS); output.writeByte(BOOLEAN); output.writeBoolean(response); } }); }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("QueryNames"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } ObjectName objectName; QueryExp query; try { Unmarshaller unmarshaller = prepareForUnMarshalling(input); objectName = unmarshaller.readObject(ObjectName.class); paramType = unmarshaller.readByte(); if (paramType != QUERY_EXP) { throw new IOException("Unexpected paramType"); } query = unmarshaller.readObject(QueryExp.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } Set<ObjectName> instances = server.getMBeanServerConnection().queryNames(objectName, query); writeResponse(instances, SET_OBJECT_NAME, QUERY_NAMES, correlationId); log.tracef("[%d] QueryNames - Success Response Sent", correlationId); } }
@Override public void handle(DataInput input, final int correlationId) throws IOException { log.trace("GetDefaultDomain"); final String defaultDomain = server.getMBeanServerConnection().getDefaultDomain(); writeResponse(defaultDomain, GET_DEFAULT_DOMAIN, correlationId); log.tracef("[%d] CreateMBean - Success Response Sent", correlationId); } }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("GetMBeanInfo"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { MBeanInfo info = server.getMBeanServerConnection().getMBeanInfo(objectName); writeResponse(info, MBEAN_INFO, GET_MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Success Response Sent", correlationId); } catch (IntrospectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (ReflectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("Begin"); WrappedMBeanServerConnection mbeanServer = mbeanServerManager.getMBeanServer(keyPairs); if (mbeanServer != null) { ServerProxy server = new ServerProxy(channel, mbeanServer, executor, serverMessageInterceptor); server.start(); String connectionId = server.getConnectionId(); writeResponse(connectionId, BEGIN, correlationId); } else { // No MBeanServer was located ;-( throw new IOException("No MBeanServer identified from the specified parameters."); } }
private void writeResponse(final String[] response, final byte inResponseTo, final int correlationId) throws IOException { write(new MessageWriter() { @Override public void write(DataOutput output) throws IOException { output.writeByte(inResponseTo ^ RESPONSE_MASK); output.writeInt(correlationId); output.writeByte(SUCCESS); output.writeByte(STRING_ARRAY); output.writeInt(response.length); for (String currentDomain : response) { output.writeUTF(currentDomain); } } }); }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("QueryMBeans"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } ObjectName objectName; QueryExp query; try { Unmarshaller unmarshaller = prepareForUnMarshalling(input); objectName = unmarshaller.readObject(ObjectName.class); paramType = unmarshaller.readByte(); if (paramType != QUERY_EXP) { throw new IOException("Unexpected paramType"); } query = unmarshaller.readObject(QueryExp.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } Set<ObjectInstance> instances = server.getMBeanServerConnection().queryMBeans(objectName, query); writeResponse(instances, SET_OBJECT_INSTANCE, QUERY_MBEANS, correlationId); log.tracef("[%d] QueryMBeans - Success Response Sent", correlationId); } }
@Override public void write(DataOutput output) throws IOException { output.writeByte(SEND_NOTIFICATION); output.writeInt(0x00); output.writeByte(INTEGER); output.writeInt(listenerId); output.writeByte(NOTIFICATION); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(notification); marshaller.writeByte(OBJECT); marshaller.writeObject(handback); marshaller.finish(); } });
@Override public void handle(DataInput input, final int correlationId) throws IOException { log.trace("GetDefaultDomain"); final String defaultDomain = server.getMBeanServerConnection().getDefaultDomain(); writeResponse(defaultDomain, GET_DEFAULT_DOMAIN, correlationId); log.tracef("[%d] CreateMBean - Success Response Sent", correlationId); } }
ServerProxy(final Channel channel, final WrappedMBeanServerConnection server, final Executor executor, final ServerMessageInterceptor serverMessageInterceptor) { super(channel, executor, serverMessageInterceptor); this.channel = channel; this.server = server; handlerRegistry = createHandlerRegistry(); this.remoteNotificationManager = new RemoteNotificationManager(); this.executor = executor; }
Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; final Object attributeValue = server.getMBeanServerConnection().getAttribute(objectName, attribute); writeResponse(attributeValue, OBJECT, GET_ATTRIBUTE, correlationId); writeResponse(e, GET_ATTRIBUTE, correlationId); log.tracef("[%d] GetAttribute - Failure Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, GET_ATTRIBUTE, correlationId); log.tracef("[%d] GetAttribute - Failure Response Sent", correlationId); } catch (MBeanException e) { writeResponse(e, GET_ATTRIBUTE, correlationId); log.tracef("[%d] GetAttribute - Failure Response Sent", correlationId); } catch (ReflectionException e) { writeResponse(e, GET_ATTRIBUTE, correlationId); log.tracef("[%d] GetAttribute - Failure Response Sent", correlationId);
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("Begin"); WrappedMBeanServerConnection mbeanServer = mbeanServerManager.getMBeanServer(keyPairs); if (mbeanServer != null) { ServerProxy server = new ServerProxy(channel, mbeanServer, executor, serverMessageInterceptor); server.start(); String connectionId = server.getConnectionId(); writeResponse(connectionId, BEGIN, correlationId); } else { // No MBeanServer was located ;-( throw new IOException("No MBeanServer identified from the specified parameters."); } }