diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2010-02-26 17:28:09 +0100 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2010-02-26 17:28:09 +0100 |
commit | deda7ca54a3c8f1ba735e8654ca87f8808606122 (patch) | |
tree | 5c4a4740d1a7ad045aa18a17e3bf7f68098f62b6 /bindings | |
parent | 4a1a83887d6faf36cb01f1c69142e6aafafe5eba (diff) |
Java Poller patch
Diffstat (limited to 'bindings')
-rwxr-xr-x | bindings/java/Context.cpp | 106 | ||||
-rw-r--r-- | bindings/java/Makefile.am | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | bindings/java/org/zmq/Context.java | 18 |
3 files changed, 18 insertions, 128 deletions
diff --git a/bindings/java/Context.cpp b/bindings/java/Context.cpp index 53ef0c9..5556ed8 100755 --- a/bindings/java/Context.cpp +++ b/bindings/java/Context.cpp @@ -24,8 +24,6 @@ #include "org_zmq_Context.h" -static void *fetch_socket (JNIEnv *env, jobject socket); - /** Handle to Java's Context::contextHandle. */ static jfieldID ctx_handle_fid = NULL; @@ -112,107 +110,3 @@ JNIEXPORT void JNICALL Java_org_zmq_Context_finalize (JNIEnv *env, put_context (env, obj, NULL); assert (rc == 0); } - -JNIEXPORT jlong JNICALL Java_org_zmq_Context_poll (JNIEnv *env, - jobject obj, - jobjectArray socket_0mq, - jshortArray event_0mq, - jshortArray revent_0mq, - jlong timeout) -{ - jsize ls_0mq = 0; - jsize le_0mq = 0; - jsize lr_0mq = 0; - - if (socket_0mq) - ls_0mq = env->GetArrayLength (socket_0mq); - if (event_0mq) - le_0mq = env->GetArrayLength (event_0mq); - if (revent_0mq) - lr_0mq = env->GetArrayLength (revent_0mq); - - if (ls_0mq != le_0mq || ls_0mq != lr_0mq) - return 0; - - jsize ls = ls_0mq; - if (ls <= 0) - return 0; - - zmq_pollitem_t *pitem = new zmq_pollitem_t [ls]; - short pc = 0; - int rc = 0; - - // Add 0MQ sockets. - if (ls_0mq > 0) { - jshort *e_0mq = env->GetShortArrayElements (event_0mq, 0); - if (e_0mq != NULL) { - for (int i = 0; i < ls_0mq; ++i) { - jobject s_0mq = env->GetObjectArrayElement (socket_0mq, i); - if (!s_0mq) - continue; - void *s = fetch_socket (env, s_0mq); - if (!s) - continue; - pitem [pc].socket = s; - pitem [pc].fd = 0; - pitem [pc].events = e_0mq [i]; - pitem [pc].revents = 0; - ++pc; - } - env->ReleaseShortArrayElements(event_0mq, e_0mq, 0); - } - } - - if (pc == ls) { - pc = 0; - long tout = (long) timeout; - rc = zmq_poll (pitem, ls, tout); - int err = 0; - const char *msg = ""; - if (rc < 0) { - err = errno; - msg = zmq_strerror (err); - } - } - - // Set 0MQ results. - if (ls_0mq > 0) { - jshort *r_0mq = env->GetShortArrayElements (revent_0mq, 0); - if (r_0mq) { - for (int i = 0; i < ls_0mq; ++i) { - r_0mq [i] = pitem [pc].revents; - ++pc; - } - env->ReleaseShortArrayElements(revent_0mq, r_0mq, 0); - } - } - - delete [] pitem; - return rc; -} - -/** - * Get the value of socketHandle for the specified Java Socket. - */ -static void *fetch_socket (JNIEnv *env, jobject socket) -{ - static jmethodID get_socket_handle_mid = NULL; - - if (get_socket_handle_mid == NULL) { - jclass cls = env->GetObjectClass (socket); - assert (cls); - get_socket_handle_mid = env->GetMethodID (cls, - "getSocketHandle", "()J"); - env->DeleteLocalRef (cls); - assert (get_socket_handle_mid); - } - - void *s = (void*) env->CallLongMethod (socket, get_socket_handle_mid); - if (env->ExceptionCheck ()) { - s = NULL; - } - - assert (s); - return s; -} - diff --git a/bindings/java/Makefile.am b/bindings/java/Makefile.am index e3d678f..f2da01c 100644 --- a/bindings/java/Makefile.am +++ b/bindings/java/Makefile.am @@ -12,15 +12,18 @@ jar_DATA = $(jarfile) dist_noinst_JAVA = \ org/zmq/Context.java \ - org/zmq/Socket.java + org/zmq/Socket.java \ + org/zmq/Poller.java lib_LTLIBRARIES = libjzmq.la libjzmq_la_SOURCES = \ Context.cpp \ - Socket.cpp + Socket.cpp \ + Poller.cpp nodist_libjzmq_la_SOURCES = \ org_zmq_Context.h \ - org_zmq_Socket.h + org_zmq_Socket.h \ + org_zmq_Poller.h libjzmq_la_CXXFLAGS = @JAVA_INCLUDE@ -I$(top_srcdir)/bindings/c -Wall libjzmq_la_LDFLAGS = -version-info @JLTVER@ @@ -30,13 +33,17 @@ BUILT_SOURCES = \ org/zmq/Context.class \ org_zmq_Context.h \ org/zmq/Socket.class \ - org_zmq_Socket.h + org_zmq_Socket.h \ + org/zmq/Poller.class \ + org_zmq_Poller.h CLEANFILES = \ org/zmq/Context.class \ org_zmq_Context.h \ org/zmq/Socket.class \ org_zmq_Socket.h \ + org/zmq/Poller.class \ + org_zmq_Poller.h \ Zmq.jar $(srcdir)/Context.cpp: org_zmq_Context.h @@ -53,6 +60,13 @@ org_zmq_Socket.h: org/zmq/Socket.class ./org/zmq/Socket.class: classdist_noinst.stamp +$(srcdir)/Poller.cpp: org_zmq_Poller.h + +org_zmq_Poller.h: org/zmq/Poller.class + $(CLASSPATH_ENV) $(JAVAH) -jni -classpath . org.zmq.Poller + +./org/zmq/Poller.class: classdist_noinst.stamp + dist-hook: -rm $(distdir)/*.h diff --git a/bindings/java/org/zmq/Context.java b/bindings/java/org/zmq/Context.java index 7a3552b..a727749 100644..100755 --- a/bindings/java/org/zmq/Context.java +++ b/bindings/java/org/zmq/Context.java @@ -26,10 +26,6 @@ public class Context { public static final int POLL = 1; - public static final int POLLIN = 1; - public static final int POLLOUT = 2; - public static final int POLLERR = 4; - /** * Class constructor. * @@ -40,20 +36,6 @@ public class Context { construct (appThreads, ioThreads, flags); } - /** - * Issue a poll call on the specified 0MQ sockets. - * This function is experimental and may change in the future. - * - * @param socket an array of 0MQ Socket objects to poll. - * @param event an array of short values specifying what to poll for. - * @param revent an array of short values with the results. - * @param timeout the maximum timeout in microseconds. - */ - public native long poll (Socket[] socket, - short[] event, - short[] revent, - long timeout); - /** Initialize the JNI interface */ protected native void construct (int appThreads, int ioThreads, int flags); |