private Handler eventHandler(Event event) { Handler result; if (event.getLink() != null) { result = BaseHandler.getHandler(event.getLink()); if (result != null) return result; } if (event.getSession() != null) { result = BaseHandler.getHandler(event.getSession()); if (result != null) return result; } if (event.getConnection() != null) { result = BaseHandler.getHandler(event.getConnection()); if (result != null) return result; } if (event.getTask() != null) { result = BaseHandler.getHandler(event.getTask()); if (result != null) return result; } if (event.getSelectable() != null) { result = BaseHandler.getHandler(event.getSelectable()); if (result != null) return result; } return handler; }
switch (e.getType()) { case CONNECTION_INIT: onConnectionInit(e); break; case CONNECTION_LOCAL_OPEN: onConnectionLocalOpen(e); break; case CONNECTION_REMOTE_OPEN: onConnectionRemoteOpen(e); break; case CONNECTION_LOCAL_CLOSE: onConnectionLocalClose(e); break; case CONNECTION_REMOTE_CLOSE: onConnectionRemoteClose(e); break; case CONNECTION_BOUND: onConnectionBound(e); break; case CONNECTION_UNBOUND: onConnectionUnbound(e); break; case CONNECTION_FINAL: onConnectionFinal(e); break; case SESSION_INIT: onSessionInit(e); break; case SESSION_LOCAL_OPEN:
@Override public Connection connection(Handler handler) { Connection connection = Proton.connection(); BaseHandler.setHandler(connection, handler); connection.collect(collector); children.add(connection); ((ConnectionImpl)connection).setReactor(this); return connection; }
public class MyClass implements Runnable{ BaseHandler handler = new BaseHandler(); public synchronized void go(){ for (int i = 0; i < 50000; i++) { handler.message = "Hello world! "; handler.printMessage( ); } } }
@Override public void run(Selectable selectable) { try { while (ioSignal.source().read(ByteBuffer.allocate(1024)) > 0) { // read until the end of the stream } } catch (ClosedChannelException ignorePipeClosedDuringReactorShutdown) { TRACE_LOGGER.info("ScheduleHandler.run() failed with an error", ignorePipeClosedDuringReactorShutdown); } catch (IOException ioException) { TRACE_LOGGER.warn("ScheduleHandler.run() failed with an error", ioException); throw new RuntimeException(ioException); } BaseHandler topWork; while ((topWork = workQueue.poll()) != null) { topWork.onTimerTask(null); } } }
protected ReactorImpl(IO io) throws IOException { collector = (CollectorImpl)Proton.collector(); global = new IOHandler(); handler = new BaseHandler(); children = new HashSet<ReactorChild>(); selectables = 0; timer = new Timer(collector); this.io = io; wakeup = this.io.pipe(); mark(); attachments = new RecordImpl(); }
@Override public void run(Selectable selectable) { try { ioSignal.source().read(ByteBuffer.allocate(1024)); } catch(ClosedChannelException ignorePipeClosedDuringReactorShutdown) { } catch(IOException ioException) { throw new RuntimeException(ioException); } BaseHandler topWork; while ((topWork = workQueue.poll()) != null) { topWork.onTimerTask(null); } } }
protected ReactorImpl(IO io, ReactorOptions options) throws IOException { collector = (CollectorImpl)Proton.collector(); global = new IOHandler(); handler = new BaseHandler(); children = new HashSet<ReactorChild>(); selectables = 0; timer = new Timer(collector); this.io = io; wakeup = this.io.pipe(); mark(); attachments = new RecordImpl(); this.options = options; }
switch (e.getType()) { case CONNECTION_INIT: onConnectionInit(e); break; case CONNECTION_LOCAL_OPEN: onConnectionLocalOpen(e); break; case CONNECTION_REMOTE_OPEN: onConnectionRemoteOpen(e); break; case CONNECTION_LOCAL_CLOSE: onConnectionLocalClose(e); break; case CONNECTION_REMOTE_CLOSE: onConnectionRemoteClose(e); break; case CONNECTION_BOUND: onConnectionBound(e); break; case CONNECTION_UNBOUND: onConnectionUnbound(e); break; case CONNECTION_FINAL: onConnectionFinal(e); break; case SESSION_INIT: onSessionInit(e); break; case SESSION_LOCAL_OPEN:
@Override public Connection connection(Handler handler) { Connection connection = Proton.connection(); BaseHandler.setHandler(connection, handler); connection.collect(collector); children.add(connection); ((ConnectionImpl)connection).setReactor(this); return connection; }
private Handler eventHandler(Event event) { Handler result; if (event.getLink() != null) { result = BaseHandler.getHandler(event.getLink()); if (result != null) return result; } if (event.getSession() != null) { result = BaseHandler.getHandler(event.getSession()); if (result != null) return result; } if (event.getConnection() != null) { result = BaseHandler.getHandler(event.getConnection()); if (result != null) return result; } if (event.getTask() != null) { result = BaseHandler.getHandler(event.getTask()); if (result != null) return result; } if (event.getSelectable() != null) { result = BaseHandler.getHandler(event.getSelectable()); if (result != null) return result; } return handler; }
@Override public Task schedule(int delay, Handler handler) { Task task = timer.schedule(now + delay); ((TaskImpl)task).setReactor(this); BaseHandler.setHandler(task, handler); if (selectable != null) { selectable.setDeadline(timer.deadline()); update(selectable); } return task; }
Handler handler = BaseHandler.getHandler(link); if (handler != null && handler instanceof BaseLinkHandler)
@Override public Task schedule(int delay, Handler handler) { Task task = timer.schedule(now + delay); ((TaskImpl)task).setReactor(this); BaseHandler.setHandler(task, handler); if (selectable != null) { selectable.setDeadline(timer.deadline()); update(selectable); } return task; }
final Handler handler = BaseHandler.getHandler(link); if (handler instanceof BaseLinkHandler) { final BaseLinkHandler linkHandler = (BaseLinkHandler) handler;
private void createSendLink(SenderLinkSettings linkSettings) { TRACE_LOGGER.info("Creating send link to '{}'", this.sendPath); final Connection connection = this.underlyingFactory.getConnection(); final Session session = connection.session(); session.setOutgoingWindow(Integer.MAX_VALUE); session.open(); BaseHandler.setHandler(session, new SessionHandler(sendPath)); final Sender sender = session.sender(linkSettings.linkName); sender.setTarget(linkSettings.target); sender.setSource(linkSettings.source); sender.setProperties(linkSettings.linkProperties); TRACE_LOGGER.debug("Send link settle mode '{}'", linkSettings.settleMode); sender.setSenderSettleMode(linkSettings.settleMode); SendLinkHandler handler = new SendLinkHandler(CoreMessageSender.this); BaseHandler.setHandler(sender, handler); sender.open(); this.sendLink = sender; this.underlyingFactory.registerForConnectionError(this.sendLink); }
final Handler handler = BaseHandler.getHandler(link); if (handler instanceof BaseLinkHandler) { final BaseLinkHandler linkHandler = (BaseLinkHandler) handler;
session.setIncomingCapacity(Integer.MAX_VALUE); session.open(); BaseHandler.setHandler(session, new SessionHandler(this.receivePath)); BaseHandler.setHandler(receiver, handler); receiver.open(); this.receiveLink = receiver;
@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(); } } }
protected AcceptorImpl(Reactor reactor, String host, int port, Handler handler) throws IOException { ServerSocketChannel ssc = ((ReactorImpl)reactor).getIO().serverSocketChannel(); ssc.bind(new InetSocketAddress(host, port)); sel = ((ReactorImpl)reactor).selectable(this); sel.setChannel(ssc); sel.onReadable(new AcceptorReadable()); sel.onFree(new AcceptorFree()); sel.setReactor(reactor); BaseHandler.setHandler(this, handler); sel.setReading(true); reactor.update(sel); }