ReaderState() { readBuffer = ByteBuffer.allocateDirect(MuxDemuxCommand.COMMAND_SIZE); command = new MuxDemuxCommand(); }
private ChannelControlBlock getCCBInCommand() { synchronized (MultiplexedConnection.this) { return cSet.getCCB(command.getChannelId()); } } }
@Override public void reset(ByteBuffer pendingBuffer, int pendingWriteSize, IChannelControlBlock ccb) { cmdWriteBuffer.clear(); command.write(cmdWriteBuffer); cmdWriteBuffer.flip(); this.pendingBuffer = pendingBuffer; this.pendingWriteSize = pendingWriteSize; this.ccb = ccb; }
int size = currentWriteBuffer.remaining(); if (size > 0) { writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.DATA); writerState.getCommand().setData(size); writerState.reset(currentWriteBuffer, size, ccb); } else { writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.ERROR); writerState.getCommand().setData(REMOTE_ERROR_CODE); writerState.reset(null, 0, null); ecodeSent = true; adjustChannelWritability(); } else if (isPendingCloseWrite()) { writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.CLOSE_CHANNEL); writerState.getCommand().setData(0); writerState.reset(null, 0, null); eosSent = true;
readerState.command.read(readerState.readBuffer); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Received command: " + readerState.command); switch (readerState.command.getCommandType()) { case ADD_CREDITS: { ccb = readerState.getCCBInCommand(); ccb.addWriteCredits(readerState.command.getData()); break; readerState.pendingReadSize = readerState.command.getData(); readerState.ccb = ccb; break; ccb.reportRemoteError(readerState.command.getData()); int channelId = ccb.getChannelId(); cSet.markEOSAck(channelId); int channelId = readerState.command.getChannelId(); ccb = cSet.registerChannel(channelId); muxDemux.getChannelOpenListener().channelOpened(ccb);
if (size > 0) { credits -= size; writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.DATA); writerState.getCommand().setData(size); writerState.reset(currentWriteBuffer, size, ccb); } else { writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.ERROR); writerState.getCommand().setData(REMOTE_ERROR_CODE); writerState.reset(null, 0, null); ecodeSent = true; adjustChannelWritability(); } else if (isPendingCloseWrite()) { writerState.getCommand().setChannelId(channelId); writerState.getCommand().setCommandType(MuxDemuxCommand.CommandType.CLOSE_CHANNEL); writerState.getCommand().setData(0); writerState.reset(null, 0, null); eosSent = true;
for (int j = pendingChannelSynBitmap.nextSetBit(0); j >= 0; j = pendingChannelSynBitmap.nextSetBit(j)) { pendingChannelSynBitmap.clear(j); writerState.command.setChannelId(j); writerState.command.setCommandType(MuxDemuxCommand.CommandType.OPEN_CHANNEL); writerState.command.setData(0); writerState.reset(null, 0, null); if (!writerState.performPendingWrite(sc)) { for (int j = pendingChannelCreditsBitmap.nextSetBit(0); j >= 0; j = pendingChannelCreditsBitmap.nextSetBit(j)) { writerState.command.setChannelId(j); writerState.command.setCommandType(MuxDemuxCommand.CommandType.ADD_CREDITS); ChannelControlBlock ccb = cSet.getCCB(j); int credits = ccb.getReadCredits(); ccb.setReadCredits(credits - effectiveCredits); writerState.command.setData(effectiveCredits); writerState.reset(null, 0, null); if (!writerState.performPendingWrite(sc)) { ChannelControlBlock ccb = cSet.getCCB(j); ccb.reportRemoteEOSAck(); writerState.command.setChannelId(j); writerState.command.setCommandType(MuxDemuxCommand.CommandType.CLOSE_CHANNEL_ACK); writerState.command.setData(0); writerState.reset(null, 0, null); if (!writerState.performPendingWrite(sc)) {
public WriterState() { cmdWriteBuffer = ByteBuffer.allocateDirect(MuxDemuxCommand.COMMAND_SIZE); cmdWriteBuffer.flip(); command = new MuxDemuxCommand(); ccb = null; }