@Override public void recycleBuffer(ByteBuffer buffer) { buffer.clear(); ccb.getReadInterface().getEmptyBufferAcceptor().accept(buffer); }
public FullFrameChannelReadInterface(IChannelControlBlock ccb) { this.ccb = ccb; riEmptyStack = new LinkedBlockingDeque<>(); credits = 0; emptyBufferAcceptor = buffer -> { if (ccb.isRemotelyClosed()) { return; } final int delta = buffer.remaining(); riEmptyStack.push(buffer); ccb.addPendingCredits(delta); }; }
public AbstractChannelWriteInterface(IChannelControlBlock ccb) { this.ccb = ccb; this.channelId = ccb.getChannelId(); wiFullQueue = new ArrayDeque<>(); fba = new CloseableBufferAcceptor(); credits = 0; eos = false; eosSent = false; ecodeSent = false; }
@Override public void adjustChannelWritability() { boolean writable = computeWritability(); if (writable) { if (!channelWritabilityState) { ccb.markPendingWrite(); } } else { if (channelWritabilityState) { ccb.unmarkPendingWrite(); } } channelWritabilityState = writable; }
@Override public void open(IHyracksCommonContext ctx) throws HyracksDataException { try { ccb = netManager.connect(remoteAddress); } catch (Exception e) { throw HyracksDataException.create(e); } ccb.getReadInterface().setFullBufferAcceptor(new ReadFullBufferAcceptor()); ccb.getWriteInterface().setEmptyBufferAcceptor(new WriteEmptyBufferAcceptor()); for (int i = 0; i < nBuffers; ++i) { ccb.getReadInterface().getEmptyBufferAcceptor().accept(ctx.allocateFrame()); } ByteBuffer writeBuffer = ByteBuffer.allocate(INITIAL_MESSAGE_SIZE); writeBuffer.putLong(jobId.getId()); writeBuffer.putLong(resultSetId.getId()); writeBuffer.putInt(partition); writeBuffer.flip(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Sending partition request for JobId: " + jobId + " partition: " + partition + " on channel: " + ccb); } ccb.getWriteInterface().getFullBufferAcceptor().accept(writeBuffer); ccb.getWriteInterface().getFullBufferAcceptor().close(); }
private void closeChannel(IChannelControlBlock ccb) { ccb.getWriteInterface().getFullBufferAcceptor().close(); }
writerState.reset(null, 0, null); ecodeSent = true; ccb.reportLocalEOS(); adjustChannelWritability(); } else if (isPendingCloseWrite()) { writerState.reset(null, 0, null); eosSent = true; ccb.reportLocalEOS(); adjustChannelWritability();
@Override public void setBufferFactory(IBufferFactory bufferFactory, int limit, int frameSize) { super.setBufferFactory(bufferFactory, limit, frameSize); ccb.addPendingCredits(limit * frameSize); } }
@Override public void setBufferFactory(IBufferFactory bufferFactory, int limit, int frameSize) { if (!channelWritabilityState) { ccb.markPendingWrite(); } channelWritabilityState = true; if (eos) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Received duplicate close() on channel: " + channelId); } return; } eos = true; } }
ccb.writeComplete(); ccb = null;
@Override public void open(IHyracksCommonContext ctx) throws HyracksDataException { try { ccb = netManager.connect(remoteAddress); } catch (Exception e) { throw HyracksDataException.create(e); } ccb.getReadInterface().setFullBufferAcceptor(new ReadFullBufferAcceptor()); ccb.getWriteInterface().setEmptyBufferAcceptor(new WriteEmptyBufferAcceptor()); ccb.getReadInterface().setBufferFactory(new ReadBufferFactory(nBuffers, ctx), nBuffers, ctx.getInitialFrameSize()); ByteBuffer writeBuffer = ByteBuffer.allocate(INITIAL_MESSAGE_SIZE); writeBuffer.putLong(partitionId.getJobId().getId()); writeBuffer.putInt(partitionId.getConnectorDescriptorId().getId()); writeBuffer.putInt(partitionId.getSenderIndex()); writeBuffer.putInt(partitionId.getReceiverIndex()); writeBuffer.flip(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Sending partition request: " + partitionId + " on channel: " + ccb); } ccb.getWriteInterface().getFullBufferAcceptor().accept(writeBuffer); ccb.getWriteInterface().getFullBufferAcceptor().close(); }
private void sendMessageToChannel(IChannelControlBlock ccb, INcAddressedMessage msg) throws IOException { byte[] serializedMsg = JavaSerializationUtils.serialize(msg); if (serializedMsg.length > maxMsgSize) { throw new HyracksDataException("Message exceeded maximum size"); } // Prepare the message buffer ByteBuffer msgBuffer = messagingFramePool.get(); if (msgBuffer == null) { throw new HyracksDataException("Could not get an empty buffer"); } msgBuffer.clear(); msgBuffer.put(serializedMsg); msgBuffer.flip(); // Give the buffer to the channel write interface for writing ccb.getWriteInterface().getFullBufferAcceptor().accept(msgBuffer); }
writerState.reset(null, 0, null); ecodeSent = true; ccb.reportLocalEOS(); adjustChannelWritability(); } else if (isPendingCloseWrite()) { writerState.reset(null, 0, null); eosSent = true; ccb.reportLocalEOS(); adjustChannelWritability();
private IChannelControlBlock establishNewConnection(String nodeId) throws Exception { Map<String, NodeControllerInfo> nodeControllers = ncs.getNodeControllersInfo(); // Get the node messaging address from its info NodeControllerInfo nodeControllerInfo = nodeControllers.get(nodeId); if (nodeControllerInfo == null) { throw new NetException("Could not find node: " + nodeId); } NetworkAddress nodeMessagingNeAddress = nodeControllerInfo.getMessagingNetworkAddress(); SocketAddress nodeAddress = new InetSocketAddress(InetAddress.getByName(nodeMessagingNeAddress.getAddress()), nodeMessagingNeAddress.getPort()); // Open the channel IChannelControlBlock ccb = connect(nodeAddress); try { // Prepare the initial message buffer ByteBuffer initialBuffer = ccb.getReadInterface().getBufferFactory().createBuffer(); prepareMessagingInitialMessage(ncs.getId(), initialBuffer); // Send the initial messaging channel handshake message to register the opened channel on both nodes ccb.getWriteInterface().getFullBufferAcceptor().accept(initialBuffer); return ccb; } catch (NetException e) { closeChannel(ccb); throw e; } }
@Override public void recycleBuffer(ByteBuffer buffer) { buffer.clear(); ccb.getReadInterface().getEmptyBufferAcceptor().accept(buffer); }
@Override public void close() { synchronized (ccb) { if (eos) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Received duplicate close() on channel: " + ccb.getChannelId()); } return; } eos = true; if (ecode.get() != REMOTE_ERROR_CODE) { adjustChannelWritability(); } } }