public JsonNode getState() { final ObjectNode state = JSONUtil.createObject(); state.put("id", channelId); state.put("localClose", localClose.get()); state.put("localCloseAck", localCloseAck.get()); state.put("remoteClose", remoteClose.get()); state.put("remoteCloseAck", remoteCloseAck.get()); state.put("readCredits", ri.getCredits()); state.put("writeCredits", wi.getCredits()); state.put("completelyClosed", completelyClosed()); return state; } }
private void freeChannel(ChannelControlBlock channel) { int idx = channel.getChannelId(); ccbArray[idx] = null; allocationBitmap.clear(idx); pendingChannelWriteBitmap.clear(idx); pendingChannelCreditsBitmap.clear(idx); pendingChannelSynBitmap.clear(idx); pendingEOSAckBitmap.clear(idx); --openChannelCount; }
void addPendingCredits(int channelId, int delta) { if (delta <= 0) { return; } synchronized (mConn) { ChannelControlBlock ccb = ccbArray[channelId]; if (ccb != null) { if (ccb.getRemoteEOS()) { return; } int oldCredits = ccb.getReadCredits(); ccb.setReadCredits(oldCredits + delta); if (oldCredits == 0) { assert !pendingChannelCreditsBitmap.get(channelId); pendingChannelCreditsBitmap.set(channelId); pendingWriteEventsCounter.increment(); } } } }
case ADD_CREDITS: { ccb = readerState.getCCBInCommand(); ccb.addWriteCredits(readerState.command.getData()); break; ccb.reportRemoteEOS(); int channelId = ccb.getChannelId(); cSet.markEOSAck(channelId); cSet.unmarkPendingCredits(channelId); ccb.reportLocalEOSAck(); break; ccb.reportRemoteError(readerState.command.getData()); int channelId = ccb.getChannelId(); cSet.markEOSAck(channelId); cSet.unmarkPendingCredits(channelId); int newPendingReadSize = readerState.ccb.read(sc, readerState.pendingReadSize); muxDemux.getPerformanceCounters().addPayloadBytesRead(readerState.pendingReadSize - newPendingReadSize); readerState.pendingReadSize = newPendingReadSize;
writerState.command.setCommandType(MuxDemuxCommand.CommandType.ADD_CREDITS); ChannelControlBlock ccb = cSet.getCCB(j); int credits = ccb.getReadCredits(); int effectiveCredits; if (credits <= MuxDemuxCommand.MAX_DATA_VALUE) { effectiveCredits = credits; ccb.setReadCredits(0); pendingChannelCreditsBitmap.clear(j); } else { effectiveCredits = MuxDemuxCommand.MAX_DATA_VALUE; ccb.setReadCredits(credits - effectiveCredits); pendingEOSAckBitmap.clear(j); ChannelControlBlock ccb = cSet.getCCB(j); ccb.reportRemoteEOSAck(); writerState.command.setChannelId(j); writerState.command.setCommandType(MuxDemuxCommand.CommandType.CLOSE_CHANNEL_ACK); writeCCB.write(writerState); if (writerState.writePending()) { pendingWriteEventsCounter.increment();
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; }
InetSocketAddress remoteAddress = ccb.getRemoteAddress(); String nameBefore = Thread.currentThread().getName(); try { ccb.getWriteInterface().getFullBufferAcceptor().accept(destBuffer);
public void abort(int ecode) { ccb.getWriteInterface().getFullBufferAcceptor().error(ecode); synchronized (NetworkOutputChannel.this) { aborted = true; NetworkOutputChannel.this.notifyAll(); } }
@Override public void channelOpened(ChannelControlBlock channel) { // Store the channel's original acceptor (which is set by the application) ICloseableBufferAcceptor fullBufferAcceptor = channel.getReadInterface().getFullBufferAcceptor(); synchronized (channelFullBufferAcceptor) { channelFullBufferAcceptor.put(channel, fullBufferAcceptor); } // Temporary set the acceptor to InitialBufferAcceptor to read the initial message channel.getReadInterface().setFullBufferAcceptor(new InitialBufferAcceptor(channel)); } }
public synchronized ArrayNode getState() { final ArrayNode state = JSONUtil.createArray(); for (ChannelControlBlock ccb : ccbArray) { if (ccb != null) { state.add(ccb.getState()); } } return state; } }
public NetworkOutputChannel(ChannelControlBlock ccb, int nBuffers) { this.ccb = ccb; this.nBuffers = nBuffers; emptyStack = new ArrayDeque<>(nBuffers); ccb.getWriteInterface().setEmptyBufferAcceptor(new WriteEmptyBufferAcceptor()); }
@Override public void accept(ByteBuffer buffer) { String nodeId = readMessagingInitialMessage(buffer); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Opened messaging channel with node: " + nodeId); } // Return the channel's original acceptor ICloseableBufferAcceptor originalAcceptor; synchronized (channelFullBufferAcceptor) { originalAcceptor = channelFullBufferAcceptor.remove(ccb); if (originalAcceptor == null) { throw new IllegalStateException("Could not find channel acceptor"); } } ccb.getReadInterface().setFullBufferAcceptor(originalAcceptor); addOpenChannel(nodeId, ccb); }
@Override public void fail() throws HyracksDataException { ccb.getWriteInterface().getFullBufferAcceptor().error(AbstractChannelWriteInterface.REMOTE_ERROR_CODE); }
@Override public void channelOpened(ChannelControlBlock channel) { channel.getReadInterface().setFullBufferAcceptor(new InitialBufferAcceptor(channel)); channel.getReadInterface().getEmptyBufferAcceptor().accept(ByteBuffer.allocate(INITIAL_MESSAGE_SIZE)); } }
/** * 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 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); } } } }
@Override public void close() throws HyracksDataException { ccb.getWriteInterface().getFullBufferAcceptor().close(); }
@Override public void channelOpened(ChannelControlBlock channel) { channel.getReadInterface().setFullBufferAcceptor(new InitialBufferAcceptor(channel)); channel.getReadInterface().getEmptyBufferAcceptor().accept(ByteBuffer.allocate(INITIAL_MESSAGE_SIZE)); } }