[libinline-java-perl] 379/398: ok

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:27 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 290a2449548f066e2b61ff2e22ba7b8d682b9e50
Author: patrick_leb <>
Date:   Fri Apr 7 16:42:20 2006 +0000

    ok
---
 CHANGES                                            |  4 ++
 Java.pm                                            |  1 +
 Java.pod                                           | 21 +++++-
 Java/JVM.pm                                        |  5 +-
 Java/Makefile.PL                                   | 76 +++++++++++++++-------
 Java/Server.pm                                     | 16 +++--
 .../org/perl/inline/java/InlineJavaServer.java     | 22 +++++--
 META.yml                                           |  2 +-
 Makefile.PL                                        | 20 ++++++
 README                                             | 10 ++-
 t/shared.java                                      |  2 +-
 11 files changed, 131 insertions(+), 48 deletions(-)

diff --git a/CHANGES b/CHANGES
index aeae71e..5243ab0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,10 @@ Revision history for Perl extension Inline::Java
     - 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
+    - Added BUILD_JNI, BUILD_PERL_NATIVES, BUILD_PERL_INTERPRETER and JVM_LIB_TYPE build 
+      configuration options to help with automated builds
+    - Added BIND configuration option. See docs for details. 
+      Note: The Java JVM server noe listens on localhost by default (instead of 0.0.0.0).
     - Other minor bug fixes
 
 0.50  Mon Jan 31 20:14:43 EST 2005
