@Override public void run(Selectable selectable) { try { if (selectable.getChannel() != null) { selectable.getChannel().close(); } } catch(IOException ioException) { // Ignore - as we can't make the channel any more closed... } } }
@Override public void run(Selectable selectable) { try { if (selectable.getChannel() != null) { selectable.getChannel().close(); } } catch(IOException ioException) { // Ignore - as we can't make the channel any more closed... } } }
@Override public void remove(Selectable selectable) { if (selectable.getChannel() != null) { SelectionKey key = selectable.getChannel().keyFor(selector); if (key != null) { key.cancel(); key.attach(null); } } selectables.remove(selectable); }
@Override public void remove(Selectable selectable) { if (selectable.getChannel() != null) { SelectionKey key = selectable.getChannel().keyFor(selector); if (key != null) { key.cancel(); key.attach(null); } } selectables.remove(selectable); }
@Override public void add(Selectable selectable) throws IOException { // Selectable can be 'null' - if this is the case it can only ever receive expiry events. if (selectable.getChannel() != null) { selectable.getChannel().configureBlocking(false); SelectionKey key = selectable.getChannel().register(selector, 0); key.attach(selectable); } selectables.add(selectable); update(selectable); }
@Override public void add(Selectable selectable) throws IOException { // Selectable can be 'null' - if this is the case it can only ever receive expiry events. if (selectable.getChannel() != null) { selectable.getChannel().configureBlocking(false); SelectionKey key = selectable.getChannel().register(selector, 0); key.attach(selectable); } selectables.add(selectable); update(selectable); }
@Override public void run(Selectable selectable) { try { selectable.getChannel().close(); } catch(IOException ioException) { // Ignore } } }
@Override public void run(Selectable selectable) { Channel channel = selectable.getChannel(); if (channel != null) { try { channel.close(); } catch(IOException ioException) { // Ignore } } } };
@Override public void run(Selectable selectable) { Channel channel = selectable.getChannel(); if (channel != null) { try { channel.close(); } catch(IOException ioException) { // Ignore } } } };
@Override public void run(Selectable selectable) { try { selectable.getChannel().close(); } catch(IOException ioException) { // Ignore } } }
@Override public void update(Selectable selectable) { if (selectable.getChannel() != null) { int interestedOps = 0; if (selectable.getChannel() instanceof SocketChannel && ((SocketChannel)selectable.getChannel()).isConnectionPending()) { interestedOps |= SelectionKey.OP_CONNECT; } else { if (selectable.isReading()) { if (selectable.getChannel() instanceof ServerSocketChannel) { interestedOps |= SelectionKey.OP_ACCEPT; } else { interestedOps |= SelectionKey.OP_READ; } } if (selectable.isWriting()) interestedOps |= SelectionKey.OP_WRITE; } SelectionKey key = selectable.getChannel().keyFor(selector); key.interestOps(interestedOps); } }
@Override public void update(Selectable selectable) { if (selectable.getChannel() != null) { int interestedOps = 0; if (selectable.getChannel() instanceof SocketChannel && ((SocketChannel)selectable.getChannel()).isConnectionPending()) { interestedOps |= SelectionKey.OP_CONNECT; } else { if (selectable.isReading()) { if (selectable.getChannel() instanceof ServerSocketChannel) { interestedOps |= SelectionKey.OP_ACCEPT; } else { interestedOps |= SelectionKey.OP_READ; } } if (selectable.isWriting()) interestedOps |= SelectionKey.OP_WRITE; } SelectionKey key = selectable.getChannel().keyFor(selector); key.interestOps(interestedOps); } }
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); try { SocketChannel socketChannel = ((ServerSocketChannel)selectable.getChannel()).accept(); if (socketChannel == null) { throw new ReactorInternalException("Selectable readable, but no socket to accept"); } Handler handler = BaseHandler.getHandler(AcceptorImpl.this); if (handler == null) { handler = reactor.getHandler(); } Connection conn = reactor.connection(handler); Transport trans = Proton.transport(); Sasl sasl = trans.sasl(); sasl.server(); sasl.setMechanisms("ANONYMOUS"); sasl.done(SaslOutcome.PN_SASL_OK); trans.bind(conn); IOHandler.selectableTransport(reactor, socketChannel.socket(), trans); } catch(IOException ioException) { sel.error(); } } }
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int capacity = transport.capacity(); if (capacity > 0) { SocketChannel socketChannel = (SocketChannel)selectable.getChannel(); try { int n = socketChannel.read(transport.tail()); if (n == -1) { transport.close_tail(); } else { transport.process(); } } catch (IOException e) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(e.getMessage()); transport.setCondition(condition); transport.close_tail(); } } // (Comment from C code:) occasionally transport events aren't // generated when expected, so the following hack ensures we // always update the selector update(selectable); reactor.update(selectable); } };
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int capacity = transport.capacity(); if (capacity > 0) { SocketChannel socketChannel = (SocketChannel)selectable.getChannel(); try { int n = socketChannel.read(transport.tail()); if (n == -1) { transport.close_tail(); } else { transport.process(); } } catch (IOException | TransportException e) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(e.getMessage()); transport.setCondition(condition); transport.close_tail(); } } // (Comment from C code:) occasionally transport events aren't // generated when expected, so the following hack ensures we // always update the selector update(selectable); reactor.update(selectable); } };
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending > 0) { SocketChannel channel = (SocketChannel)selectable.getChannel(); try { int n = channel.write(transport.head()); if (n < 0) { transport.close_head(); } else { transport.pop(n); } } catch(IOException ioException) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(ioException.getMessage()); transport.setCondition(condition); transport.close_head(); } } int newPending = transport.pending(); if (newPending != pending) { update(selectable); reactor.update(selectable); } } };
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); int pending = transport.pending(); if (pending > 0) { SocketChannel channel = (SocketChannel)selectable.getChannel(); try { int n = channel.write(transport.head()); if (n < 0) { transport.close_head(); } else { transport.pop(n); } } catch(IOException ioException) { ErrorCondition condition = new ErrorCondition(); condition.setCondition(Symbol.getSymbol("proton:io")); condition.setDescription(ioException.getMessage()); transport.setCondition(condition); transport.close_head(); } } int newPending = transport.pending(); if (newPending != pending) { update(selectable); reactor.update(selectable); } } };
Reactor reactor = selectable.getReactor(); try { SocketChannel socketChannel = ((ServerSocketChannel)selectable.getChannel()).accept(); if (socketChannel == null) { throw new ReactorInternalException("Selectable readable, but no socket to accept");
selectable.getChannel().close();