@Override public void handleMessage(Channel channel, MessageInputStream message) { final DataInputStream dis = new DataInputStream(message); try { byte messageId = dis.readByte(); final int correlationId = dis.readInt(); log.tracef("Message Received id(%h), correlationId(%d)", messageId, correlationId); IoUtils.safeClose(dis); } finally { channel.receiveMessage(this);
try (MessageOutputStream out = channel.writeMessage()) { out.write(version); out.writeUTF("river"); channel.receiveMessage(new Channel.Receiver() { public void handleError(final Channel channel, final IOException error) { futureResult.setException(error); channel.closeAsync(); channel.addCloseHandler((closed, exception) -> futureResult.setException(e));
TransactionServerChannel(final RemotingTransactionServer server, final Channel channel, final LocalTransactionContext localTransactionContext) { this.server = server; this.channel = channel; this.localTransactionContext = localTransactionContext; messageTracker = new MessageTracker(channel, channel.getOption(RemotingOptions.MAX_OUTBOUND_MESSAGES).intValue()); channel.getConnection().getAttachments().attach(KEY, this); }
public void close() { try { channel.writeShutdown(); channel.close(); } catch (IOException e) { log.warn("Unable to close channel"); // Can't rely on the Receiver to have called this if we can't close down. remoteNotificationManager.removeNotificationListener(); } }
public void handleMessage(Channel channel, MessageInputStream messageInputStream) { DataInputStream dis = new DataInputStream(messageInputStream); try { log.tracef("Bytes Available %d", dis.available()); byte[] firstThree = new byte[3]; dis.read(firstThree); log.tracef("First Three %s", new String(firstThree)); if (Arrays.equals(firstThree, JMX_BYTES) == false) { channel.receiveMessage(this); return; log.error("Error determining version selected by client."); } finally { IoUtils.safeClose(dis);
final EJBMethodLocator methodLocator; final Connection connection = channel.getConnection(); final SecurityIdentity identity; if (version >= 3) { methodLocator = unmarshaller.readObject(EJBMethodLocator.class); int identityId = unmarshaller.readInt(); identity = identityId == 0 ? connection.getLocalIdentity() : connection.getLocalIdentity(identityId); } else { assert version <= 2; DataInputStream data = new DataInputStream(input); final String methodName = data.readUTF(); final String sigString = data.readUTF(); unmarshaller = marshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(data)); identity = connection.getLocalIdentity();
final EJBClientInvocationContext context = receiverInvocationContext.getClientInvocationContext(); if (version >= 3) try { final int cmd = inputStream.readUnsignedByte(); final XAOutflowHandle outflowHandle = getOutflowHandle(); if (outflowHandle != null) { safeClose(inputStream); break; final String message = inputStream.readUTF(); final EJBModuleIdentifier moduleIdentifier = receiverInvocationContext.getClientInvocationContext().getLocator().getIdentifier().getModuleIdentifier(); final NodeInformation nodeInformation = discoveredNodeRegistry.getNodeInformation(getChannel().getConnection().getRemoteEndpointName()); nodeInformation.removeModule(EJBClientChannel.this, moduleIdentifier); receiverInvocationContext.requestFailed(new NoSuchEJBException(message + " @ " + getChannel().getConnection().getPeerURI()), getRetryExecutor()); } catch (IOException e) { receiverInvocationContext.requestFailed(new EJBException("Failed to read 'No such EJB' response", e), getRetryExecutor()); } finally { safeClose(inputStream); receiverInvocationContext.requestFailed(new EJBException("Failed to read 'Bad EJB view type' response", e), getRetryExecutor()); } finally { safeClose(inputStream);
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, SERVER_CHANNEL_TYPE, configuration.getOptionMap()); if(setChannel(channel)) { channel.receiveMessage(channelHandler.getReceiver()); channel.addCloseHandler(channelHandler); } else { channel.closeAsync(); } }
protected void write(MessageWriter writer) throws IOException { CancellableDataOutputStream output = new CancellableDataOutputStream(channel.writeMessage()); try { writer.write(output); } catch (IOException e) { output.cancel(); throw e; } finally { IoUtils.safeClose(output); } }
public void channelOpened(final Channel channel) { final MessageTracker messageTracker = new MessageTracker(channel, channel.getOption(RemotingOptions.MAX_OUTBOUND_MESSAGES).intValue()); channel.receiveMessage(new Channel.Receiver() { public void handleError(final Channel channel, final IOException error) { } catch (InterruptedException e) { Thread.currentThread().interrupt(); safeClose(channel); } catch (IOException e) { safeClose(channel);
public void channelOpened(Channel channel) { log.trace("Channel Opened"); try { writeVersionHeader(channel, false); channel.receiveMessage(new ClientVersionReceiver(serverMessageInterceptorFactory.create(channel))); } catch (IOException e) { log.error("Unable to send header, closing channel", e); IoUtils.safeClose(channel); } }
@Override public HandleableCloseable.Key startReceiving(final Channel channel) { final ManagementChannelHandler channelHandler = new ManagementChannelHandler(channel, executorService); final ServerToHostProtocolHandler registrationHandler = new ServerToHostProtocolHandler(serverInventory.getValue(), operationExecutor, domainController, channelHandler, registrations, expressionResolver); channelHandler.addHandlerFactory(new ManagementPongRequestHandler()); channelHandler.addHandlerFactory(registrationHandler); channel.receiveMessage(channelHandler.getReceiver()); return null; }
@Override public ManagementChannelHandler startReceiving(Channel channel) { final ManagementChannelHandler handler = new ManagementChannelHandler(ManagementClientChannelStrategy.create(channel), getExecutor()); handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler, getResponseAttachmentSupport(), getClientRequestExecutor(), channel.getConnection().getLocalIdentity())); channel.receiveMessage(handler.getReceiver()); return handler; } }
public void channelOpened(Channel channel) { log.debugf("Channel Opened - %s", channel); channel.addCloseHandler(new ChannelCloseHandler()); try { writeHeader(channel); channel.receiveMessage(new ClientVersionReceiver()); } catch (IOException e) { logger.failedToSendHeader(e); IoUtils.safeClose(channel); } }
void start() { channel.receiveMessage(receiver); }
@Override public void connectionOpened(final Connection connection) throws IOException { final Channel channel = openChannel(connection, serviceType, channelOptions); if(setChannel(channel)) { channel.receiveMessage(receiver); } else { channel.closeAsync(); } }
@Override public Channel getChannel() throws IOException { if(channel == null) { synchronized (this) { if(channel == null) { final Connection connection = connect(); channel = openChannel(connection); channel.receiveMessage(handler.getReceiver()); } } } return channel; }
public Connection getConnection() { return channel.getConnection(); }
public void handleError(final Channel channel, final IOException error) { try { channel.close(); } catch (IOException ignored) { } }
/** * Construct a new instance. * * @param channel the channel that is being tracked * @param messageTracker the message tracker to use * @param intMasker the function to apply to ID numbers to limit them to a specific range */ public InvocationTracker(final Channel channel, final MessageTracker messageTracker, final IntUnaryOperator intMasker) { Assert.checkNotNullParam("channel", channel); Assert.checkNotNullParam("messageTracker", messageTracker); Assert.checkNotNullParam("intMasker", intMasker); this.messageTracker = messageTracker; channel.addCloseHandler((closed, exception) -> connectionClosed(exception)); this.intMasker = intMasker; }