[libinline-java-perl] 373/398: ok. good for 0.50_92

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.55
in repository libinline-java-perl.

commit 07a78fc1964365323ea68f8964f093f5c706ab07
Author: patrick_leb <>
Date:   Thu Mar 2 21:59:52 2006 +0000

    ok. good for 0.50_92
---
 CHANGES           |   7 ++--
 Java.pod          |  43 ++++++++++++++++++++--
 Java/Callback.pod | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 README            |   6 ++++
 TODO              |   1 +
 5 files changed, 155 insertions(+), 7 deletions(-)

diff --git a/CHANGES b/CHANGES
index b03dfa0..aeae71e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,14 +1,17 @@
 Revision history for Perl extension Inline::Java
 ------------------------------------------------
 0.51
-    - Inline::Java now requires Perl 5.8.0 or greater.
     - Several major speed optimizations.
     - Introduction of support for I/O mapping between Perl and Java (Inline::Java::Handle)
     - Applied patches by Andrew Bruno and Tim Bunce for MAC OSX
     - JNI fix for system property passing
         (thanks to Brian Gugliemetti and Jason Stelzer)
     - Added NATIVE_DOUBLES configuration option to avoid loss of precision
-      whne passing double values between Perl and Java
+      when passing double values between Perl and Java
+    - New interface for processing callbacks from java to perl.
+    - Added support for java.lang.CharSequence as a primitive type. Any
+      Perl scalar passed as a java.lang.CharSequence will instantiate
+      a java.lang.String on the Java side
     - Other minor bug fixes
 
 0.50  Mon Jan 31 20:14:43 EST 2005
diff --git a/Java.pod b/Java.pod
index be024e1..203aef2 100644
--- a/Java.pod
+++ b/Java.pod
@@ -613,6 +613,45 @@ $@ is reset by the next eval.
    Z<>
 
 
+=head1 FILEHANDLES
+
+Java filehandles (java.io.Reader, java.io.Writer, java.io.InputStream or
+java.io.OutputStream objects) can be wrapped the C<Inline::Java::Handle>
+class to allow reading or writing from Perl. Here's an example:
+
+=for comment
+
+   use Inline Java => <<'END' ;
+      import java.io.* ;
+
+      class Pod_91 {
+         public static Reader getReader(String file) throws FileNotFoundException {
+           return new FileReader(file) ;
+         }
+      }
+   END
+
+    my $o = Pod_91->getReader('data.txt') ;
+    my $h = new Inline::Java::Handle($o) ;
+    while (<$h>){
+      chomp($_) ;
+      print($_ . "\n") ; # prints data
+    }
+
+
+=for comment
+
+What's important to understand is that $@ actually contains a reference
+to the Throwable object that was thrown by Java. The getMessage() function
+is really a method of the java.lang.Exception class. So if Java is throwing
+a custom exception you have in your code, you will have access to that
+exception object's public methods just like any other Java object in
+C<Inline::Java>. It is also probably a good idea to undef $@ once you have
+treated a Java exception, or else the object still has a reference until
+$@ is reset by the next eval.
+   Z<>
+
+
 =head1 CALLBACKS
 
 See L<Inline::Java::Callbacks> for more information on making callbacks.
@@ -955,7 +994,7 @@ the SHARED_JVM server in a CGI.
 
 Here is an example of how to use C<Inline::Java> under mod_perl:
 
-   use Apache::Constants ;
+   use Apache2::Const qw(:common) ;
    use Inline (
       Java => <<'END',
          class Pod_counter {
@@ -980,7 +1019,7 @@ Here is an example of how to use C<Inline::Java> under mod_perl:
          "This page has been accessed " . $c->{cnt} . " times." .
          $q->end_html() ;
 
-      return Apache::Constants::OK() ;
+      return OK ;
    }
 
 See USING Inline::Java IN A CGI for more details.
diff --git a/Java/Callback.pod b/Java/Callback.pod
index 2e2f796..feca097 100644
--- a/Java/Callback.pod
+++ b/Java/Callback.pod
@@ -233,7 +233,7 @@ in Perl. Here's an example:
             }
             catch (InlineJavaPerlException pe){
                // $@ is in pe.GetObject()
-			}
+            }
             catch (InlineJavaException pe) {
                pe.printStackTrace() ;
             }
