Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
This library allows your Java program to interface very easily with the Python world. It uses the Pyro protocol to call methods on remote objects. (See https://pyro5.readthedocs.io/).
Pyrolite only implements part of the client side Pyro library, hence its name 'lite'... So if you don't need Pyro's full feature set, Pyrolite may be a good choice to connect java or .NET and python.
Version 5.0 changes: support Pyro5 wire protocol. Dropped support of Pyro4 (stick to version 4.xx for that).
package net.razorvine.pyro;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import net.razorvine.pickle.PickleException;
import net.razorvine.pyro.serializer.PyroSerializer;
/**
* Proxy for Pyro objects.
*
* @author Irmen de Jong ([email protected])
*/
public class PyroProxy implements Serializable {
private static final long serialVersionUID = -5564313476693913031L;
public String hostname;
public int port;
public String objectid;
public byte[] pyroHmacKey = null; // per-proxy hmac key, used to be HMAC_KEY config item
public UUID correlation_id = null; // per-proxy correlation id (need to set/update this yourself)
public Object pyroHandshake = "hello"; // data object that should be sent in the initial connection handshake message. Can be any serializable object.
private transient int sequenceNr = 0;
private transient Socket sock;
private transient OutputStream sock_out;
private transient InputStream sock_in;
public Set pyroMethods = new HashSet(); // remote methods
public Set pyroAttrs = new HashSet(); // remote attributes
public Set pyroOneway = new HashSet(); // oneway methods
/**
* No-args constructor for (un)pickling support
*/
public PyroProxy() {
}
/**
* Create a proxy for the remote Pyro object denoted by the uri
*/
public PyroProxy(PyroURI uri) throws UnknownHostException, IOException {
this(uri.host, uri.port, uri.objectid);
}
/**
* Create a proxy for the remote Pyro object on the given host and port, with the given objectid/name.
*/
public PyroProxy(String hostname, int port, String objectid) throws UnknownHostException, IOException {
this.hostname = hostname;
this.port = port;
this.objectid = objectid;
}
/**
* (re)connect the proxy to the remote Pyro daemon.
*/
protected void connect() throws UnknownHostException, IOException {
if (sock == null) {
sock = new Socket(hostname, port);
sock.setKeepAlive(true);
sock.setTcpNoDelay(true);
sock_out = sock.getOutputStream();
sock_in = sock.getInputStream();
sequenceNr = 0;
_handshake();
if(Config.METADATA) {
// obtain metadata if this feature is enabled, and the metadata is not known yet
if(!pyroMethods.isEmpty() || !pyroAttrs.isEmpty()) {
// not checking _pyroONeway because that feature already existed and it is not yet deprecated
// log.debug("reusing existing metadata")
} else {
getMetadata(this.objectid);
}
}
}
}
/**
* get metadata from server (methods, attrs, oneway, ...) and remember them in some attributes of the proxy
*/
protected void getMetadata(String objectId) throws PickleException, PyroException, IOException {
// get metadata from server (methods, attrs, oneway, ...) and remember them in some attributes of the proxy
if(objectId==null) objectId=this.objectid;
if(sock==null) {
connect();
if(!pyroMethods.isEmpty() || !pyroAttrs.isEmpty())
return; // metadata has already been retrieved as part of creating the connection
}
// invoke the get_metadata method on the daemon
@SuppressWarnings("unchecked")
HashMap result = (HashMap) this.internal_call("get_metadata", Config.DAEMON_NAME, 0, false, new Object[] {objectId});
if(result==null)
return;
_processMetadata(result);
}
/**
* Extract meta data and store it in the relevant properties on the proxy.
* If no attribute or method is exposed at all, throw an exception.
*/
private void _processMetadata(HashMap result) {
// the collections in the result can be either an object[] or a HashSet