[libinline-java-perl] 244/398: on towards 0.44...

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:10 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 09359c13a6b4c5d79d54d3ab91fc576266a4a0a4
Author: patrick_leb <>
Date:   Thu Nov 20 02:22:56 2003 +0000

    on towards 0.44...
---
 Java.pm                                  |  4 ++-
 Java/JVM.pm                              |  3 ++
 Java/sources/InlineJavaServer.java       | 51 ++++++++++++++++++--------------
 Java/sources/InlineJavaServerThread.java |  9 ++++--
 4 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/Java.pm b/Java.pm
index 8944f19..1cd8aab 100644
--- a/Java.pm
+++ b/Java.pm
@@ -8,7 +8,7 @@ package Inline::Java ;
 use strict ;
 require 5.6.0 ;
 
-$Inline::Java::VERSION = '0.43' ;
+$Inline::Java::VERSION = '0.44' ;
 
 
 # DEBUG is set via the DEBUG config
@@ -128,6 +128,8 @@ sub validate {
 	$o->set_option('EXTRA_JAVA_ARGS',		'',		's', 1, \%opts) ;
 	$o->set_option('EXTRA_JAVAC_ARGS',		'',		's', 1, \%opts) ;
 
+	$o->set_option('PRIVATE',				'',		'b', 1, \%opts) ;
+
 	my @left_overs = keys(%opts) ;
 	if (scalar(@left_overs)){
 		croak "'$left_overs[0]' is not a valid configuration option for Inline::Java" ;
diff --git a/Java/JVM.pm b/Java/JVM.pm
index 23d76ce..378f435 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -33,6 +33,7 @@ sub new {
 	$this->{embedded} = $o->get_java_config('EMBEDDED_JNI') ;
 	$this->{owner} = 1 ;
 	$this->{destroyed} = 0 ;
+	$this->{private} = $o->get_java_config('PRIVATE') ;
 
 	if ($this->{embedded}){
 		Inline::Java::debug(1, "using embedded JVM...") ;
@@ -289,6 +290,8 @@ 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 79ac279..aa118bc 100644
--- a/Java/sources/InlineJavaServer.java
+++ b/Java/sources/InlineJavaServer.java
@@ -17,20 +17,23 @@ public class InlineJavaServer {
 	private InlineJavaUserClassLoader ijucl = null ;
 	private HashMap thread_objects = new HashMap() ;
 	private int objid = 1 ;
+	private boolean jni = false ;
 
 
 	// This constructor is used in JNI mode
-	public InlineJavaServer(int d){
+	private InlineJavaServer(int d){
 		init(d) ;
 
-		thread_objects.put(Thread.currentThread().getName(), new HashMap()) ;
+		jni = true ; 
+		thread_objects.put(Thread.currentThread(), new HashMap()) ;
 	}
 
 
 	// This constructor is used in server mode
-	public InlineJavaServer(String[] argv){
+	private InlineJavaServer(String[] argv){
 		init(new Integer(argv[0]).intValue()) ;
 
+		jni = false ;
 		port = Integer.parseInt(argv[1]) ;
 		shared_jvm = new Boolean(argv[2]).booleanValue() ;
 
@@ -150,16 +153,15 @@ public class InlineJavaServer {
 	
 	Object GetObject(int id) throws InlineJavaException {
 		Object o = null ;
-		String name = Thread.currentThread().getName() ;
-		HashMap h = (HashMap)thread_objects.get(name) ;
+		HashMap h = (HashMap)thread_objects.get(Thread.currentThread()) ;
 
 		if (h == null){
-			throw new InlineJavaException("Can't find thread " + name + "!") ;
+			throw new InlineJavaException("Can't find thread " + Thread.currentThread().getName() + "!") ;
 		}
 		else{
 			o = h.get(new Integer(id)) ;
 			if (o == null){
-				throw new InlineJavaException("Can't find object " + id + " for thread " + name) ;
+				throw new InlineJavaException("Can't find object " + id + " for thread " +Thread.currentThread().getName()) ;
 			}
 		}
 
@@ -168,12 +170,11 @@ public class InlineJavaServer {
 
 
 	synchronized int PutObject(Object o) throws InlineJavaException {
-		String name = Thread.currentThread().getName() ;
-		HashMap h = (HashMap)thread_objects.get(name) ;
+		HashMap h = (HashMap)thread_objects.get(Thread.currentThread()) ;
 
 		int id = objid ;
 		if (h == null){
-			throw new InlineJavaException("Can't find thread " + name + "!") ;
+			throw new InlineJavaException("Can't find thread " + Thread.currentThread().getName() + "!") ;
 		}
 		else{
 			h.put(new Integer(objid), o) ;
@@ -186,16 +187,15 @@ public class InlineJavaServer {
 
 	Object DeleteObject(int id) throws InlineJavaException {
 		Object o = null ;
-		String name = Thread.currentThread().getName() ;
-		HashMap h = (HashMap)thread_objects.get(name) ;
+		HashMap h = (HashMap)thread_objects.get(Thread.currentThread()) ;
 
 		if (h == null){
-			throw new InlineJavaException("Can't find thread " + name + "!") ;
+			throw new InlineJavaException("Can't find thread " + Thread.currentThread().getName() + "!") ;
 		}
 		else{
 			o = h.remove(new Integer(id)) ;
 			if (o == null){
-				throw new InlineJavaException("Can't find object " + id + " for thread " + name) ;
+				throw new InlineJavaException("Can't find object " + id + " for thread " + Thread.currentThread().getName()) ;
 			}
 		}
 
@@ -205,11 +205,10 @@ public class InlineJavaServer {
 
 	int ObjectCount() throws InlineJavaException {
 		int i = -1 ;
-		String name = Thread.currentThread().getName() ;
-		HashMap h = (HashMap)thread_objects.get(name) ;
+		HashMap h = (HashMap)thread_objects.get(Thread.currentThread()) ;
 
 		if (h == null){
-			throw new InlineJavaException("Can't find thread " + name + "!") ;
+			throw new InlineJavaException("Can't find thread " + Thread.currentThread().getName() + "!") ;
 		}
 		else{
 			i = h.values().size() ;
@@ -219,6 +218,12 @@ public class InlineJavaServer {
 	}
 
 
+	// So far this is the only method that can be called (indirectly) by the 
+	// user code to get back in to Perl. This means that this method really
+	// can be called by other threads the are not InlineJavaServerThreads...
+	//
+	// Is there a way to figure out which InlineJavaServerThread has created
+	// the current thread or is logically attached to it?
 	Object Callback(String pkg, String method, Object args[], String cast) throws InlineJavaException, InlineJavaPerlException {
 		Object ret = null ;
 
@@ -236,9 +241,9 @@ public class InlineJavaServer {
 
 			Thread t = Thread.currentThread() ;
 			String resp = null ;
-			while (true) {			
+			while (true) {
 				InlineJavaUtils.debug(3, "packet sent (callback) is " + cmd) ;
-				if (t instanceof InlineJavaServerThread){
+				if (! jni){
 					// Client-server mode
 					InlineJavaServerThread ijt = (InlineJavaServerThread)t ;
 					ijt.GetWriter().write(cmd + "\n") ;
@@ -285,13 +290,13 @@ public class InlineJavaServer {
 	native private String jni_callback(String cmd) ;
 
 
-	void AddThread(String name){
-		thread_objects.put(name, new HashMap()) ;
+	void AddThread(InlineJavaServerThread t){
+		thread_objects.put(t, new HashMap()) ;
 	}
 
 
-	void RemoveThread(String name){
-		thread_objects.remove(name) ;
+	void RemoveThread(InlineJavaServerThread t){
+		thread_objects.remove(t) ;
 	}
 	
 
diff --git a/Java/sources/InlineJavaServerThread.java b/Java/sources/InlineJavaServerThread.java
index d3aba87..0213e10 100644
--- a/Java/sources/InlineJavaServerThread.java
+++ b/Java/sources/InlineJavaServerThread.java
@@ -23,6 +23,11 @@ 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() ;
+		}
 	}
 
 
@@ -43,7 +48,7 @@ class InlineJavaServerThread extends Thread {
 
 	public void run(){
 		try {
-			ijs.AddThread(getName()) ;
+			ijs.AddThread(this) ;
 
 			while (true){
 				String cmd = br.readLine() ;
@@ -62,7 +67,7 @@ class InlineJavaServerThread extends Thread {
 			System.err.println("IO error: " + e.getMessage()) ;
 		}
 		finally {
-			ijs.RemoveThread(getName()) ;
+			ijs.RemoveThread(this) ;
 		}
 	}
 }

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