[zeromq-dev] Language binding guidelines

Chuck Remes cremes.devlist at mac.com
Mon Mar 1 19:24:34 CET 2010

On Mar 1, 2010, at 12:17 PM, Martin Sustrik wrote:

> Hi Chuck,
>> For the Java and Ruby cases, why not move to a factory pattern where
>> a class method instantiates and returns an object containing the
>> context and all of the other bits?
>> // Java z = ZMQ.factory(); s = z.makeSocket(ZMQ::PUB);
>> # Ruby z = ZMQ.factory s = z.make_socket ZMQ::PUB
>> This way there isn't any confusion about instantiating what looks
>> like a namespace.
> Yes. That's the same thing. It just renames context to factory.

Sure, but at least the syntax isn't as confusing as "new ZMQ()" which looks odd in every case.

>> I must say I prefer the hiding the context away. Whenever I am made
>> to pass the same parameter around I usually write a wrapper class for
>> it anyway just to handle it for me.
> Right. The problem is that context cannot be completely hidden. The reason why it exists at all is that several instances of 0MQ may get into the same process - think of linking your app with two libraries, each using 0MQ. Having a single global context would make the libraries interfere in unexpected ways.

I guess I wasn't completely clear. The factory method would create a new instance of context. Your response implied that the factory would really be a singleton which would certainly limit the usefulness of using 0mq with multiple libraries. I'm saying that each call to ZMQ.factory (or whatever) would spin up a whole new instance of context instead of returning the same one over and over.

No globals. :)


More information about the zeromq-dev mailing list