Ok, will do Jay ----- Original Message ----- From: <[EMAIL PROTECTED]> To: "Jay Strauss" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, January 18, 2004 6:28 PM Subject: Re: Inline::Java Request For Comments: PerlNatives
> Jay, > > PerlNatives does not add new callback functionnality, it justy provodes a > different way to use callbacks. > But you should have all you need in Inline::Java 0.44. > Try using callback loops (see documentation). > > Cheers, > > Patrick > ----- Original Message ----- > From: "Jay Strauss" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Sunday, January 18, 2004 1:13 PM > Subject: Re: Inline::Java Request For Comments: PerlNatives > > > > Patrick, > > > > Do you think your new changes might help me with what I was trying to do? > > > > I'm not sure if you remember the whole mess but in Java I have to: > > > > 1) create a class which implements EWrapper (a vendor supplied interface), > > within this class are methods like: tickPrice, tickSize... I call this > > class TWSAPI > > > > 2) then: > > a) new an instance of TWSAPI > > b) new a EClientSocket passing it my TWSAPI instance > > c) call my EClientSocket.connect, which in turn creates an instance of > > EReader (another vendor piece of code). EReader starts a new > > thread which runs continuously, sitting on a socket reading everything > > coming from the socket, and makes calls to tickPrice, tickSize... > > > > 3) call methods on my EClientSocket to make trades and request > information, > > such as, EClientSocket.reqMktData(args), EClientSocket.placeOrder > > > > In summary, I have one thread that is that is issuing requests like > > placeOrder, > > requestMktData, getTransactions... and another thread reading the socket > > making callbacks to my custom code to handle tickSize, tickPrice, > > orderExecuted... > > > > Both threads are independent of eachother and non-blocking > > > > Thanks > > Jay > > > > ----- Original Message ----- > > From: "Patrick LeBoutillier" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Sunday, January 11, 2004 2:12 PM > > Subject: Inline::Java Request For Comments: PerlNatives > > > > > > > Hi all, > > > > > > First of all I would like to take this opportunity to wish a happy new > > > year to all Inline users and their families. > > > > > > Now on with business. In the last Inline::Java version (0.44), > significant > > > changes where brought (thanks in part to many users on this list) to the > > > way callbacks are handled within Inline::Java. But the way callbacks are > > > invoked, i.e.: > > > > > > Object rv = CallPerl("my::package", "my_sub", new Object [] {"arg1", > > > "arg2"}) ; > > > > > > is still somewhat cumbersome. During the holidays I did a bit of > research > > > (and also looked a bit at JPL) and came up with a cleaner way to define > > > callbacks and invoke them: I call this "PerlNatives". > > > > > > Let's look at a realistic example with the way callbacks are invoked > > > currently: > > > > > > use Inline Java => <<'END' ; > > > import java.util.* ; > > > import org.perl.inline.java.* ; > > > import javax.swing.* ; > > > import java.awt.event.* ; > > > > > > class Button extends InlineJavaPerlCaller > > > implements ActionListener { > > > public Button() throws InlineJavaException { > > > JFrame frame = new JFrame("Button") ; > > > frame.setSize(50,50) ; > > > JButton button = new JButton("Click Me!") ; > > > frame.getContentPane().add(button) ; > > > button.addActionListener(this) ; > > > frame.show() ; > > > } > > > > > > public void actionPerformed(ActionEvent e){ > > > try { > > > CallPerl("main", "button_pressed", new Object [] {}) ; > > > } > > > catch (InlineJavaPerlException pe){ } > > > catch (InlineJavaException pe) { pe.printStackTrace() ;} > > > } > > > } > > > END > > > > > > my $b = new Button() ; > > > > > > sub button_pressed { > > > print("click!\n") ; # prints click! > > > } > > > > > > > > > With PerlNatives, you do it like this: > > > > > > use Inline Java => <<'END' ; > > > import java.util.* ; > > > import org.perl.inline.java.* ; > > > import javax.swing.* ; > > > import java.awt.event.* ; > > > > > > class Button extends InlineJavaPerlNatives > > > implements ActionListener { > > > public Button() throws InlineJavaException { > > > JFrame frame = new JFrame("Button") ; > > > frame.setSize(50,50) ; > > > JButton button = new JButton("Click Me!") ; > > > frame.getContentPane().add(button) ; > > > button.addActionListener(this) ; > > > frame.show() ; > > > } > > > > > > public void actionPerformed(ActionEvent e){ > > > button_pressed() ; > > > } > > > > > > native public void button_pressed() ; > > > } > > > END > > > > > > my $b = new Button() ; > > > > > > sub Button::perl::button_pressed { > > > my $this = shift ; > > > print("click!\n") ; # prints click! > > > } > > > > > > > > > So what has changed here? > > > > > > First of all, the Button class now extends InlineJavaPerlNatives instead > > > of InlineJavaPerlCaller. Basically all this does is tell Java that all > > > methods declared "native" in this class will be implemented (or more > > > specifically mapped) to a subroutine in Perl. > > > > > > Secondly, we defined a new native method in our class called > > > button_pressed. Since this method is in the class Button (which extends > > > InlineJavaPerlNatives), Inline::Java will know that this method is > mapped > > > to the Button::perl::button_pressed subroutine in Perl (the addition of > > > the ::perl subpackage is necessary or else you will get into a infinite > > > loop (remember that since Button.button_pressed is public, Inline::Java > > > has already mapped to Button::button_pressed!)). > > > > > > Thirdly, we simply call button_pressed as if it where a normal Java > > method. > > > > > > Of course there are a few limitations with PerlNatives: > > > - You can't have 2 native methods with the same name in a class > > > - Native methods can only return void or Object types (no primitive > > > types). This is somewhat anoying but can be easily worked around using > the > > > wrapper classes (Integer, Double, ...) > > > - (certainly others to be discovered later...) > > > > > > That's basically it. I still have some implementation details to iron > out > > > and some tiny portability issues, but I've got everything working pretty > > > well. > > > > > > Note: For those of you who are wondering why I'm so preoccupied with > > > callbacks, I just want to say that one day I would like people to use > > > Inline::Java to call PERL from JAVA. Callbacks (which in this case won't > > > be callbacks at all) will then become very important. > > > > > > Anyways, I just wanted to get some feedback on this before I got to > far... > > > > > > Thanks, > > > > > > Patrick > > > > > > ---------------------------------- > > > | Patrick LeBoutillier > > > | [EMAIL PROTECTED] > > > > > > _________________________________________________________________ > > > STOP MORE SPAM with the new MSN 8 and get 2 months FREE* > > > > > > http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn > > .com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca > > > > > > > > > > > > > > > > >