@Override public void addPendingCredits(int credit) { cSet.addPendingCredits(channelId, credit); }
ChannelControlBlock allocateChannel() throws NetException { synchronized (mConn) { cleanupClosedChannels(); int idx = allocationBitmap.nextClearBit(0); if (idx < 0 || idx >= ccbArray.length) { cleanupClosedChannels(); idx = allocationBitmap.nextClearBit(0); if (idx < 0 || idx == ccbArray.length) { idx = ccbArray.length; } } return createChannel(idx); } }
numCycles = cSet.getOpenChannelCount(); ChannelControlBlock writeCCB = null; synchronized (MultiplexedConnection.this) { BitSet pendingChannelSynBitmap = cSet.getPendingChannelSynBitmap(); for (int j = pendingChannelSynBitmap.nextSetBit(0); j >= 0; j = pendingChannelSynBitmap.nextSetBit(j)) { pendingChannelSynBitmap.clear(j); BitSet pendingChannelCreditsBitmap = cSet.getPendingChannelCreditsBitmap(); 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(); int effectiveCredits; BitSet pendingEOSAckBitmap = cSet.getPendingEOSAckBitmap(); for (int j = pendingEOSAckBitmap.nextSetBit(0); j >= 0; j = pendingEOSAckBitmap.nextSetBit(j)) { pendingEOSAckBitmap.clear(j); ChannelControlBlock ccb = cSet.getCCB(j); ccb.reportRemoteEOSAck(); writerState.command.setChannelId(j); BitSet pendingChannelWriteBitmap = cSet.getPendingChannelWriteBitmap(); lastChannelWritten = pendingChannelWriteBitmap.nextSetBit(lastChannelWritten + 1); if (lastChannelWritten == -1) { writeCCB = cSet.getCCB(lastChannelWritten);
/** * Open a channel to the other side. * * @return * @throws NetException * - A network failure occurred. */ public ChannelControlBlock openChannel() throws NetException { synchronized (this) { if (connectionFailure) { throw new NetException(error); } } ChannelControlBlock channel = cSet.allocateChannel(); int channelId = channel.getChannelId(); cSet.initiateChannelSyn(channelId); return channel; }
private ChannelControlBlock createChannel(int idx) throws NetException { if (idx > MuxDemuxCommand.MAX_CHANNEL_ID) { throw new NetException("Channel Id > " + MuxDemuxCommand.MAX_CHANNEL_ID + " being opened"); } if (idx >= ccbArray.length) { expand(idx); } if (ccbArray[idx] != null) { assert ccbArray[idx].completelyClosed() : ccbArray[idx].toString(); if (ccbArray[idx].completelyClosed()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Cleaning free channel: " + ccbArray[idx]); } freeChannel(ccbArray[idx]); } } assert idx < ccbArray.length; assert !allocationBitmap.get(idx); IChannelInterfaceFactory channelInterfaceFactory = mConn.getChannelInterfaceFactory(); ChannelControlBlock channel = new ChannelControlBlock(this, idx, channelInterfaceFactory); ccbArray[idx] = channel; allocationBitmap.set(idx); ++openChannelCount; return channel; }
ChannelControlBlock registerChannel(int channelId) throws NetException { synchronized (mConn) { return createChannel(channelId); } }
private ChannelControlBlock getCCBInCommand() { synchronized (MultiplexedConnection.this) { return cSet.getCCB(command.getChannelId()); } } }
public InetSocketAddress getRemoteAddress() { return cSet.getMultiplexedConnection().getRemoteAddress(); }
private void cleanupClosedChannels() { for (int i = 0; i < ccbArray.length; ++i) { ChannelControlBlock ccb = ccbArray[i]; if (ccb != null) { if (ccb.completelyClosed()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Cleaning free channel: " + ccb); } freeChannel(ccb); } } } }
MultiplexedConnection(MuxDemux muxDemux) { this.muxDemux = muxDemux; pendingWriteEventsCounter = new EventCounter(); cSet = new ChannelSet(this, pendingWriteEventsCounter); readerState = new ReaderState(); writerState = new WriterState(); lastChannelWritten = -1; connectionFailure = false; }