All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.razorvine.pyro.serializer.PyroProxyPickler Maven / Gradle / Ivy

Go to download

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).

There is a newer version: 5.1
Show newest version
package net.razorvine.pyro.serializer;

import java.io.IOException;
import java.io.OutputStream;

import net.razorvine.pickle.IObjectPickler;
import net.razorvine.pickle.Opcodes;
import net.razorvine.pickle.PickleException;
import net.razorvine.pickle.Pickler;
import net.razorvine.pyro.PyroProxy;
import net.razorvine.pyro.PyroURI;

/**
 * Pickler extension to be able to pickle PyroProxy objects.
 *  
 * @author Irmen de Jong ([email protected])
 */
public class PyroProxyPickler implements IObjectPickler {

	public void pickle(Object o, OutputStream out, Pickler currentPickler) throws PickleException, IOException {
		PyroProxy proxy = (PyroProxy) o;
		out.write(Opcodes.GLOBAL);
		byte[] output="Pyro4.core\nProxy\n".getBytes();
		out.write(output,0,output.length);
		out.write(Opcodes.EMPTY_TUPLE);
		out.write(Opcodes.NEWOBJ);
		
		// args(8): pyroUri, pyroOneway(hashset), pyroMethods(set), pyroAttrs(set), pyroTimeout, pyroHmacKey, pyroHandshake, pyroMaxRetries
		Object[] args = new Object[] {   
			new PyroURI(proxy.objectid, proxy.hostname, proxy.port),
			proxy.pyroOneway,
			proxy.pyroMethods,
			proxy.pyroAttrs,
			0.0,
			proxy.pyroHmacKey,
			proxy.pyroHandshake,
			0  // maxretries is not yet used/supported by pyrolite
		};
		currentPickler.save(args);
		out.write(Opcodes.BUILD);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy