private void closeAllChannels() { final ArrayList<RemoteConnectionChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<RemoteConnectionChannel>(channels); } for (RemoteConnectionChannel channel : list) { channel.closeAsync(); } }
private void closePendingChannels() { final ArrayList<PendingChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<PendingChannel>(pendingChannels); } for (PendingChannel pendingChannel : list) { pendingChannel.getResult().setCancelled(); } }
public void receiveMessage(final Receiver handler) { synchronized (connection.getLock()) { if (inboundMessageQueue.isEmpty()) { if ((channelState & READ_CLOSED) != 0) { getExecutor().execute(() -> handler.handleEnd(RemoteConnectionChannel.this)); } else if (nextReceiver != null) { throw new IllegalStateException("Message handler already queued"); } else { nextReceiver = handler; } } else { final InboundMessage message = inboundMessageQueue.remove(); try { getExecutor().execute(() -> handler.handleMessage(RemoteConnectionChannel.this, message.messageInputStream)); } catch (Throwable t) { connection.handleException(new IOException("Fatal connection error", t)); return; } } connection.getLock().notify(); } }
private void notifyEnd() { synchronized (connection.getLock()) { if (nextReceiver != null) { final Receiver receiver = nextReceiver; nextReceiver = null; try { getExecutor().execute(() -> receiver.handleEnd(RemoteConnectionChannel.this)); } catch (Throwable t) { connection.handleException(new IOException("Fatal connection error", t)); return; } } } }
void dumpState(final StringBuilder b) { synchronized (remoteConnection.getLock()) { final int state = this.channelState; final boolean sentCloseReq = Bits.allAreSet(state, SENT_CLOSE_REQ); final boolean receivedCloseReq = Bits.allAreSet(state, RECEIVED_CLOSE_REQ); final int inboundChannels = (state & INBOUND_CHANNELS_MASK) >>> Integer.numberOfTrailingZeros(ONE_INBOUND_CHANNEL); final int outboundChannels = (state & OUTBOUND_CHANNELS_MASK) >>> Integer.numberOfTrailingZeros(ONE_OUTBOUND_CHANNEL); final Connection connection = remoteConnection.getConnection(); final SocketAddress localAddress = connection.getLocalAddress(); final SocketAddress peerAddress = connection.getPeerAddress(); b.append(" ").append("Connection ").append(localAddress).append(" <-> ").append(peerAddress).append('\n'); b.append(" ").append("Raw: ").append(connection).append('\n'); b.append(" ").append("* Flags: "); if (Bits.allAreSet(behavior, Protocol.BH_MESSAGE_CLOSE)) b.append("supports-message-close "); if (Bits.allAreSet(behavior, Protocol.BH_FAULTY_MSG_SIZE)) b.append("remote-faulty-message-size "); if (supportsRemoteAuth) b.append("auth-cap "); if (receivedCloseReq) b.append("received-close-req "); if (sentCloseReq) b.append("set-close-req "); b.append('\n'); b.append(" ").append("* ").append(inboundChannels).append(" (max ").append(maxInboundChannels).append(") inbound channels\n"); b.append(" ").append("* ").append(outboundChannels).append(" (max ").append(maxOutboundChannels).append(") outbound channels\n"); b.append(" ").append("* Channels:\n"); for (RemoteConnectionChannel connectionChannel : channels) { connectionChannel.dumpState(b); } } } }
private void closeMessages() { final List<InboundMessage> exceptionMessages; final List<OutboundMessage> cancelMessages; final List<InboundMessage> terminateMessages; synchronized (connection.getLock()) { exceptionMessages = new ArrayList<InboundMessage>(inboundMessages); cancelMessages = new ArrayList<OutboundMessage>(outboundMessages); terminateMessages = new ArrayList<InboundMessage>(inboundMessageQueue); inboundMessageQueue.clear(); } for (final InboundMessage message : exceptionMessages) { message.inputStream.pushException(new MessageCancelledException()); } for (final OutboundMessage message : cancelMessages) { message.cancel(); } for (final InboundMessage message : terminateMessages) { message.terminate(); } }
void handlePreAuthCloseRequest() { try { terminateHeartbeat(); synchronized (getLock()) { connection.close(); } } catch (IOException e) { Messages.conn.debug("Error closing remoting channel", e); } }
RemoteReadListener(final RemoteConnectionHandler handler, final RemoteConnection connection) { synchronized (connection.getLock()) { connection.getConnection().getCloseSetter().set((ChannelListener<Channel>) channel -> connection.getExecutor().execute(() -> { handler.handleConnectionClose(); handler.closeComplete(); })); } this.handler = handler; this.connection = connection; }
void handleException(IOException e, boolean log) { Messages.conn.logf(RemoteConnection.class.getName(), Logger.Level.TRACE, e, "Connection error detail"); if (log) { Messages.conn.connectionError(e); } final XnioExecutor.Key key = writeListener.heartKey; if (key != null) { key.remove(); } synchronized (getLock()) { IoUtils.safeClose(connection); } final Result<ConnectionHandlerFactory> result = this.result; if (result != null) { result.setException(e); this.result = null; } }
existing.handleDuplicate(); synchronized(connection.getLock()) { if (nextReceiver != null) { final Receiver receiver = nextReceiver;
public void handleEvent(final ConduitStreamSourceChannel channel) { SaslWrapper saslWrapper = connection.getSaslWrapper(); final Object lock = connection.getLock(); final MessageReader messageReader = connection.getMessageReader(); try {
private void closeAllChannels() { final ArrayList<RemoteConnectionChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<RemoteConnectionChannel>(channels); } for (RemoteConnectionChannel channel : list) { channel.closeAsync(); } }
private void closeAllChannels() { final ArrayList<RemoteConnectionChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<RemoteConnectionChannel>(channels); } for (RemoteConnectionChannel channel : list) { channel.closeAsync(); } }
private void closePendingChannels() { final ArrayList<PendingChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<PendingChannel>(pendingChannels); } for (PendingChannel pendingChannel : list) { pendingChannel.getResult().setCancelled(); } }
private void closePendingChannels() { final ArrayList<PendingChannel> list; synchronized (remoteConnection.getLock()) { list = new ArrayList<PendingChannel>(pendingChannels); } for (PendingChannel pendingChannel : list) { pendingChannel.getResult().setCancelled(); } }
private void notifyEnd() { synchronized (connection.getLock()) { if (nextReceiver != null) { final Receiver receiver = nextReceiver; nextReceiver = null; try { getExecutor().execute(() -> receiver.handleEnd(RemoteConnectionChannel.this)); } catch (Throwable t) { connection.handleException(new IOException("Fatal connection error", t)); return; } } } }
void setReadListener(ChannelListener<? super ConnectedMessageChannel> listener, final boolean resume) { RemoteLogger.log.logf(RemoteConnection.class.getName(), Logger.Level.TRACE, null, "Setting read listener to %s", listener); synchronized (getLock()) { channel.getReadSetter().set(listener); if (listener != null && resume) { channel.resumeReads(); } } }
void handlePreAuthCloseRequest() { try { terminateHeartbeat(); synchronized (getLock()) { connection.close(); } } catch (IOException e) { Messages.conn.debug("Error closing remoting channel", e); } }
void handleException(IOException e, boolean log) { Messages.conn.logf(RemoteConnection.class.getName(), Logger.Level.TRACE, e, "Connection error detail"); if (log) { Messages.conn.connectionError(e); } final XnioExecutor.Key key = writeListener.heartKey; if (key != null) { key.remove(); } synchronized (getLock()) { IoUtils.safeClose(connection); } final Result<ConnectionHandlerFactory> result = this.result; if (result != null) { result.setException(e); this.result = null; } }
RemoteReadListener(final RemoteConnectionHandler handler, final RemoteConnection connection) { synchronized (connection.getLock()) { connection.getConnection().getCloseSetter().set((ChannelListener<Channel>) channel -> connection.getExecutor().execute(() -> { handler.handleConnectionClose(); handler.closeComplete(); })); } this.handler = handler; this.connection = connection; }