Hi,

I'm not sure if what I want to do can be done with Inline::Java (or maybe
I'm approaching it incorrectly).

My Java code starts another thread which sits reads a socket, and makes
callbacks to an object in the first thread (which then makes a callback to
perl).  So far so good, it all works.

But once I start my callback loop, I can't continue processing my perl code.

What I was hoping I could do, was start my Java, which would run
independently, calling back to my perl.  Meanwhile my perl could continue
processing.

Below is all the code.

Any direction would be much appreciated.
Thanks
Jay

---------
#!/usr/bin/perl

use InteractiveBrokers::TWS;
my ($tws,$api) = InteractiveBrokers::TWS->new;

$tws->eConnect("",7496,0);

use InteractiveBrokers::TWS::Contract;
my $contract = InteractiveBrokers::TWS::Contract->new;

$contract->{m_symbol} = 'AMZN';
$contract->{m_secType} = 'STK';
$contract->{m_exchange} = "SMART";

$tws->reqMktData(404,$contract);

$api->StartCallbackLoop;
# ***********
#  I can't get to this code
#
$contract->{m_symbol} = 'IBM';
$contract->{m_secType} = 'STK';
$contract->{m_exchange} = "SMART";

$tws->reqMktData(405,$contract);

>>>
package InteractiveBrokers::TWS;

use strict;
my $api;

use base qw(Class::Accessor);
#__PACKAGE__->mk_accessors(qw/api/);

use Inline (
    Java      => 'DATA',
    CLASSPATH => '/home/jstrauss/IB/IBJts/java',
    STUDY     => ['com.ib.client.EClientSocket'],
    PORT      => 7890,
);

sub new {
    my $class = shift;
    my $self = $class->SUPER::new([EMAIL PROTECTED]);
    $api = InteractiveBrokers::TWS::TWSAPI->new(__PACKAGE__);

    my $name = __PACKAGE__."::com::ib::client::EClientSocket";
    my $socket = $name->new($api);

    return ($socket, $api);
}

sub tickPrice {
    my @args = @_;
    print "In perl tickPrice: ",join("\t",@args),"\n";
}

sub tickSize {
    my @args = @_;
    print "In my tickSize: ",join("\t",@args),"\n";
}

sub error {
    print "In perl I was called with: ", shift,"\n";
}

1;

__DATA__
__Java__

import org.perl.inline.java.* ;
import com.ib.client.*;

public class TWSAPI extends InlineJavaPerlCaller
                          implements EWrapper {

    public int id = 0;
    String module = null;

    public TWSAPI(String m)  throws InlineJavaException  {
        module = m;
    }

    public void tickPrice(int tickerId, int field, double price) {
          try {
                 CallPerl(module, "tickPrice", new Object [] {
                     String.valueOf(tickerId),
                     String.valueOf(field),
                     String.valueOf(price),
                 }) ;
          }
          catch (InlineJavaPerlException pe){ }
          catch (InlineJavaException pe) { pe.printStackTrace() ;}
    }

    public void tickSize(int tickerId, int field, int size) {
          try {
                 CallPerl(module, "tickSize", new Object [] {
                     String.valueOf(tickerId),
                     String.valueOf(field),
                     String.valueOf(size),
                 }) ;
          }
          catch (InlineJavaPerlException pe){ }
          catch (InlineJavaException pe) { pe.printStackTrace() ;}
    }
}

Reply via email to