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

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

package net.razorvine.pyro.serializer;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import net.razorvine.pyro.PyroProxy;
import net.razorvine.pyro.PyroURI;
import net.razorvine.serpent.IClassSerializer;

/**
 * Serpent extension to be able to serialize PyroProxy objects with Serpent.
 *  
 * @author Irmen de Jong ([email protected])
 */
public class PyroProxySerpent implements IClassSerializer {

	public static Object FromSerpentDict(Map dict) throws IOException {
		Object[] state = (Object[])dict.get("state");  // pyroUri, onway(set), timeout
		PyroURI uri = new PyroURI((String)state[0]);
		return new PyroProxy(uri);
	}

	public Map convert(Object obj) {
		PyroProxy proxy = (PyroProxy) obj;
		Map dict = new HashMap();
		String uri = String.format("PYRO:%s@%s:%d", proxy.objectid, proxy.hostname, proxy.port);
		dict.put("state", new Object[]{uri, Collections.EMPTY_SET, 0.0});
		dict.put("__class__", "Pyro4.core.Proxy");
		return dict;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy