diff options
author | patrick_leb <> | 2003-11-23 22:18:04 +0000 |
---|---|---|
committer | patrick_leb <> | 2003-11-23 22:18:04 +0000 |
commit | 3dd9b2ff17a215ca776a10c193a321fb3c1cc3d6 (patch) | |
tree | 0532cc69aad4184cc1d18713d2e61d334b44ab52 | |
parent | 4272600c9d5a0efc7a14024647d9da6f77d231ca (diff) |
ok 0.44 RC2
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | Java.pod | 68 | ||||
-rw-r--r-- | Java/JNI.xs | 25 | ||||
-rw-r--r-- | Java/JVM.pm | 5 | ||||
-rw-r--r-- | Java/sources/InlineJavaServer.java | 5 | ||||
-rw-r--r-- | Java/sources/InlineJavaServerThread.java | 5 | ||||
-rw-r--r-- | README | 4 |
7 files changed, 80 insertions, 37 deletions
@@ -1,6 +1,11 @@ Revision history for Perl extension Inline::Java ------------------------------------------------ +0.44 Sun Nov 23 15:47:06 EST 2003 + - Callbacks from multiple threads are now supported. + - Refactored (again...) studying/.jdat/cache stuff + - Fixed memory leak in JNI coded (patch submitted by Dave Blob) + 0.43 Tue Oct 14 13:18:25 EDT 2003 - Restored $VERSION in each .pm file - Inline::Java now formerly requires Perl 5.6 @@ -187,6 +187,14 @@ behavior of C<Inline::Java>: 'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. + PRIVATE: + In SHARED_JVM mode, makes every connection to the JVM use a different + classloader so that each connection is isolated from the others. + Ex: PRIVATE => 1 + Note: This configuration option only has an effect on the first + 'use Inline Java' call inside a Perl script, since all other calls + make use of the same JVM. + DEBUG: Enables debugging info. Debugging now uses levels (1 through 5) that (loosely) follow these definitions: @@ -618,7 +626,7 @@ an "Inline::Java" object. Here is a example of a typical use: import org.perl.inline.java.* ; class Pod_regexp extends InlineJavaPerlCaller { - public Pod_regexp(){ + public Pod_regexp() throws InlineJavaException { } public boolean match(String target, String pattern) @@ -666,6 +674,64 @@ that $@ was a Perl scalar, you can use the GetString method). Z<> +=head1 CALLBACK LOOPS + +As of 0.44, it is now possible to use callbacks from differents Java threads. +One of the big advantages of this is that you can now handle, for example, +SWING events in Perl. Here's an example: + +=for comment + + use Inline Java => <<'END' ; + import java.util.* ; + import org.perl.inline.java.* ; + import javax.swing.* ; + import java.awt.event.* ; + + class Pod_Button extends InlineJavaPerlCaller + implements ActionListener { + public Pod_Button() throws InlineJavaException { + JFrame frame = new JFrame("Pod_Button") ; + frame.setSize(100,100) ; + JButton button = new JButton("Click Me!") ; + frame.getContentPane().add(button) ; + button.addActionListener(this) ; + frame.show() ; + } + + public void actionPerformed(ActionEvent e){ + try { + CallPerl("main", "button_pressed", new Object [] {}) ; + } + catch (InlineJavaPerlException pe){ } + catch (InlineJavaException pe) { pe.printStackTrace() ;} + } + } + END + + my $b = new Pod_Button() ; + $b->StartCallbackLoop() ; + + sub button_pressed { + print("click!\n") ; # prints click! + $b->StopCallbackLoop() ; + } + +=for comment + +The StartCallbackLoop method can be called on any InlineJavaPerlCaller object +and will block the current thread and allow the reception of callbacks through +any InlineJavaPerlCaller that has been created by the same (current) thread. +The only way to interrupt such a StartCallbackLoop method is to call the +StopCallbackLoop method on any InlineJavaPerlCaller object that has been created +by that same thread. + +Also, only threads that communicate with Perl through C<Inline::Java> are allowed +to create InlineJavaPerlCaller objects and invoke their StartCallbackLoop / +StopCallbackLoop methods. + Z<> + + =head1 STUDYING As of version 0.21, C<Inline::Java> can learn about other Java classes diff --git a/Java/JNI.xs b/Java/JNI.xs index 2798faa..80701a9 100644 --- a/Java/JNI.xs +++ b/Java/JNI.xs @@ -109,31 +109,6 @@ jstring JNICALL jni_callback(JNIEnv *env, jobject obj, jstring cmd){ } -/* This function loads up a Perl Interpreter */ -static PerlInterpreter *my_perl ; -JNIEXPORT void JNICALL Java_org_perl_inline_java_InlineJavaPerlInterpreter_jni_1load_1perl_1interpreter(JNIEnv *env, jobject obj){ - JNINativeMethod nm ; - jclass ijs_class ; - char *embedding[] = { "", "-e", "0" } ; - - /* Register the callback function */ - ijs_class = (*(env))->FindClass(env, "org/perl/inline/java/InlineJavaServer") ; - check_exception(env, "Can't find class InlineJavaServer") ; - - nm.name = "jni_callback" ; - nm.signature = "(Ljava/lang/String;)Ljava/lang/String;" ; - nm.fnPtr = jni_callback ; - (*(env))->RegisterNatives(env, ijs_class, &nm, 1) ; - check_exception(env, "Can't register method jni_callback in class InlineJavaServer") ; - - my_perl = perl_alloc() ; - perl_construct(my_perl) ; - - perl_parse(my_perl, NULL, 3, embedding, NULL) ; - perl_run(my_perl) ; -} - - MODULE = Inline::Java::JNI PACKAGE = Inline::Java::JNI diff --git a/Java/JVM.pm b/Java/JVM.pm index 378f435..8dba017 100644 --- a/Java/JVM.pm +++ b/Java/JVM.pm @@ -107,7 +107,8 @@ sub new { "java" . Inline::Java::portable("EXE_EXTENSION")) ; my $shared = ($this->{shared} ? "true" : "false") ; - my $cmd = Inline::Java::portable("SUB_FIX_CMD_QUOTES", "\"$java\" $args org.perl.inline.java.InlineJavaServer $debug $this->{port} $shared") ; + my $priv = ($this->{private} ? "true" : "false") ; + my $cmd = Inline::Java::portable("SUB_FIX_CMD_QUOTES", "\"$java\" $args org.perl.inline.java.InlineJavaServer $debug $this->{port} $shared $priv") ; Inline::Java::debug(2, $cmd) ; if ($o->get_config('UNTAINT')){ ($cmd) = $cmd =~ /(.*)/ ; @@ -289,8 +290,6 @@ sub setup_socket { } $socket->autoflush(1) ; - - print $socket (($this->{private} ? "private" : "public") . "\n") ; return $socket ; } diff --git a/Java/sources/InlineJavaServer.java b/Java/sources/InlineJavaServer.java index c68ac26..0ed1829 100644 --- a/Java/sources/InlineJavaServer.java +++ b/Java/sources/InlineJavaServer.java @@ -13,6 +13,7 @@ public class InlineJavaServer { private static InlineJavaServer instance = null ; private int port = 0 ; private boolean shared_jvm = false ; + private boolean priv = false ; private InlineJavaUserClassLoader ijucl = null ; private HashMap thread_objects = new HashMap() ; @@ -38,6 +39,7 @@ public class InlineJavaServer { jni = false ; port = Integer.parseInt(argv[1]) ; shared_jvm = new Boolean(argv[2]).booleanValue() ; + priv = new Boolean(argv[3]).booleanValue() ; ServerSocket ss = null ; try { @@ -51,7 +53,8 @@ public class InlineJavaServer { while (true){ try { String name = "IJST-#" + thread_count++ ; - InlineJavaServerThread ijt = new InlineJavaServerThread(name, this, ss.accept(), ijucl) ; + InlineJavaServerThread ijt = new InlineJavaServerThread(name, this, ss.accept(), + (priv ? new InlineJavaUserClassLoader() : ijucl)) ; ijt.start() ; if (! shared_jvm){ try { diff --git a/Java/sources/InlineJavaServerThread.java b/Java/sources/InlineJavaServerThread.java index 74e54ca..7c0248f 100644 --- a/Java/sources/InlineJavaServerThread.java +++ b/Java/sources/InlineJavaServerThread.java @@ -23,11 +23,6 @@ class InlineJavaServerThread extends Thread { new InputStreamReader(client.getInputStream())) ; bw = new BufferedWriter( new OutputStreamWriter(client.getOutputStream())) ; - - String security_type = br.readLine() ; - if (security_type.equals("private")){ - ijucl = new InlineJavaUserClassLoader() ; - } } @@ -71,9 +71,9 @@ WARNING: THIS IS ALPHA SOFTWARE. It is incomplete and possibly unreliable. change in future releases. Inline::Java version 0.44 is a major upgrade that includes: -+ Fixed memory leak in JNI coded (patch submitted by Dave Blob) -+ Fixed STUDY that was sometimes not studying (.jdat issue) + Callbacks from multiple threads are now supported. ++ Refactored (again...) studying/.jdat/cache stuff ++ Fixed memory leak in JNI coded (patch submitted by Dave Blob) Inline::Java version 0.43 is a minor upgrade that includes: + Restored $VERSION in each .pm file |