ServerProxy(final Channel channel, final WrappedMBeanServerConnection server, final Executor executor, final ServerMessageInterceptor serverMessageInterceptor) { super(channel); this.channel = channel; this.server = server; this.handlerRegistry = createHandlerRegistry(); this.remoteNotificationManager = new RemoteNotificationManager(); this.executor = executor; this.serverMessageInterceptor = serverMessageInterceptor; }
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); } }); }
public static void startServer(final Channel channel, final WrappedMBeanServerConnection server, final Executor executor, final ServerMessageInterceptor serverMessageInterceptor) throws IOException { ServerProxy proxy = new ServerProxy(channel, server, executor, serverMessageInterceptor); proxy.start(); }
private Map<Byte, Common.MessageHandler> createHandlerRegistry() { Map<Byte, Common.MessageHandler> registry = new HashMap<Byte, Common.MessageHandler>(); registry.put(ADD_NOTIFICATION_LISTENER, new AddNotificationListenerHandler()); registry.put(CREATE_MBEAN, new CreateMBeanHandler()); registry.put(GET_ATTRIBUTE, new GetAttributeHandler()); registry.put(GET_ATTRIBUTES, new GetAttributesHandler()); registry.put(GET_DEFAULT_DOMAIN, new GetDefaultDomainHandler()); registry.put(GET_DOMAINS, new GetDomainsHandler()); registry.put(GET_MBEAN_COUNT, new GetMBeanCountHandler()); registry.put(GET_MBEAN_INFO, new GetMBeanInfoHandler()); registry.put(GET_OBJECT_INSTANCE, new GetObjectInstanceHandler()); registry.put(INSTANCE_OF, new InstanceofHandler()); registry.put(INVOKE, new InvokeHandler()); registry.put(IS_REGISTERED, new IsRegisteredHandler()); registry.put(QUERY_MBEANS, new QueryMBeansHandler()); registry.put(QUERY_NAMES, new QueryNamesHandler()); registry.put(REMOVE_NOTIFICATION_LISTENER, new RemoveNotificationListenerHandler()); registry.put(SET_ATTRIBUTE, new SetAttributeHandler()); registry.put(SET_ATTRIBUTES, new SetAttributesHandler()); registry.put(UNREGISTER_MBEAN, new UnregisterMBeanHandler()); return Collections.unmodifiableMap(registry); }
void start() throws IOException { sendVersionHeader(); IoFuture<String> futureConnectionId = ConnectionIdReceiver.getConnectionId(channel); IoFuture.Status result = futureConnectionId.await(timeoutSeconds, TimeUnit.SECONDS); switch (result) { case DONE: connectionId = futureConnectionId.get(); mbeanServerConnection = new TheConnection(); localNotificationManager = new LocalNotificationManager(); channel.receiveMessage(new MessageReceiver()); break; case FAILED: throw futureConnectionId.getException(); default: throw new IOException("Unable to obtain connectionId, status=" + result.toString()); } }
public static VersionedConnection getConnection(final Channel channel, final Map<String, ?> environment) throws IOException { ClientConnection connection = new ClientConnection(channel, environment); connection.start(); return connection; }
private synchronized int associate(ObjectName target, NotificationListener listener, NotificationFilter filter, Object handBack) { Integer next = getNextNotificationId(); // Not likely but possible to use all IDs and start back at beginning while // old request still in progress. while (listeners.containsKey(next)) { next = getNextNotificationId(); } Association association = new Association(); association.target = target; association.listener = listener; association.filter = filter; association.handBack = handBack; listeners.put(next, association); return next; }
public static IoFuture<String> getConnectionId(final Channel channel) { VersionedIoFuture<String> future = new VersionedIoFuture<String>(); channel.receiveMessage(new ConnectionIdReceiver(future)); return future; }
public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException { removeNotificationListener(localNotificationManager.matchToRemove(name, listener, filter, handback)); }
private void sendVersionHeader() throws IOException { write(new MessageWriter() { @Override public void write(DataOutput output) throws IOException { output.writeBytes("JMX"); output.writeByte(VersionOne.getVersionIdentifier()); } }); }
public void handleError(Channel channel, IOException e) { future.setException(e); }
/** * Creates and returns a {@link org.jboss.marshalling.Unmarshaller} which is ready to be used for unmarshalling. The * {@link org.jboss.marshalling.Unmarshaller#start(org.jboss.marshalling.ByteInput)} will be invoked by this method, to use * the passed {@link java.io.DataInput dataInput}, before returning the unmarshaller. * * This unmarshaller will use the context class loader to resolve any classes. * * @param dataInput The data input from which to unmarshall * @return * @throws IOException */ protected Unmarshaller prepareForUnMarshalling(final DataInput dataInput) throws IOException { return prepareForUnMarshalling(dataInput, DefaultClassResolver.INSTANCE); }
private void writeResponse(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); } }); }
public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException { removeNotificationListener(localNotificationManager.matchToRemove(name, listener)); }
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); output.writeUTF(response); } }); }
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); } }); }
private void writeResponse(final Exception e, 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(FAILURE); output.writeByte(EXCEPTION); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(e); marshaller.finish(); } }); }
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); } } }); }
private void writeResponse(final Object response, final byte type, 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(type); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(response); marshaller.finish(); } }); }
private void writeNotification(final int listenerId, final Notification notification, final Object handback) throws IOException { write(new MessageWriter() { @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(); } }); }