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

net.razorvine.pyro.FlameRemoteConsole 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;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

import net.razorvine.pickle.PickleException;

/**
 * Flame remote interactive console client. 
 * 
 * @author Irmen de Jong ([email protected])
 */

public class FlameRemoteConsole {

	private PyroProxy remoteconsole;
	
	/**
	 * called by the Unpickler to restore state
	 */
	public void __setstate__(HashMap args) throws IOException {
		remoteconsole=(PyroProxy)args.get("remoteconsole"); 
	}

	public void interact() throws PickleException, PyroException, IOException {
		String banner=(String)remoteconsole.call("get_banner");
		System.out.println(banner);
		String ps1=">>> ";
		String ps2="... ";
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		boolean more=false;
		while(true) {
			if(more)
				System.out.print(ps2);
			else
				System.out.print(ps1);
			System.out.flush();
			String line=br.readLine();
			if(line==null) {
				// end of input
				System.out.println("");
				break;
			}
			try {
				Object[] result=(Object[])remoteconsole.call("push_and_get_output", line);
				if(result[0]!=null) {
					System.out.print(result[0]);
				}
				more=(Boolean)result[1];
			} catch(IOException x) {
				break;
			}
		}
		System.out.println("(Remote session ended)");
	}

	public void close() throws PickleException, PyroException, IOException {
		if(remoteconsole!=null) {
			remoteconsole.call("terminate");
			remoteconsole.close();
		}
	}
	
	public void setHmacKey(byte[] hmac) {
		remoteconsole.pyroHmacKey = hmac;
	}	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy