Hi,
I am trying to call perl from Java using
Inline::Java::Callback but it does not seem to work.
The details are as follows:
There are some async java functions that I am trying
to wrap in Perl. The async java functions are like:
AsyncJavaFunction(Sting someArgs,StatusListener obj),
so that when the function (or associated action) is
completed, the server calls the ListenerObject with
the status of the function call.
I am trying to replicate the same in Perl, with the
StatusListener being replaced by a PerlObject. So the
user would do something like this in Perl:

package perlObject;

sub new{
  my $class = shift;
  bless {}, $class;
}

package main;
my $login = somePackage->new;
my $obj = perlObject->new;
my $req_id = $login->async_perl_func($some_args,
$obj);
.
.............................
sub async_perl_func {
   my $self = shift;
   my $some_args = shift;
   my $callback = shift;

   my $listener =
MyPackage::Utils::get_listener($callback);
  $self->{obj}->AsyncJavaFunc($some_args,$listener)
}
----------------------------------------------------
MyPackage.Utils.pm
-----------------------------------------------------
package MyPackage::Utils;

use Inline (
    Java => <<'END_OF_JAVA',
import org.perl.inline.java.*;
import org.perl.inline.java.InlineJavaException;
import org.perl.inline.java.InlineJavaPerlException;

class IdStatusListener extends InlineJavaPerlCaller
implements StatusListener {
    InlineJavaPerlObject perlobj;
    
    public IdStatusListener(InlineJavaPerlObject
PerlObj) throws InlineJavaException {
         perlobj = PerlObj;
    }

    public void onStatus(String request_id, Status
status)  {
        try {
                System.out.println("recd call from java");
//Always get this printout;
                
perlobj.InvokeMethod("MyPackage::Utils::on_state", new
Object[] {request_id, status});  #does not work
           //CallPerlSub("MyPackage::Utils::on_state",
new Object[] {request_id,status}); #does not work
either!!!
        }

        catch (InlineJavaException e) {
            e.printStackTrace();
        }

        catch (InlineJavaPerlException e) {
            
        }
    }
}

END_OF_JAVA
);

sub get_listener {
  my $call_val = shift; 
  my $listener =
MyPackage::Utils::IdStatusListener->new($call_val);
return $listener;
}

sub on_state{
  print "\n recd call in perl"; #never prints out!!!
}

-----------------------------------------------------
So this code does not even call a perl subroutine even
when a callback from the server is received in the
java code. I am not sure what I am missing in the
above code.
Is there a better, more elegant way to wrap up async
calls?
Thanks in advance,
Sharmi



       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play 
Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  

Reply via email to