pyrolite: newbie quicker-start for Java
"Frank J. Iannarilli, Jr." <franki-u9QQAxJRRC9Wk0Htik3J/[email protected]> Wed, 18 Feb 2015 01:42:03 -0500
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <[email protected]> |
This is a cryptographically signed message in MIME format.
--===============7401194371232216776==
Content-Type: multipart/signed; protocol="application/pkcs7-signature";
micalg=sha1; boundary="------------ms060709090908010108070904"
This is a cryptographically signed message in MIME format.
--------------ms060709090908010108070904
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Hi,
Thanks, Irmen for Pyro and Pyrolite! It saves my day.
I'm posting what I hope is useful for other newbies like me, which is an =
elaboration of the Pyro simple example greeting.py appearing in=20
http://pythonhosted.org//Pyro4/intro.html#with-a-name-server but with a=20
Java (rather than Python) client.
That is, tying together the above with an elaboration of the "small code =
example in Java" that appears in:=20
https://pythonhosted.org/Pyro4/pyrolite.html
FYI, I am running under Window 7 64-bit, WinPython-64bit-3.4.2.4 and=20
Java1.6 (forced by my using ImageJ).
Install Pyro4 onto Python side:
https://pythonhosted.org/Pyro4/install.html
Install pyrolite on Java side (stick the .jar files wherever they need=20
to be):
https://pythonhosted.org/Pyro4/pyrolite.html
Under Python, start a Pyro NameServer: python -m Pyro4.naming
refs:
http://pythonhosted.org//Pyro4/intro.html#with-a-name-server
http://pythonhosted.org//Pyro4/nameserver.html#nameserver-nameserver
Under Python, following=20
http://pythonhosted.org//Pyro4/intro.html#with-a-name-server ,
type in the contents of greeting.py to Python interpreter (omitting the=20
print statement) or execute greeting.py. What this does is to set up a=20
"server" class (i.e. something you want to serve up Python library=20
methods to Java client) and instantiate it, start the Pyro daemon,=20
register the server class instance to the daemon and also to the=20
(auto-found) Pyro name server (already running due to previous step above=
).
Under Java, essentially follow the "small code example in Java" that=20
appears in
https://pythonhosted.org/Pyro4/pyrolite.html but minding some=20
clarification comments and possibly needed adaptations, as I show=20
below. This Java example is actually an ImageJ plugin implementation,=20
but those particulars are unimportant. What this code does is to=20
locate|grab the NameServerProxy, construct the (java proxy|instance of=20
the) Pyro-served Python server class instance (here, the class=20
GreetingMaker), invoke its method (get_fortune), and cast the return=20
value to the appropriate Java type (see Python-Java mappings in pyrolite =
readme.txt).
// Stuff for ImageJ -- of no interest to non-ImageJ folks!
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
// Needed for pyrolite
import net.razorvine.pyro.*;
import java.io.*; // Needed (?) for IOException thrown by some=20
pyrolite methods
public class Greeting_Client implements PlugIn {
// public void run(String arg) throws IOException {
// The above "throws" augmentation would allow various=20
exception-throwing pyrolite methods to
// compile, but ImageJ's plugin interface can't be overriden=20
this way.
// So instead, required to use try-catch blocks below!
public void run(String arg) {
IJ.showMessage("Here we go...");
// NameServerProxy ns =3D NameServerProxy.locateNS(null);
// We have to break up the declaration and construction of the=20
ns variable as follows, or
// declaring and constructing it in one line (as above) within =
the try block means ns
// is local (only) within that try block.
// We follow this idiom with further instances later below.
NameServerProxy ns =3D null; // needs to be initialized to null o=
r=20
get
// "variable=20
might not have been initialized" compilation error
try {
ns =3D NameServerProxy.locateNS(null);
} catch (IOException e) {
IJ.showMessage("Caught LocateNS IOException: " +=20
e.getMessage());
return;
}
// PyroProxy remoteobject =3D new=20
PyroProxy(ns.lookup("PYRONAME:example.greeting"));
// The Pyro dox for the Python side uses above argument form,=20
but the Java-side Pyrolite uses
// below form without the PYRONAME: prefix.
//PyroProxy remoteobject =3D new=20
PyroProxy(ns.lookup("example.greeting"));
PyroProxy remoteobject =3D null;
try {
remoteobject =3D new PyroProxy(ns.lookup("example.greeting"))=
;
} catch (IOException e) {
IJ.showMessage("Caught ns.lookup IOException: " +=20
e.getMessage());
return; // occurs AFTER the following finally block
} finally {
ns.close();
}
// Object result =3D remoteobject.call("get_fortune", "Lucifer");=
Object result =3D null;
try {
result =3D remoteobject.call("get_fortune", "Lucifer");
} catch (IOException e) {
IJ.showMessage("Caught remoteobject.call IOException: " + =
e.getMessage());
return;
} finally {
ns.close();
remoteobject.close();
}
String message =3D (String)result; // cast to the type that=20
'get_fortune' returns
IJ.showMessage(message);
boolean okQ =3D IJ.showMessageWithCancel("My_Plugin", "Pyrolite=20
Example"); // waits...till user action
remoteobject.close();
ns.close();
}
}
--=20
Frank J. Iannarilli franki-u9QQAxJRRC9Wk0Htik3J/[email protected]
Aerodyne Research, Inc., 45 Manning Road, Billerica, MA 01821 USA
--------------ms060709090908010108070904
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature
MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIKNTCC
BOkwggPRoAMCAQICBEwOjDcwDQYJKoZIhvcNAQEFBQAwgbQxFDASBgNVBAoTC0VudHJ1c3Qu
bmV0MUAwPgYDVQQLFDd3d3cuZW50cnVzdC5uZXQvQ1BTXzIwNDggaW5jb3JwLiBieSByZWYu
IChsaW1pdHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBFbnRydXN0Lm5ldCBMaW1pdGVk
MTMwMQYDVQQDEypFbnRydXN0Lm5ldCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAoMjA0OCkw
HhcNMTExMTExMTUzNDQxWhcNMjExMTEyMDc1MTIzWjCBpTELMAkGA1UEBhMCVVMxFjAUBgNV
BAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0Lm5ldC9DUFMgaXMgaW5j
b3Jwb3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMWKGMpIDIwMTAgRW50cnVzdCwgSW5j
LjEiMCAGA1UEAxMZRW50cnVzdCBDbGFzcyAxIENsaWVudCBDQTCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBAKlg/IAuYnCTjPYZYkutNliXDk7+nY8AL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Ibk12BSTd
6e16pHW+eMMlke4bmolS/n0b9iYWcaJEc5fF4dAkoNSJYCiO4BL9jcsXg7/QIDKS9GydrJ44
8b3OETYjbZ9jOwAAAAAAAA==
--------------ms060709090908010108070904--
--===============7401194371232216776==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
--===============7401194371232216776==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core
--===============7401194371232216776==--