[zeromq-dev] fun with Java API
Peter Friend
pfriend at gehrytech.com
Thu Nov 15 23:13:38 CET 2012
Perhaps I have missed it, but as far as I can tell there is no up-to-date reference for the Java zeromq bindings. But that's a minor issue as I can RTFS...
This has been a source of annoyance:
public ZContext() {
context = null; // Don't create Context until create 1st 0MQ socket
sockets = new CopyOnWriteArrayList<Socket>();
ioThreads = 1;
linger = 0;
main = true;
}
I am not sure why the context is not created at this point, but it can cause problems if you have an object which has callback hooks for registering/unregistering the sockets on a Poller. I create my objects which create their sockets and manage their connections, but I need to create a Poller before that point whether I am passing in the Poller explicitly, or referring to a global copy from an overridden method. Creating a socket and then ditching it is a workaround, but is annoying and you have to have a loud comment there so someone doesn't accidentally delete your obviously lame code which is creating a socket then immediately closing it. I am proposing this solution:
public Context getContext() {
if (isMain() && context == null)
context = ZMQ.context(ioThreads);
return context;
}
Of course if you want >1 thread you have to set that value before calling createSocket() or getContext().
Cheers,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121115/d0aef0fb/attachment.htm>
More information about the zeromq-dev
mailing list