@Override public void doTask(final Task task) { if (task.getType() == Task.Type.CONNECT) { LOGGER.info("Client: Received CONNECT task"); try { LOGGER.info("Sending data to server"); task.getLink().send(getTestBytes()); } catch (ClosedChannelException e) { LOGGER.error(e.getMessage()); e.printStackTrace(); } } else if (task.getType() == Task.Type.DATA) { LOGGER.info("Client: Received DATA task"); } else if (task.getType() == Task.Type.DISCONNECT) { LOGGER.info("Client: Received DISCONNECT task"); stopClient(); } else if (task.getType() == Task.Type.OTHER) { LOGGER.info("Client: Received OTHER task"); } } }
public void register(SelectableChannel channel, int ops, Handler handler) { try { channel.register(selector, ops, handler); } catch (ClosedChannelException e) { e.printStackTrace(); } }
private <C> SelectionKey registerInterest(SelectableChannel c, int opKeys) { try { return c.register(_selector, opKeys); } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement throw new RuntimeException(e); } } }
private <C> SelectionKey registerInterest(SelectableChannel c, int opKeys) { try { return c.register(_selector, opKeys); } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement throw new RuntimeException(e); } } }
private <C> SelectionKey registerInterest(SelectableChannel c, int opKeys) { try { return c.register(_selector, opKeys); } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement throw new RuntimeException(e); } } }
public <C> Listener<C> createListener(String host, int port, C context) { try { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.configureBlocking(false); ServerSocket serverSocket = serverSocketChannel.socket(); serverSocket.bind(new InetSocketAddress(host, port)); return createListener(serverSocketChannel, context); } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement } catch (IOException e) { e.printStackTrace(); // TODO - Implement } return null; }
public <C> Listener<C> createListener(String host, int port, C context) { try { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); ServerSocket serverSocket = serverSocketChannel.socket(); serverSocket.bind(new InetSocketAddress(host, port)); serverSocketChannel.configureBlocking(false); Listener<C> listener = createListener(serverSocketChannel, context); _logger.fine("Created listener on " + host + ":" + port + ": " + context); return listener; } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement } catch (IOException e) { e.printStackTrace(); // TODO - Implement } return null; }
public <C> Listener<C> createListener(String host, int port, C context) { try { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); ServerSocket serverSocket = serverSocketChannel.socket(); serverSocket.bind(new InetSocketAddress(host, port)); serverSocketChannel.configureBlocking(false); Listener<C> listener = createListener(serverSocketChannel, context); _logger.fine("Created listener on " + host + ":" + port + ": " + context); return listener; } catch (ClosedChannelException e) { e.printStackTrace(); // TODO - Implement } catch (IOException e) { e.printStackTrace(); // TODO - Implement } return null; }
request.channel.register(selector, request.mask, request.listener); } catch (ClosedChannelException e) { e.printStackTrace();
@Override public void run() { while (true) { ByteBuffer byteBuffer = ByteBuffer.allocate(4); try { InetSocketAddress inetSocketAddress = (InetSocketAddress) datagramChannel.receive(byteBuffer); InetAddress inetAddress = inetSocketAddress.getAddress(); byteBuffer.flip(); int port = byteBuffer.getInt(); InetSocketAddress remoteInetSocketAddress = new InetSocketAddress(inetAddress, port); if (!("/" + agentChannelManagerAddress).equals(remoteInetSocketAddress.toString())) { (new OpenAgentChannel(remoteInetSocketAddress)).sendEvent(agentChannelManager); } } catch (ClosedByInterruptException cbie) { return; } catch (ClosedChannelException cce) { System.out.println("Discovery exception"); cce.printStackTrace(); return; } catch (Exception e) { agentChannelManager.getMailboxFactory().logException(false, "Discovery receiver threw unexpected exception", e); return; } } } });
void recv() { int nbytes = 0; // On windows, there may be a need to try several times until it succeeds while (nbytes == 0) { try { rdummy.clear(); nbytes = r.read(rdummy); } catch (ClosedChannelException e) { e.printStackTrace(); errno.set(ZError.EINTR); return; } catch (IOException e) { throw new ZError.IOException(e); } } assert (nbytes == 1); rcursor++; }
public void testConnection() { _testBytes = new byte[1000000]; randomGenerator.nextBytes(_testBytes); try { getOneMoreTest(); _clientLink.send(_testBytes); s_logger.info("Client: Data sent"); getOneMoreTest(); _clientLink.send(_testBytes); s_logger.info("Client: Data sent"); } catch (final ClosedChannelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** Adds a component's server to the selector. */ void registerComponentServer(TestReactorComponent component) { assertNotNull(component.server()); try { component.server().selectableChannel().register(_selector, SelectionKey.OP_ACCEPT); } catch (ClosedChannelException e) { e.printStackTrace(); fail("Caught ClosedChannelException"); } }
e.printStackTrace(); fail("Caught ClosedChannelException.");
void writeBuffer(TransportBuffer buffer) { int ret; ret = _channel.write(buffer, _writeArgs, _error); assertTrue(ret >= 0 || ret == TransportReturnCodes.WRITE_FLUSH_FAILED && _channel.state() == ChannelState.ACTIVE); while (ret > 0) { try { _channel.selectableChannel().register(_selector, SelectionKey.OP_WRITE, _channel); _selector.select(0); ret = _channel.flush(_error); } catch (ClosedChannelException e) { e.printStackTrace(); fail("Caught ClosedChannelException."); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException."); } assertTrue(ret >= 0); } }
e.printStackTrace(); fail("Caught ClosedChannelException.");
e.printStackTrace(); fail("Caught ClosedChannelException.");