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

Martin Lucina mato at kotelna.sk
Thu Feb 25 16:58:54 CET 2010

Hi Gonzalo,

gdiethelm at dcv.cl said:
> It is in general very difficult to debug these kinds of bindings; Java
> code calls C / C++ code, and the only sure way of knowing what's going
> on in that code is through logging. Debuggers don't work well here
> because of the mixed environment.

Agreed, debugging language bindinds is painful.

> I have added a LOG() macro to the Java binding. It is called this way
> from the C / C++ code (notice the double parenthesis):
>   LOG(("Will poll socket 0x%p", socket));
> If the preprocessor macro ZMQ_JAVA_DEBUG is undefined or it is 0, this
> ends up being expanded to nothing and has zero cost at run time; if that
> macro is greater than zero, it ends up calling
>   zmq_java_log("Will poll socket 0x%p", socket);
> This function appends that message to a file called "/tmp/zmq_java.log".

I would suggest calling the macro ZMQ_JAVA_LOG instead of just LOG.  It is
good practice to not pollute the preprocessor namespace with "generic"
names. This is specific to the 0MQ Java binding so using a ZMQ_JAVA prefix
for macros "private" to that makes sense.

Also, please don't make the output go to a random hardcoded file. Instead,
use stderr and/or an environment variable (e.g. ZMQ_JAVA_LOG_FILE=..., if
present use that else use stderr). This makes it easier for someone else to
use the functionality without having to read the code to understand what
it's doing, and also prevents bad things happening should someone
inaverdently leave ZMQ_JAVA_DEBUG enabled.

> Question: would you accept a patch to create these two files and add
> lots of LOG() calls to Context.cpp / Socket.cpp, which by default will
> do nothing but which could be helpful in debugging this binding?

See above for my reservations. As Martin Sustrik has said elsewhere in this
thread we are trying to offload all except the C and C++ bindings from the
core 0MQ distribution, and that seems like a good way to go with the Java
binding also.

Thanks for your work on this!


More information about the zeromq-dev mailing list