Java Code Examples for org.apache.qpid.proton.engine.Event#getSelectable()
The following examples show how to use
org.apache.qpid.proton.engine.Event#getSelectable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Echo.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onSelectableReadable(Event event) { Selectable selectable = event.getSelectable(); // The onSelectableReadable event tells us that there is data // to be read, or the end of stream has been reached. SourceChannel channel = (SourceChannel)selectable.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); try { while(true) { int amount = channel.read(buffer); if (amount < 0) { selectable.terminate(); selectable.getReactor().update(selectable); } if (amount <= 0) break; System.out.write(buffer.array(), 0, buffer.position()); buffer.clear(); } } catch(IOException ioException) { ioException.printStackTrace(); selectable.terminate(); selectable.getReactor().update(selectable); } }
Example 2
Source File: Cat.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onSelectableReadable(Event event) { Selectable selectable = event.getSelectable(); // The onSelectableReadable event tells us that there is data // to be read, or the end of stream has been reached. SourceChannel channel = (SourceChannel)selectable.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); try { while(true) { int amount = channel.read(buffer); if (amount < 0) { selectable.terminate(); selectable.getReactor().update(selectable); } if (amount <= 0) break; System.out.write(buffer.array(), 0, buffer.position()); buffer.clear(); } } catch(IOException ioException) { ioException.printStackTrace(); selectable.terminate(); selectable.getReactor().update(selectable); } }
Example 3
Source File: Echo.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSelectableInit(Event event) { Selectable selectable = event.getSelectable(); // We can configure a selectable with any SelectableChannel we want. selectable.setChannel(channel); // Ask to be notified when the channel is readable selectable.setReading(true); event.getReactor().update(selectable); }
Example 4
Source File: Cat.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSelectableInit(Event event) { Selectable selectable = event.getSelectable(); // We can configure a selectable with any SelectableChannel we want. selectable.setChannel(channel); // Ask to be notified when the channel is readable selectable.setReading(true); event.getReactor().update(selectable); }
Example 5
Source File: ReactorImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
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; }
Example 6
Source File: IOHandler.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Override public void onUnhandled(Event event) { try { ReactorImpl reactor = (ReactorImpl)event.getReactor(); Selector selector = reactor.getSelector(); if (selector == null) { selector = new SelectorImpl(reactor.getIO()); reactor.setSelector(selector); } Selectable selectable; switch(event.getType()) { case SELECTABLE_INIT: selectable = event.getSelectable(); selector.add(selectable); break; case SELECTABLE_UPDATED: selectable = event.getSelectable(); selector.update(selectable); break; case SELECTABLE_FINAL: selectable = event.getSelectable(); selector.remove(selectable); selectable.release(); break; case CONNECTION_LOCAL_OPEN: handleOpen(reactor, event); break; case CONNECTION_BOUND: handleBound(reactor, event); break; case TRANSPORT: handleTransport(reactor, event); break; case TRANSPORT_CLOSED: event.getTransport().unbind(); break; case REACTOR_QUIESCED: handleQuiesced(reactor, selector); break; default: break; } } catch(IOException ioException) { // XXX: Might not be the right exception type, but at least the exception isn't being swallowed throw new ReactorInternalException(ioException); } }