inboundMessage = new InboundMessage((short) id, this, inboundWindow, maxInboundMessageSize); final InboundMessage existing = inboundMessages.putIfAbsent(inboundMessage); if (existing != null) { existing.handleDuplicate(); inboundMessage.handleIncoming(message); ok1 = true; } finally {
private void doAcknowledge(final Pooled<ByteBuffer> acked) { assert holdsLock(inputStream); if (eofReceived) { // no ack needed; also a best-effort to work around broken peers return; } final boolean badMsgSize = channel.getConnectionHandler().isFaultyMessageSize(); int consumed = acked.getResource().position(); if (! badMsgSize) consumed -= 8; // position minus header length (not including framing size) inboundWindow += consumed; Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_WINDOW_OPEN); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.putInt(consumed); // Open window by buffer size buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
if (bufRemaining > remaining) { cancelled = true; doClose(); doAcknowledge(pooledBuffer); doSendCloseMessage();
private void doClose() { assert holdsLock(inputStream); if (streamClosed) { // idempotent return; } streamClosed = true; // on close, send close message doSendCloseMessage(); // but keep the mapping around until we receive our EOF // else just keep discarding data until the EOF comes in. }
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 dumpState(final StringBuilder b) { final int state = channelState; final int inboundMessageCnt = (state & INBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_INBOUND_MESSAGE)); final int outboundMessageCnt = (state & OUTBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_OUTBOUND_MESSAGE)); b.append(" ").append(String.format("%s channel ID %08x summary:\n", (channelId & 0x80000000) == 0 ? "Inbound" : "Outbound", channelId)); b.append(" ").append("* Flags: "); if (Bits.allAreSet(state, READ_CLOSED)) b.append("read-closed "); if (Bits.allAreSet(state, WRITE_CLOSED)) b.append("write-closed "); b.append('\n'); b.append(" ").append("* ").append(inboundMessageQueue.size()).append(" pending inbound messages\n"); b.append(" ").append("* ").append(inboundMessageCnt).append(" (max ").append(maxInboundMessages).append(") inbound messages\n"); b.append(" ").append("* ").append(outboundMessageCnt).append(" (max ").append(maxOutboundMessages).append(") outbound messages\n"); b.append(" ").append("* Pending inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessageQueue) { inboundMessage.dumpState(b); } b.append(" ").append("* Inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessages) { inboundMessage.dumpState(b); } b.append(" ").append("* Outbound messages:\n"); for (OutboundMessage outboundMessage : outboundMessages) { outboundMessage.dumpState(b); } } }
private void doClose() { assert holdsLock(inputStream); if (streamClosed) { // idempotent return; } streamClosed = true; // on close, send close message doSendCloseMessage(); // but keep the mapping around until we receive our EOF // else just keep discarding data until the EOF comes in. }
public void run() { message.terminate(); } });
void dumpState(final StringBuilder b) { final int state = channelState; final int inboundMessageCnt = (state & INBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_INBOUND_MESSAGE)); final int outboundMessageCnt = (state & OUTBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_OUTBOUND_MESSAGE)); b.append(" ").append(String.format("%s channel ID %08x summary:\n", (channelId & 0x80000000) == 0 ? "Inbound" : "Outbound", channelId)); b.append(" ").append("* Flags: "); if (Bits.allAreSet(state, READ_CLOSED)) b.append("read-closed "); if (Bits.allAreSet(state, WRITE_CLOSED)) b.append("write-closed "); b.append('\n'); b.append(" ").append("* ").append(inboundMessageQueue.size()).append(" pending inbound messages\n"); b.append(" ").append("* ").append(inboundMessageCnt).append(" (max ").append(maxInboundMessages).append(") inbound messages\n"); b.append(" ").append("* ").append(outboundMessageCnt).append(" (max ").append(maxOutboundMessages).append(") outbound messages\n"); b.append(" ").append("* Pending inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessageQueue) { inboundMessage.dumpState(b); } b.append(" ").append("* Inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessages) { inboundMessage.dumpState(b); } b.append(" ").append("* Outbound messages:\n"); for (OutboundMessage outboundMessage : outboundMessages) { outboundMessage.dumpState(b); } } }
if (bufRemaining > remaining) { cancelled = true; doClose(); doAcknowledge(pooledBuffer); doSendCloseMessage();
inboundMessage = new InboundMessage((short) id, this, inboundWindow, maxInboundMessageSize); final InboundMessage existing = inboundMessages.putIfAbsent(inboundMessage); if (existing != null) { existing.handleDuplicate(); inboundMessage.handleIncoming(message); ok1 = true; } finally {
private void doSendCloseMessage() { assert holdsLock(inputStream); if (closeSent || ! channel.getConnectionHandler().isMessageClose()) { // we don't send a MESSAGE_CLOSE because broken versions will simply stop sending packets, and we won't know when the message is really gone. // the risk is that the remote side could have started a new message in the meantime, and our MESSAGE_CLOSE would kill the wrong message. // so this behavior is better than the alternative. return; } Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_CLOSE); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; closeSent = true; } finally { if (! ok) pooled.free(); } }
private void doClose() { assert holdsLock(inputStream); if (streamClosed) { // idempotent return; } streamClosed = true; // on close, send close message doSendCloseMessage(); // but keep the mapping around until we receive our EOF // else just keep discarding data until the EOF comes in. }
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 dumpState(final StringBuilder b) { final int state = channelState; final int inboundMessageCnt = (state & INBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_INBOUND_MESSAGE)); final int outboundMessageCnt = (state & OUTBOUND_MESSAGES_MASK) >>> (Integer.numberOfTrailingZeros(ONE_OUTBOUND_MESSAGE)); b.append(" ").append(String.format("%s channel ID %08x summary:\n", (channelId & 0x80000000) == 0 ? "Inbound" : "Outbound", channelId)); b.append(" ").append("* Flags: "); if (Bits.allAreSet(state, READ_CLOSED)) b.append("read-closed "); if (Bits.allAreSet(state, WRITE_CLOSED)) b.append("write-closed "); b.append('\n'); b.append(" ").append("* ").append(inboundMessageQueue.size()).append(" pending inbound messages\n"); b.append(" ").append("* ").append(inboundMessageCnt).append(" (max ").append(maxInboundMessages).append(") inbound messages\n"); b.append(" ").append("* ").append(outboundMessageCnt).append(" (max ").append(maxOutboundMessages).append(") outbound messages\n"); b.append(" ").append("* Pending inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessageQueue) { inboundMessage.dumpState(b); } b.append(" ").append("* Inbound messages:\n"); for (InboundMessage inboundMessage : inboundMessages) { inboundMessage.dumpState(b); } b.append(" ").append("* Outbound messages:\n"); for (OutboundMessage outboundMessage : outboundMessages) { outboundMessage.dumpState(b); } } }
if (bufRemaining > remaining) { cancelled = true; doClose(); doAcknowledge(pooledBuffer); doSendCloseMessage();
inboundMessage = new InboundMessage((short) id, this, inboundWindow, maxInboundMessageSize); final InboundMessage existing = inboundMessages.putIfAbsent(inboundMessage); if (existing != null) { existing.handleDuplicate(); inboundMessage.handleIncoming(message); ok1 = true; } finally {
private void doAcknowledge(final Pooled<ByteBuffer> acked) { assert holdsLock(inputStream); if (eofReceived) { // no ack needed; also a best-effort to work around broken peers return; } final boolean badMsgSize = channel.getConnectionHandler().isFaultyMessageSize(); int consumed = acked.getResource().position(); if (! badMsgSize) consumed -= 8; // position minus header length (not including framing size) inboundWindow += consumed; Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_WINDOW_OPEN); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.putInt(consumed); // Open window by buffer size buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
private void doAcknowledge(final Pooled<ByteBuffer> acked) { assert holdsLock(inputStream); if (eofReceived) { // no ack needed; also a best-effort to work around broken peers return; } final boolean badMsgSize = channel.getConnectionHandler().isFaultyMessageSize(); int consumed = acked.getResource().position(); if (! badMsgSize) consumed -= 8; // position minus header length (not including framing size) inboundWindow += consumed; Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_WINDOW_OPEN); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.putInt(consumed); // Open window by buffer size buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
private void doSendCloseMessage() { assert holdsLock(inputStream); if (closeSent || ! channel.getConnectionHandler().isMessageClose()) { // we don't send a MESSAGE_CLOSE because broken versions will simply stop sending packets, and we won't know when the message is really gone. // the risk is that the remote side could have started a new message in the meantime, and our MESSAGE_CLOSE would kill the wrong message. // so this behavior is better than the alternative. return; } Pooled<ByteBuffer> pooled = allocate(Protocol.MESSAGE_CLOSE); boolean ok = false; try { ByteBuffer buffer = pooled.getResource(); buffer.flip(); channel.getRemoteConnection().send(pooled); ok = true; closeSent = true; } finally { if (! ok) pooled.free(); } }