void reportRemoteError(int ecode) { ri.flush(); ri.getFullBufferAcceptor().error(ecode); remoteClose.set(true); }
int getReadCredits() { return ri.getCredits(); }
synchronized int read(ISocketChannel sc, int size) throws IOException, NetException { return ri.read(sc, size); }
@Override public void channelOpened(ChannelControlBlock channel) { channel.getReadInterface().setFullBufferAcceptor(new InitialBufferAcceptor(channel)); channel.getReadInterface().getEmptyBufferAcceptor().accept(ByteBuffer.allocate(INITIAL_MESSAGE_SIZE)); } }
@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)); } }
@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(); }
@Override public void recycleBuffer(ByteBuffer buffer) { buffer.clear(); ccb.getReadInterface().getEmptyBufferAcceptor().accept(buffer); }
@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); }
void setReadCredits(int credits) { ri.setReadCredits(credits); }
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 channelOpened(ChannelControlBlock channel) { channel.getReadInterface().setFullBufferAcceptor(new InitialBufferAcceptor(channel)); channel.getReadInterface().getEmptyBufferAcceptor().accept(ByteBuffer.allocate(INITIAL_MESSAGE_SIZE)); } }
@Override public void recycleBuffer(ByteBuffer buffer) { buffer.clear(); ccb.getReadInterface().getEmptyBufferAcceptor().accept(buffer); }
@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(); }
synchronized void reportRemoteEOS() { ri.flush(); ri.getFullBufferAcceptor().close(); remoteClose.set(true); }
@Override public String toString() { return "Channel:" + channelId + "[localClose: " + localClose + " localCloseAck: " + localCloseAck + " remoteClose: " + remoteClose + " remoteCloseAck:" + remoteCloseAck + " readCredits: " + ri.getCredits() + " writeCredits: " + wi.getCredits() + "]"; }
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; } }