@@ -242,7 +242,7 @@ in Perl. Here's an example:
          public void close(){
             frame.dispose() ;
             frame.hide() ;
-			frame = null ;
+            frame = null ;
          }
 
          public void quit(){
@@ -280,6 +280,105 @@ StartCallbackLoop / StopCallbackLoop methods.
    Z<>
 
 
+=head1 SELECT-STYLE CALLBACK LOOPS
+
+The disadvantage with the type of callback loop presented in the previous 
+section is that the main portion of the Perl program is completely blocked
+while waiting for callbacks. In version 0.51 a new API for callback loops 
+was introduced, allowing for callbacks to be processed much in the same 
+fashion one uses select(2) to read data from a filehandle. 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 {
+         JFrame frame = null ;
+
+         public Pod_Button() throws InlineJavaException {
+            frame = new JFrame("Pod_Button") ;
+            frame.setSize(100,100) ;
+            JButton button = new JButton("Click Me!") ;
+            frame.getContentPane().add(button) ;
+            button.addActionListener(this) ;
+            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) ; 
+            frame.show() ;
+         }
+
+         public void actionPerformed(ActionEvent e){
+            try {
+               CallPerlSub("main::button_pressed", new Object [] {}) ;
+            }
+            catch (InlineJavaPerlException pe){
+               // $@ is in pe.GetObject()
+            }
+            catch (InlineJavaException pe) {
+               pe.printStackTrace() ;
+            }
+         }
+
+         public void close(){
+            frame.dispose() ;
+            frame.hide() ;
+            frame = null ;
+         }
+
+         public void quit(){
+            System.exit(0) ;
+         }
+      }
+   END
+
+   my $b = new Pod_Button() ;  
+   $b->OpenCallbackStream() ;
+   while ((my $rc = $t->WaitForCallback(5)) > -1){
+      if ($rc > 0){
+         # A callback is pending, we must process it.
+         $t->ProcessNextCallback() ;
+      }
+      else {
+         # A timeout has occured after, in this case, 5 secs.
+         print "5 seconds have passed, still waiting for callback...\n" ;
+         # Maybe do some other stuff
+      }
+   }
+   $b->close() ;
+
+   # Maybe do some other stuff
+
+   exit() ;      # in client-server mode, optional
+   $b->quit() ;  # in JNI mode
+
+   sub button_pressed {
+      print('click!' . "\n") ; # prints click!
+      $b->CloseCallbackStream() ;
+   }
+
+=for comment
+
+The StartCallbackStream method can be called on any InlineJavaPerlCaller object
+to initialize a channel to receive callbacks. The WaitForCallback method can 
+then be called with a float timeout value (-1 means wait forever, 0 means return 
+immediately). The WaitForCallback method can return:
+
+   rc  >  0, indicating that rc callbacks are waiting to be processed
+   rc ==  0, indicating that a timeout has occured and no callbacks are waiting
+   rc == -1, indicating that the callback stream has been closed
+
+The callback stream can be closed by calling CloseCallbackStream, which works 
+similarly to the StopCallbackLoop method used in the previous section. 
+
+Also, the restrictions regarding thread communication stated in the previous
+section are valid in this case as well.
+   Z<>
+
+
 =head1 SEE ALSO
 
 L<Inline::Java>, L<Inline::Java::PerlNatives>, L<Inline::Java::PerlInterpreter>.
@@ -292,7 +391,7 @@ Patrick LeBoutillier <patl at cpan.org> is the author of Inline::Java.
 
 Brian Ingerson <ingy at cpan.org> is the author of Inline.
    Z<>
-
+ 
 
 =head1 COPYRIGHT
 
diff --git a/README b/README
index 88823dc..c1cbd20 100644
--- a/README
+++ b/README
@@ -72,6 +72,12 @@ Inline::Java version 0.51 is a major upgrade that includes:
     - Applied patches by Andrew Bruno and Tim Bunce for MAC OSX
     - JNI fix for system property passing 
         (thanks to Brian Gugliemetti and Jason Stelzer)
+    - Added NATIVE_DOUBLES configuration option to avoid loss of precision
+      when passing double values between Perl and Java
+    - New interface for processing callbacks from java to perl.
+    - Added support for java.lang.CharSequence as a primitive type. Any
+      Perl scalar passed as a java.lang.CharSequence will instantiate
+      a java.lang.String on the Java side
     - Other minor bug fixes
 
 See CHANGES for a full change list.
diff --git a/TODO b/TODO
index f8028e8..5ac2656 100644
--- a/TODO
+++ b/TODO
@@ -3,6 +3,7 @@ CODE:
 - Finish PerlHandle stuff and document
 
 DOCUMENTATION:
+- Document new Callback Interface
 - Document InlineJavaPerlObject when finished
 
 TEST:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git



More information about the Pkg-perl-cvs-commits mailing list