[zeromq-dev] Initial support for zmq_poll() under Java

gonzalo diethelm gdiethelm at dcv.cl
Wed Feb 24 23:11:44 CET 2010

> I have completed initial support for zmq_poll() in the Java binding.
> now it only supports ZMQ sockets. I will send a reply to this e-mail
> explaining the interface and implementation issues.

Now the details of this implementation...

The function is a member of org.zmq.Context and looks like this:

    public native long poll (Socket[] socket,
                             short[] event,
                             short[] revent,
                             long timeout);

It receives four arrays (which must match in size) with the sockets to
poll, the events to poll for in each socket, a place to receive the
results and a timeout in microseconds.

Issue #1: it is difficult to pass a single array of structures because
accessing such array from JNI is complex. I think it CAN be done, but I
decided to work on a simpler way first and later improve things, after
other eyes have had the chance to look at the code.

Issue #2: I would have liked to use an interface such as Set instead of
arrays, but accessing those from JNI seems to be even more complex or
even impossible.

Issue #3: adding Java / plain sockets to this method is not easy, may
not be portable and may even be impossible. For one thing, if you have a
java.net.Socket object, there is no portable way to access the
underlying socket descriptor. The only way I found is a hack that works
for Sun's JVM and is described here (post #2):


The second challenge is that Java has several different classes of
Sockets; we might ignore some of them, but I think we would want to
support at least java.net.Socket and java.net.ServerSocket.
Unfortunately, these classes share no common ancestor, so it is not
possible to pass them to Context.poll() in a single array, unless we use
an Object array and do some casting. And the way to get at the
underlying socket descriptor might vary across these classes too.

In summary, this is as far as I can get, for now, with poll under Java.
I will submit the patch soon, but if anybody has comments, criticism or
suggestions, they are welcome.

Best regards.

Gonzalo Diethelm

Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena. 
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje. 

"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law. 
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message. 

More information about the zeromq-dev mailing list