private Selectable timerSelectable() { Selectable sel = selectable(); sel.setChannel(wakeup.source()); sel.onReadable(new TimerReadable()); sel.onExpired(new TimerExpired()); sel.onFree(new TimerFree()); sel.setReading(true); sel.setDeadline(timer.deadline()); update(sel); return sel; }
@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) { Reactor reactor = selectable.getReactor(); Transport transport = ((SelectableImpl)selectable).getTransport(); long deadline = transport.tick(reactor.now()); selectable.setDeadline(deadline); int c = capacity(selectable); int p = pending(selectable); selectable.setReading(c > 0); selectable.setWriting(p > 0); reactor.update(selectable); } };
@Override public void run(Selectable selectable) { Reactor reactor = selectable.getReactor(); selectable.terminate(); reactor.update(selectable); } };
@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); } }
private static void update(Selectable selectable) { SelectableImpl selectableImpl = (SelectableImpl)selectable; int c = capacity(selectableImpl); int p = pending(selectableImpl); selectable.setReading(c > 0); selectable.setWriting(p > 0); selectable.setDeadline(deadline(selectableImpl)); }
protected static Selectable selectableTransport(Reactor reactor, Socket socket, Transport transport) { Selectable selectable = reactor.selectable(); selectable.setChannel(socket != null ? socket.getChannel() : null); selectable.onReadable(connectionReadable); selectable.onWritable(connectionWritable); selectable.onError(connectionError); selectable.onExpired(connectionExpired); selectable.onFree(connectionFree); ((SelectableImpl)selectable).setTransport(transport); ((TransportImpl)transport).setSelectable(selectable); ((TransportImpl)transport).setReactor(reactor); update(selectable); reactor.update(selectable); return selectable; }
private void initializeSelectable() { Selectable schedulerSelectable = this.reactor.selectable(); schedulerSelectable.setChannel(this.ioSignal.source()); schedulerSelectable.onReadable(this.workScheduler); schedulerSelectable.onFree(new CloseHandler()); schedulerSelectable.setReading(true); this.reactor.update(schedulerSelectable); }
@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(); } } }
private void handleQuiesced(Reactor reactor, Selector selector) throws IOException { // check if we are still quiesced, other handlers of // PN_REACTOR_QUIESCED could have produced more events to process if (!reactor.quiesced()) return; selector.select(reactor.getTimeout()); reactor.mark(); Iterator<Selectable> selectables = selector.readable(); while(selectables.hasNext()) { selectables.next().readable(); } selectables = selector.writeable(); while(selectables.hasNext()) { selectables.next().writeable(); } selectables = selector.expired(); while(selectables.hasNext()) { selectables.next().expired(); } selectables = selector.error(); while(selectables.hasNext()) { selectables.next().error(); } reactor.yield(); }
private void expireSelectable(Selectable selectable) { ReactorImpl reactor = (ReactorImpl) selectable.getReactor(); reactor.timer.tick(reactor.now); selectable.setDeadline(reactor.timer.deadline()); reactor.update(selectable); }
@Override public Reactor getReactor() { if (context instanceof Reactor) { return (Reactor) context; } else if (context instanceof Task) { return ((Task)context).getReactor(); } else if (context instanceof Transport) { return ((TransportImpl)context).getReactor(); } else if (context instanceof Delivery) { return ((Delivery)context).getLink().getSession().getConnection().getReactor(); } else if (context instanceof Link) { return ((Link)context).getSession().getConnection().getReactor(); } else if (context instanceof Session) { return ((Session)context).getConnection().getReactor(); } else if (context instanceof Connection) { return ((Connection)context).getReactor(); } else if (context instanceof Selectable) { return ((Selectable)context).getReactor(); } return null; }
long d = selectable.getDeadline(); if (d > 0) { deadline = (deadline == 0) ? d : Math.min(deadline, d); long deadline = selectable.getDeadline(); if (deadline > 0 && awoken >= deadline) { expired.add(selectable);
protected static Selectable selectableTransport(Reactor reactor, Socket socket, Transport transport) { Selectable selectable = reactor.selectable(); selectable.setChannel(socket != null ? socket.getChannel() : null); selectable.onReadable(connectionReadable); selectable.onWritable(connectionWritable); selectable.onError(connectionError); selectable.onExpired(connectionExpired); selectable.onFree(connectionFree); ((SelectableImpl)selectable).setTransport(transport); ((TransportImpl)transport).setSelectable(selectable); ((TransportImpl)transport).setReactor(reactor); update(selectable); reactor.update(selectable); return selectable; }
private void initializeSelectable() { Selectable schedulerSelectable = this.reactor.selectable(); schedulerSelectable.setChannel(this.ioSignal.source()); schedulerSelectable.onReadable(this.workScheduler); schedulerSelectable.onFree(new CloseHandler()); schedulerSelectable.setReading(true); this.reactor.update(schedulerSelectable); }
@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); } };
private static void update(Selectable selectable) { SelectableImpl selectableImpl = (SelectableImpl)selectable; int c = capacity(selectableImpl); int p = pending(selectableImpl); selectable.setReading(c > 0); selectable.setWriting(p > 0); selectable.setDeadline(deadline(selectableImpl)); }
private void handleQuiesced(Reactor reactor, Selector selector) throws IOException { // check if we are still quiesced, other handlers of // PN_REACTOR_QUIESCED could have produced more events to process if (!reactor.quiesced()) return; selector.select(reactor.getTimeout()); reactor.mark(); Iterator<Selectable> selectables = selector.readable(); while(selectables.hasNext()) { selectables.next().readable(); } selectables = selector.writeable(); while(selectables.hasNext()) { selectables.next().writeable(); } selectables = selector.expired(); while(selectables.hasNext()) { selectables.next().expired(); } selectables = selector.error(); while(selectables.hasNext()) { selectables.next().error(); } reactor.yield(); }
@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); } }
private void expireSelectable(Selectable selectable) { ReactorImpl reactor = (ReactorImpl) selectable.getReactor(); reactor.timer.tick(reactor.now); selectable.setDeadline(reactor.timer.deadline()); reactor.update(selectable); }