public void setChannelId(int channelId) throws NetException { if (channelId > MAX_CHANNEL_ID) { throw new NetException("channelId " + channelId + " exceeds " + MAX_CHANNEL_ID); } this.channelId = channelId; }
public void setData(int data) throws NetException { if (data > MAX_DATA_VALUE) { throw new NetException("data " + data + " exceeds " + MAX_DATA_VALUE); } this.data = data; }
synchronized void waitUntilConnected() throws InterruptedException, NetException { while (tcpConnection == null && !connectionFailure) { wait(); } if (connectionFailure) { throw new NetException("Connection failure", error); } }
private void prepareMessagingInitialMessage(String ncId, final ByteBuffer buffer) throws NetException { /* * The messaging initial message contains the node id of the node * which requested the channel to be opened. */ int intialMsgLength = Integer.BYTES + ncId.length(); if (intialMsgLength > buffer.capacity()) { throw new NetException("Initial message exceded the channel buffer size " + buffer.capacity() + " bytes"); } buffer.clear(); buffer.putInt(ncId.length()); buffer.put(ncId.getBytes()); buffer.flip(); }
len = sc.read(currentReadBuffer); if (len < 0) { throw new NetException("Socket Closed");
len = sc.read(currentReadBuffer); if (len < 0) { throw new NetException("Socket Closed");
/** * 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; }
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; } }
int read = sc.read(readerState.readBuffer); if (read < 0) { throw new NetException("Socket Closed");