@Override public synchronized void addWriteCredits(int delta) { wi.addCredits(delta); wi.adjustChannelWritability(); }
@Override public String toString() { return "Channel:" + channelId + "[localClose: " + localClose + " localCloseAck: " + localCloseAck + " remoteClose: " + remoteClose + " remoteCloseAck:" + remoteCloseAck + " readCredits: " + ri.getCredits() + " writeCredits: " + wi.getCredits() + "]"; }
synchronized void write(WriterState writerState) throws NetException { wi.write(writerState); }
public void abort(int ecode) { ccb.getWriteInterface().getFullBufferAcceptor().error(ecode); synchronized (NetworkOutputChannel.this) { aborted = true; NetworkOutputChannel.this.notifyAll(); } }
@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 synchronized void writeComplete() { wi.writeComplete(); }
public NetworkOutputChannel(ChannelControlBlock ccb, int nBuffers) { this.ccb = ccb; this.nBuffers = nBuffers; emptyStack = new ArrayDeque<>(nBuffers); ccb.getWriteInterface().setEmptyBufferAcceptor(new WriteEmptyBufferAcceptor()); }
@Override public void fail() throws HyracksDataException { ccb.getWriteInterface().getFullBufferAcceptor().error(AbstractChannelWriteInterface.REMOTE_ERROR_CODE); }
@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(); }
@Override public void close() throws HyracksDataException { ccb.getWriteInterface().getFullBufferAcceptor().close(); }
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 closeChannel(IChannelControlBlock ccb) { ccb.getWriteInterface().getFullBufferAcceptor().close(); }
ccb.getWriteInterface().getFullBufferAcceptor().accept(destBuffer);
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); }
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; } }