In the case of the Server engine example it uses a single thread for doing everything from accepting connections to processing all of them thereafter, so it all needs to be asynchronous or it wouldnt work, presumably what you are seeing when trying to use blocking operations within that thread.
As Ted mentioned, the proton engine itself needs to be used by a single thread at a time, so in the case where you have an IO etc thread processing the proton engine, and another thread processing your data, you cant call methods on proton directly from that second thread. You need to pass the work off to the thead processing the engine in some manner. In a case like the example then you would need to wire in a way to wake up its Selector when there is new work to process, in case the thread is already awaiting IO activity. The same goes for any heartbeat processing requested by the client. There is a slightly higher level 'reactor' in the code base, and though it may not be suitable for you to use directly, its implementation details do show methods of doing the above things, since it has a 'wakeup' method that lets you notify it of work needing done from a different thread (which could then be processed on the reactor thread in the onReactorQuiesced handler callback), and schedules processing of sending any client-requested heartbeats using the 'tick' method on the Transport. There are examples for the reactor at https://github.com/apache/qpid-proton/tree/master/examples/java/reactor/src/main/java/org/apache/qpid/proton/example/reactor, specifically Send is a client and Recv is a server that talk to each other. The impl is at https://github.com/apache/qpid-proton/tree/master/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl, with e.g the IOHandler and ReactorImpl classes perhaps being of interest. Its worth noting that writing the IO bits yourself like the above examples/reactor, and using a single thread for everything, is just one option. Another would be using an existing IO framework that has its own support for passing tasks from other threads for execution on its IO threads. For example you could use Netty, allowing you to process the engine in the netty event loop and also have other threads indicate when there is data to handle by feeding the event loop tasks to run. Another potential advantage of this approach is each connection would be processed in its own even loop, with all the loops then being able to be spread across multiple threads if desired. You could look at the server bits of https://github.com/vert-x3/vertx-proton to get the general idea, its the same general idea but done at a slightly higher level and using Vert.x (which itself uses Netty). Robbie On 8 July 2016 at 21:44, Artem <[email protected]> wrote: > Ted, > > thanks a lot. May be Java experts help me later. > > Artem > > > > -- > View this message in context: > http://qpid.2158936.n2.nabble.com/Broker-with-live-data-tp7647047p7647139.html > Sent from the Apache Qpid users mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