diff --git a/Java.pm b/Java.pm
index d07d814..a47dc75 100644
--- a/Java.pm
+++ b/Java.pm
@@ -137,6 +137,7 @@ sub validate {
 	$o->set_option('J2SDK',					$jdk,			's', 1, \%opts) ;
 	$o->set_option('CLASSPATH',				'',				's', 1, \%opts) ;
 
+	$o->set_option('BIND',					'localhost',	's', 1, \%opts) ;
 	$o->set_option('HOST',					'localhost',	's', 1, \%opts) ;
 	$o->set_option('PORT',					-1,				'i', 1, \%opts) ;
 	$o->set_option('STARTUP_DELAY',			15,				'i', 1, \%opts) ;
diff --git a/Java.pod b/Java.pod
index 9f887b6..76bd267 100644
--- a/Java.pod
+++ b/Java.pod
@@ -157,6 +157,18 @@ 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.
 
+=item BIND
+
+Specifies the IP address on which the JVM server will be listening. By 
+default the JVM server listens for connections on 'localhost' only.
+
+   Ex: BIND => '192.168.1.1'
+   Ex: BIND => '0.0.0.0'
+
+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.
+
 =item STARTUP_DELAY
 
 Specifies the maximum number of seconds that the Perl script
@@ -607,9 +619,12 @@ 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.
+C<Inline::Java>. 
+Note: C<Inline::Java> uses eval under the hood, so it recommended that you
+store any exception in a temporary variable before processing it, especially
+f you will be calling other C<Inline::Java> functions. 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<>
 
 
diff --git a/Java/JVM.pm b/Java/JVM.pm
index 51d0ba1..9f641bf 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -72,6 +72,9 @@ sub new {
 		$this->{port} = $o->get_java_config('PORT') ;
 		$this->{host} = $o->get_java_config('HOST') ;
 
+		# Used to limit the bind of the JVM server
+		$this->{'bind'} = $o->get_java_config('BIND') ;
+
 		# Grab the next free port number and release it.
 		if ((! $this->{shared})&&($this->{port} < 0)){
 			if (Inline::Java::Portable::portable("GOT_NEXT_FREE_PORT")){
@@ -122,7 +125,7 @@ sub new {
 		my $shared = ($this->{shared} ? "true" : "false") ;
 		my $priv = ($this->{private} ? "true" : "false") ;
 		my $native_doubles = ($o->get_java_config('NATIVE_DOUBLES') ? "true" : "false") ;
-		my $cmd = Inline::Java::Portable::portable("SUB_FIX_CMD_QUOTES", "\"$java\" $args org.perl.inline.java.InlineJavaServer $debug $this->{port} $shared $priv $native_doubles") ;
+		my $cmd = Inline::Java::Portable::portable("SUB_FIX_CMD_QUOTES", "\"$java\" $args org.perl.inline.java.InlineJavaServer $debug $this->{bind} $this->{port} $shared $priv $native_doubles") ;
 		Inline::Java::debug(2, $cmd) ;
 		if ($o->get_config('UNTAINT')){
 			($cmd) = $cmd =~ /(.*)/ ;
diff --git a/Java/Makefile.PL b/Java/Makefile.PL
index a1c7b6c..d9d1ded 100644
--- a/Java/Makefile.PL
+++ b/Java/Makefile.PL
@@ -8,10 +8,10 @@ require "Portable.pm" ;
 # The file we just produced in the parent Makefile.PL
 require "default_j2sdk.pl" ;
 
-
-# Some shortcuts while developing
-my $jdk_dir = undef ;
-my $build_jni = ($jdk_dir ? 1 : 0) ;
+my $build_jni = $main::build_jni ;
+my $build_perl_natives = $main::build_perl_natives ;
+my $build_perl_interpreter = $main::build_perl_interpreter ;
+my $jvm_lib_type = $main::jvm_lib_type ;
 
 my $jvm_lib = Inline::Java::Portable::portable('JVM_LIB') ;
 my $jvm_so = Inline::Java::Portable::portable('JVM_SO') ;
@@ -50,22 +50,26 @@ foreach my $f (@files){
 }
 
 
-print
-	"\nInline::Java can use a JNI extension that allows the Java Virtual Machine\n" .
-	"(JVM) to be dynamically linked with Perl instead of running as a separate\n" .
-	"process. The use of this extension is optional, and building it still\n" .
-	"allows Inline::Java to run the JVM in the default (separate process)\n" .
-	"fashion.\n" .
-	"Note: You need a C compiler to build the extension.\n" .
-	"Note: You must build the extension if you wish to use PerlNatives or\n" .
-	"      PerlInterpreter.\n" ;
-
 my $build_jni_by_dflt = Inline::Java::Portable::portable("BUILD_JNI_BY_DFLT") ;
-if (($build_jni || AskYN("Do you wish to build the JNI extension?", 
-	($build_jni_by_dflt ? 'y' : 'n')))){
+if (! defined($build_jni)){
+	print
+		"\nInline::Java can use a JNI extension that allows the Java Virtual Machine\n" .
+		"(JVM) to be dynamically linked with Perl instead of running as a separate\n" .
+		"process. The use of this extension is optional, and building it still\n" .
+		"allows Inline::Java to run the JVM in the default (separate process)\n" .
+		"fashion.\n" .
+		"Note: You need a C compiler to build the extension.\n" .
+		"Note: You must build the extension if you wish to use PerlNatives or\n" .
+		"      PerlInterpreter.\n" ;
+	if (AskYN("Do you wish to build the JNI extension?", 
+		($build_jni_by_dflt ? 'y' : 'n'))){
+		$build_jni = 1 ;
+	}
+}
+if ($build_jni){
 	print "\nBuilding JNI extension.\n\n" ;
 
-	$jdk_dir = Inline::Java::get_default_j2sdk() ;
+	my $jdk_dir = Inline::Java::get_default_j2sdk() ;
 
 	my $symlink = Inline::Java::Portable::portable("GOT_SYMLINK") ;
 	find(
@@ -100,8 +104,20 @@ if (($build_jni || AskYN("Do you wish to build the JNI extension?",
 		elsif ($cnt == 1){
 			$files->{$f}->{selected} = $files->{$f}->{choices}->[0] ;
 		}
-		else{
-			Choose($f) ;
+		else {
+			my $choose = 1 ;
+			if (($f eq $jvm_lib)&&(defined($jvm_lib_type))){
+				my @matches = grep {/$jvm_lib_type/} @{$files->{$f}->{choices}} ;
+				if (! scalar(@matches)){
+					print "WARNING: No $f type matching '$jvm_lib_type' found.\n\n" ;
+				}
+				elsif (scalar(@matches) == 1){
+					print "Automatically selecting '$matches[0]' for $f type.\n\n" ;
+					$files->{$f}->{selected} = $matches[0] ;
+					$choose = 0 ;
+				}
+			}
+			Choose($f) if $choose ;
 		}
 	}
 	if (! $done){
@@ -133,27 +149,37 @@ if (($build_jni || AskYN("Do you wish to build the JNI extension?",
 					"-L" . $files->{$jvm_lib}->{selected})) ;
 
 			my $DIR = [] ;
-			print <<TXT;
+			if (! defined($build_perl_natives)){
+				print <<TXT;
 The PerlNatives extension allows for callbacks to be defined as native
 Java methods. It is still EXPERIMENTAL and may not build or work properly
 on all platforms. See documentation for more details.
 Note: PerlNatives requires J2SDK 1.4 or greater.
 TXT
-			if (AskYN("Do you wish to build the PerlNatives extension?", 'n')){
+				if (AskYN("Do you wish to build the PerlNatives extension?", 'n')){
+					$build_perl_natives = 1 ;
+				}
+				print "\n" ;
+			}
+			if ($build_perl_natives){
 				push @{$DIR}, 'PerlNatives' ;
 			}
-			print "\n" ;
 
-			print <<TXT;
+			if (! defined($build_perl_interpreter)){
+				print <<TXT;
 The PerlInterpreter extension allows Inline::Java to be loaded directly from
 Java using an embedded Perl interpreter. It is still EXPERIMENTAL and 
 may not build or work properly on all platforms. See documentation for 
 more details.
 TXT
-			if (AskYN("Do you wish to build the PerlInterpreter extension?", 'n')){
+				if (AskYN("Do you wish to build the PerlInterpreter extension?", 'n')){
+					$build_perl_interpreter = 1 ;
+				}
+				print "\n" ;
+			}
+			if ($build_perl_interpreter){
 				push @{$DIR}, 'PerlInterpreter' ;
 			}
-			print "\n" ;
 
 			WriteMakefile(
 				NAME => 'Inline::Java::JNI',
diff --git a/Java/Server.pm b/Java/Server.pm
index 258d6b2..7357c32 100644
--- a/Java/Server.pm
+++ b/Java/Server.pm
@@ -37,6 +37,8 @@ sub import {
 		push @actions, $a ;
 	}
 
+	my $host = $IJ->get_java_config("HOST") ;
+	my $bind = $IJ->get_java_config("BIND") ;
 	my $port = $IJ->get_java_config("PORT") ;
 	foreach $a (@actions){
 		if ($a eq 'sleep'){
@@ -48,29 +50,29 @@ sub import {
 
 		if ($a eq 'start'){
 			if ($status){
-				print "SHARED_JVM server on port $port is already running\n" ;
+				print "SHARED_JVM server on port $bind:$port is already running\n" ;
 			}
 			else{
 				Inline::Java::Server::start() ;
 				my $pid = Inline::Java::__get_JVM()->{pid} ;
-				print "SHARED_JVM server on port $port started with pid $pid\n" ;
+				print "SHARED_JVM server on port $bind:$port started with pid $pid\n" ;
 			}
 		}
 		elsif ($a eq 'stop'){
 			if (! $status){
-				print "SHARED_JVM server on port $port is not running\n" ;
+				print "SHARED_JVM server on port $host:$port is not running\n" ;
 			}
 			else {
 				Inline::Java::Server::stop() ;
-				print "SHARED_JVM server on port $port stopped\n" ;
+				print "SHARED_JVM server on port $host:$port stopped\n" ;
 			}
 		}
 		elsif ($a eq 'status'){
 			if ($status){
-				print "SHARED_JVM on port $port is running\n" ;
+				print "SHARED_JVM on port $host:$port is running\n" ;
 			}
 			else {
-				print "SHARED_JVM on port $port is not running\n" ;
+				print "SHARED_JVM on port $host:$port is not running\n" ;
 			}
 		}
 		else{
@@ -88,7 +90,7 @@ sub status {
 
 	eval {
 	    $socket = Inline::Java::JVM::setup_socket(
-	        "localhost",
+			$IJ->get_java_config("HOST"),
 			$IJ->get_java_config("PORT"),
 			0,
 			1
diff --git a/Java/sources/org/perl/inline/java/InlineJavaServer.java b/Java/sources/org/perl/inline/java/InlineJavaServer.java
index 5584f77..e18fcbc 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaServer.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaServer.java
@@ -11,6 +11,7 @@ import java.util.* ;
 */
 public class InlineJavaServer {
 	private static InlineJavaServer instance = null ;
+	private String host = null ;
 	private int port = 0 ;
 	private boolean shared_jvm = false ;
 	private boolean priv = false ;
@@ -37,16 +38,22 @@ public class InlineJavaServer {
 
 	// This constructor is used in server mode
 	// Normally one would then call RunMainLoop()
-	public InlineJavaServer(int debug, int _port, boolean _shared_jvm, boolean _priv, boolean _native_doubles){
+	public InlineJavaServer(int debug, String _host, int _port, boolean _shared_jvm, boolean _priv, boolean _native_doubles){
 		init(debug, _native_doubles) ;
 
 		jni = false ;
+		host = _host ;
 		port = _port ;
 		shared_jvm = _shared_jvm ;
 		priv = _priv ;
 
 		try {
-			server_socket = new ServerSocket(port) ;	
+			if ((host == null)||(host.equals(""))||(host.equals("ANY"))){
+				server_socket = new ServerSocket(port) ;
+			}
+			else {
+				server_socket = new ServerSocket(port, 0, InetAddress.getByName(host)) ;
+			}
 		}
 		catch (IOException e){
 			InlineJavaUtils.Fatal("Can't open server socket on port " + String.valueOf(port) +
@@ -300,12 +307,13 @@ public class InlineJavaServer {
 	*/
 	public static void main(String[] argv){
 		int debug = Integer.parseInt(argv[0]) ;
-		int port = Integer.parseInt(argv[1]) ;
-		boolean shared_jvm = new Boolean(argv[2]).booleanValue() ;
-		boolean priv = new Boolean(argv[3]).booleanValue() ;
-		boolean native_doubles = new Boolean(argv[4]).booleanValue() ;
+		String host = argv[1] ;
+		int port = Integer.parseInt(argv[2]) ;
+		boolean shared_jvm = new Boolean(argv[3]).booleanValue() ;
+		boolean priv = new Boolean(argv[4]).booleanValue() ;
+		boolean native_doubles = new Boolean(argv[5]).booleanValue() ;
 
-		InlineJavaServer ijs = new InlineJavaServer(debug, port, shared_jvm, priv, native_doubles) ;
+		InlineJavaServer ijs = new InlineJavaServer(debug, host, port, shared_jvm, priv, native_doubles) ;
 		ijs.RunMainLoop() ;
 		System.exit(0) ;
 	}
diff --git a/META.yml b/META.yml
index 02c2e99..939ccc7 100644
--- a/META.yml
+++ b/META.yml
@@ -1,7 +1,7 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Inline-Java
-version:      0.50_92
+version:      0.50_93
 version_from: Java.pm
 installdirs:  site
 requires:
diff --git a/Makefile.PL b/Makefile.PL
index 6bf5c4a..5a7a304 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,8 +12,28 @@ print "\nWelcome to the Inline::Java installation procedure.\n\n" ;
 # Grab the J2SDK argument
 my $jdk_dir = '' ;
 for (my $i = 0 ; $i < scalar(@ARGV) ; $i++){
+	my $remove = 0 ;
 	if ($ARGV[$i] =~ /^J2SDK=(.+)$/){
 		$jdk_dir = $1 ;
+		$remove = 1 ;
+	}
+	elsif ($ARGV[$i] =~ /^BUILD_JNI=(.+)$/){
+		$main::build_jni = $1 ;
+		$remove = 1 ;
+	}
+	elsif ($ARGV[$i] =~ /^BUILD_PERL_NATIVES=(.+)$/){
+		$main::build_perl_natives = $1 ;
+		$remove = 1 ;
+	}
+	elsif ($ARGV[$i] =~ /^BUILD_PERL_INTERPRETER=(.+)$/){
+		$main::build_perl_interpreter = $1 ;
+		$remove = 1 ;
+	}
+	elsif ($ARGV[$i] =~ /^JVM_LIB_TYPE=(.+)$/){
+		$main::jvm_lib_type = $1 ;
+		$remove = 1 ;
+	}
+	if ($remove){
 		splice(@ARGV, $i, 1) ;
 		$i-- ;
 	}
diff --git a/README b/README
index c1cbd20..d87d210 100644
--- a/README
+++ b/README
@@ -67,10 +67,10 @@ second time you test loading of an already built module.
 FEATURES FOR THIS VERSION:
 
 Inline::Java version 0.51 is a major upgrade that includes:
-    - Several major speed optimizations
-    - Introduction of support for I/O mapping between Perl and Java
+    - 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 
+    - 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
@@ -78,6 +78,10 @@ Inline::Java version 0.51 is a major upgrade that includes:
     - 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
+    - Added BUILD_JNI, BUILD_PERL_NATIVES, BUILD_PERL_INTERPRETER and JVM_LIB_TYPE build
+      configuration options to help with automated builds
+    - Added BIND configuration option. See docs for details.
+      Note: The Java JVM server noe listens on localhost by default (instead of 0.0.0.0).
     - Other minor bug fixes
 
 See CHANGES for a full change list.
diff --git a/t/shared.java b/t/shared.java
index c6c45d7..2409b40 100644
--- a/t/shared.java
+++ b/t/shared.java
@@ -4,7 +4,7 @@ class t10 {
 	public t10(){
 	}
 
-	public void incr(){
+	static synchronized public void incr(){
 		i++ ;
 	}
 }

-- 
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