[zeromq-dev] Language binding guidelines

Martin Sustrik sustrik at 250bpm.com
Mon Mar 1 19:17:39 CET 2010


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.

The other piece here is using a different syntax for creating sockets 
(issue pointed out originally by Brian Granger):

s = z.makeSocket (ZMQ::PUB);

vs.

s = ZMQ::Socket.new(z, ZMQ::REP);

So far it seems that people prefer the former.

> 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.

Martin



More information about the zeromq-dev mailing list