当前位置: 首页>>代码示例>>Java>>正文


Java PyroProxy类代码示例

本文整理汇总了Java中net.razorvine.pyro.PyroProxy的典型用法代码示例。如果您正苦于以下问题:Java PyroProxy类的具体用法?Java PyroProxy怎么用?Java PyroProxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PyroProxy类属于net.razorvine.pyro包,在下文中一共展示了PyroProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public Map<String, Object> convert(Object obj) {
	// note: the state array returned here must conform to the list consumed by Pyro4's Proxy.__setstate_from_dict__ 
	// that means, we make a list with 8 entries:
	// uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
	PyroProxy proxy = (PyroProxy) obj;
	Map<String, Object> dict = new HashMap<String, Object>();
	String uri = String.format("PYRO:%[email protected]%s:%d", proxy.objectid, proxy.hostname, proxy.port);

	String encodedHmac = proxy.pyroHmacKey!=null? "b64:"+DatatypeConverter.printBase64Binary(proxy.pyroHmacKey) : null;
	dict.put("state", new Object[]{
		uri,
		proxy.pyroOneway,
		proxy.pyroMethods,
		proxy.pyroAttrs,
		0.0,
		encodedHmac,
		proxy.pyroHandshake,
		0   // maxretries is not used/supported in pyrolite
	});
	dict.put("__class__", "Pyro4.core.Proxy");
	return dict;
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:23,代码来源:PyroProxySerpent.java

示例2: pickle

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
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);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:23,代码来源:PyroProxyPickler.java

示例3: main

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		setConfig();
		System.out.println("Testing Pyro handshake and custom annotations. Make sure the server from the pyro handshake example is running.");
		System.out.println("Pyrolite version: "+Config.PYROLITE_VERSION);
		System.out.println("serializer used: " + Config.SERIALIZER);

		Scanner scanner = new Scanner(System.in);
		System.out.println("\r\nEnter the server URI: ");
		String uri = scanner.next().trim();
		System.out.println("Enter the secret code as printed by the server: ");
		String secret = scanner.next().trim();
		scanner.close();
		
		PyroProxy p = new CustomAnnotationsProxy(new PyroURI(uri));
		p.pyroHandshake = secret;
		p.correlation_id = UUID.randomUUID();
		System.out.println("Correlation id set to: "+p.correlation_id);
		p.call("ping");
		System.out.println("Connection Ok!");
		
		// tidy up:
		p.close();
	}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:25,代码来源:HandshakeExample.java

示例4: main

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		System.out.println("Testing Pyro autoproxy server (check the port number)...");
		System.out.println("Pyrolite version: "+Config.PYROLITE_VERSION);

		setConfig();
		
		PyroProxy p=new PyroProxy("localhost",51353,"example.autoproxy");	// change port number to whatever the server prints

		Object result=p.call("createSomething", 42);
		System.out.println("return value:");
		PrettyPrint.print(result);
		PyroProxy resultproxy=(PyroProxy)result;
		resultproxy.call("speak", "hello from java");
		
		p.close();
	}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:18,代码来源:AutoproxyExample.java

示例5: testPyroProxySerpent

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
@Test
public void testPyroProxySerpent() throws IOException
{
	PyroProxySerpent serp = new PyroProxySerpent();
	PyroURI uri = new PyroURI("PYRO:[email protected]:4444");
	PyroProxy proxy = new PyroProxy(uri);
	proxy.correlation_id = UUID.randomUUID();
	proxy.pyroHandshake = "apples";
	proxy.pyroHmacKey = "secret".getBytes();
	proxy.pyroAttrs = new HashSet<String>();
	proxy.pyroAttrs.add("attr1");
	proxy.pyroAttrs.add("attr2");
	Map<String, Object> data = serp.convert(proxy);
	assertEquals(2, data.size());
	assertEquals("Pyro4.core.Proxy", data.get("__class__"));
	assertEquals(8, ((Object[])data.get("state")).length);
	
	Map<Object, Object> data2=new HashMap<Object, Object>(data);
	
	PyroProxy proxy2 = (PyroProxy) PyroProxySerpent.FromSerpentDict(data2);
	assertEquals(proxy.objectid, proxy2.objectid);
	assertEquals("apples", proxy2.pyroHandshake);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:24,代码来源:SerializePyroTest.java

示例6: testUnserpentProxy

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
@Test
public void testUnserpentProxy() throws IOException
{
	byte[] data = ("# serpent utf-8 python3.2\n" +
				   "{'state':('PYRO:[email protected]:9090',(),('count','lookup','register','ping','list','remove'),(),0.0,'b64:c2VjcmV0','hello',0),'__class__':'Pyro4.core.Proxy'}").getBytes();
	
	SerpentSerializer ser = new SerpentSerializer();
	PyroProxy p = (PyroProxy) ser.deserializeData(data);
	assertNull(p.correlation_id);
	assertEquals("Pyro.NameServer", p.objectid);
	assertEquals("localhost", p.hostname);
	assertEquals(9090, p.port);
	assertEquals("hello", p.pyroHandshake);
	assertArrayEquals("secret".getBytes(), p.pyroHmacKey);
	assertEquals(0, p.pyroAttrs.size());
	assertEquals(0, p.pyroOneway.size());
	assertEquals(6, p.pyroMethods.size());
	Set<String> methods = new HashSet<String>();
	methods.add("ping");
	methods.add("count");
	methods.add("lookup");
	methods.add("list");
	methods.add("register");
	methods.add("remove");
	assertEquals(methods, p.pyroMethods);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:27,代码来源:SerializePyroTest.java

示例7: convert

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public Map<String, Object> convert(Object obj) {
	// note: the state array returned here must conform to the list consumed by Pyro4's Proxy.__setstate_from_dict__ 
	// that means, we make a list with 8 entries:
	// uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
	PyroProxy proxy = (PyroProxy) obj;
	Map<String, Object> dict = new HashMap<String, Object>();
	String uri = String.format("PYRO:%[email protected]%s:%d", proxy.objectid, proxy.hostname, proxy.port);

	String encodedHmac = proxy.pyroHmacKey!=null? "b64:"+Base64.getEncoder().encodeToString(proxy.pyroHmacKey) : null;
	dict.put("state", new Object[]{
		uri,
		proxy.pyroOneway,
		proxy.pyroMethods,
		proxy.pyroAttrs,
		0.0,
		encodedHmac,
		proxy.pyroHandshake,
		0   // maxretries is not used/supported in pyrolite
	});
	dict.put("__class__", "Pyro4.core.Proxy");
	return dict;
}
 
开发者ID:irmen,项目名称:Pyrolite,代码行数:23,代码来源:PyroProxySerpent.java

示例8: main

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		System.out.println("Testing Pyro flame server (make sure it's running on localhost 9999)...");
		System.out.println("Pyrolite version: "+Config.PYROLITE_VERSION);

		setConfig();

		PyroProxy flame=new PyroProxy("localhost",9999,"Pyro.Flame");
		if(hmacKey!=null) flame.pyroHmacKey = hmacKey;

		System.out.println("builtin:");
		FlameBuiltin r_max=(FlameBuiltin)flame.call("builtin", "max");
		if(hmacKey!=null) r_max.setHmacKey(hmacKey);
		int maximum=(Integer)r_max.call(new int[]{22,99,1});
		System.out.println("maximum="+maximum);
		
		FlameModule r_module=(FlameModule)flame.call("module","socket");
		if(hmacKey!=null) r_module.setHmacKey(hmacKey);
		String hostname=(String)r_module.call("gethostname");
		
		System.out.println("hostname="+hostname);
		
		int sum=(Integer)flame.call("evaluate", "9+9");
		System.out.println("sum="+sum);
		
		flame.call("execute", "import sys; sys.stdout.write('HELLO FROM JAVA\\n')");
		
		FlameRemoteConsole console=(FlameRemoteConsole)flame.call("console");
		if(hmacKey!=null) console.setHmacKey(hmacKey);
		console.interact();
		console.close();
	}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:33,代码来源:FlameExample.java

示例9: testPyroClassesPickle

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
@Test
public void testPyroClassesPickle() throws IOException
{
	PickleSerializer pickler = new PickleSerializer();
	PyroURI uri = new PyroURI("PYRO:[email protected]:4444");
	byte[] s = pickler.serializeData(uri);
	Object x = pickler.deserializeData(s);
	assertEquals(uri, x);

	PyroProxy proxy = new PyroProxy(uri);
	proxy.correlation_id = UUID.randomUUID();
	proxy.pyroHmacKey = "secret".getBytes();
	proxy.pyroHandshake = "apples";
	proxy.pyroAttrs = new HashSet<String>();
	proxy.pyroAttrs.add("attr1");
	proxy.pyroAttrs.add("attr2");
	s = pickler.serializeData(proxy);
	x = pickler.deserializeData(s);
	PyroProxy proxy2 = (PyroProxy) x;
	assertEquals(uri.host, proxy2.hostname);
	assertEquals(uri.objectid, proxy2.objectid);
	assertEquals(uri.port, proxy2.port);
	assertNull(proxy2.correlation_id); // correlation_id is not serialized on the proxy object")
	assertEquals(proxy.pyroHandshake, proxy2.pyroHandshake);
	assertArrayEquals(proxy.pyroHmacKey, proxy2.pyroHmacKey);
	assertEquals(2, proxy2.pyroAttrs.size());
	assertEquals(proxy.pyroAttrs, proxy2.pyroAttrs);
	
	PyroException ex = new PyroException("error");
	ex._pyroTraceback = "traceback";
	s = pickler.serializeData(ex);
	x = pickler.deserializeData(s);
	PyroException ex2 = (PyroException) x;
	assertEquals(ex.getMessage(), ex2.getMessage());
	assertEquals("traceback", ex2._pyroTraceback);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:37,代码来源:SerializePyroTest.java

示例10: testPickleUnpickleProxy

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
@Test
public void testPickleUnpickleProxy() throws IOException {
	PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
	proxy.pyroHmacKey = "secret".getBytes();
	PyroSerializer ser = new PickleSerializer();
	byte[] pickled_proxy=ser.serializeData(proxy);
	PyroProxy result = (PyroProxy) ser.deserializeData(pickled_proxy);
	assertEquals(proxy.hostname, result.hostname);
	assertEquals(proxy.objectid, result.objectid);
	assertEquals(proxy.port, result.port);
	assertArrayEquals("secret".getBytes(), result.pyroHmacKey);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:13,代码来源:UnpicklerComplexTest.java

示例11: unpickleRealProxy

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
private void unpickleRealProxy(String pickle_name) throws IOException
{
	InputStream is = this.getClass().getResourceAsStream(pickle_name);
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	int c;
	while((c = is.read())>=0) bos.write(c);
	is.close();
	byte[] pickled_proxy = bos.toByteArray();
	PyroSerializer ser = new PickleSerializer();
	PyroProxy proxy=(PyroProxy)ser.deserializeData(pickled_proxy);
	assertEquals("Pyro.NameServer",proxy.objectid);
	assertEquals("localhost",proxy.hostname);
	assertEquals(9090,proxy.port);
	assertEquals("hello", proxy.pyroHandshake);
	assertArrayEquals("secret".getBytes(), proxy.pyroHmacKey);
	
	Set<String> expectedSet = new HashSet<String>();
	assertEquals(expectedSet, proxy.pyroAttrs);
	expectedSet.clear();
	expectedSet.add("lookup");
	expectedSet.add("ping");
	expectedSet.add("register");
	expectedSet.add("remove");
	expectedSet.add("list");
	expectedSet.add("count");
	assertEquals(expectedSet, proxy.pyroMethods);
	expectedSet = new HashSet<String>();
	assertEquals(expectedSet, proxy.pyroOneway);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:30,代码来源:UnpicklerComplexTest.java

示例12: testPyroClassesPickle

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
@Test
public void testPyroClassesPickle() throws IOException
{
	PickleSerializer pickler = new PickleSerializer();
	PyroURI uri = new PyroURI("PYRO:[email protected]:4444");
	byte[] s = pickler.serializeData(uri);
	Object x = pickler.deserializeData(s);
	assertEquals(uri, x);

	PyroProxy proxy = new PyroProxy(uri);
	proxy.correlation_id = UUID.randomUUID();
	proxy.pyroHmacKey = "secret".getBytes();
	proxy.pyroHandshake = "apples";
	proxy.pyroAttrs = new HashSet<String>();
	proxy.pyroAttrs.add("attr1");
	proxy.pyroAttrs.add("attr2");
	s = pickler.serializeData(proxy);
	x = pickler.deserializeData(s);
	PyroProxy proxy2 = (PyroProxy) x;
	assertEquals(uri.host, proxy2.hostname);
	assertEquals(uri.objectid, proxy2.objectid);
	assertEquals(uri.port, proxy2.port);
	assertNull(proxy2.correlation_id); // correlation_id is not serialized on the proxy object")
	assertEquals(proxy.pyroHandshake, proxy2.pyroHandshake);
	assertArrayEquals(proxy.pyroHmacKey, proxy2.pyroHmacKey);
	assertEquals(2, proxy2.pyroAttrs.size());
	assertEquals(proxy.pyroAttrs, proxy2.pyroAttrs);
	
	PyroException ex = new PyroException("error");
	ex._pyroTraceback = "traceback";
	s = pickler.serializeData(ex);
	x = pickler.deserializeData(s);
	PyroException ex2 = (PyroException) x;
	assertEquals("[Pyro4.errors.PyroError] error", ex2.getMessage());
	assertEquals("traceback", ex2._pyroTraceback);
}
 
开发者ID:irmen,项目名称:Pyrolite,代码行数:37,代码来源:SerializePyroTest.java

示例13: unpickleRealProxy

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
private void unpickleRealProxy(String pickle_name) throws IOException
{
	InputStream is = this.getClass().getResourceAsStream(pickle_name);
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	int c;
	while((c = is.read())>=0) bos.write(c);
	is.close();
	byte[] pickled_proxy = bos.toByteArray();
	PyroSerializer ser = new PickleSerializer();
	PyroProxy proxy=(PyroProxy)ser.deserializeData(pickled_proxy);
	assertEquals("Pyro.NameServer",proxy.objectid);
	assertEquals("localhost",proxy.hostname);
	assertEquals(9090,proxy.port);
	assertEquals("hello", proxy.pyroHandshake);
	assertArrayEquals("secret".getBytes(), proxy.pyroHmacKey);
	
	Set<String> expectedSet = new HashSet<String>();
	assertEquals(expectedSet, proxy.pyroAttrs);
	expectedSet.clear();
	expectedSet.add("lookup");
	expectedSet.add("ping");
	expectedSet.add("register");
	expectedSet.add("remove");
	expectedSet.add("list");
	expectedSet.add("count");
	expectedSet.add("set_metadata");
	proxy.pyroMethods.removeAll(expectedSet);
	
	assertEquals(0, proxy.pyroMethods.size());
	expectedSet = new HashSet<String>();
	assertEquals(expectedSet, proxy.pyroOneway);
}
 
开发者ID:irmen,项目名称:Pyrolite,代码行数:33,代码来源:UnpicklerComplexTest.java

示例14: FromSerpentDict

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public static Object FromSerpentDict(Map<Object, Object> dict) throws IOException {
	// note: the state array received in the dict conforms to the list produced by Pyro4's Proxy.__getstate_for_dict__
	// that means, we get an array of length 8:  (the same as with convert, below!)
	// uri, oneway set, methods set, attrs set, timeout, hmac_key, handshake, maxretries  (in this order)
	Object[] state = (Object[])dict.get("state");
	PyroURI uri = new PyroURI((String)state[0]);
	PyroProxy proxy = new PyroProxy(uri);
	
	// the following nasty piece of code is similar to _processMetadata from the PyroProxy
	// this is because the three collections can either be an array or a set
	Object methods = state[2];
	Object attrs = state[3];
	Object oneways = state[1];
	
	if(methods instanceof Object[]) {
		Object[] methods_array = (Object[]) methods;
		proxy.pyroMethods = new HashSet<String>();
		for(int i=0; i<methods_array.length; ++i) {
			proxy.pyroMethods.add((String) methods_array[i]);
		}
	} else if(methods!=null) {
		@SuppressWarnings("unchecked")
		HashSet<String> methods_set = (HashSet<String>) methods;
		proxy.pyroMethods = methods_set;
	}
	if(attrs instanceof Object[]) {
		Object[] attrs_array = (Object[]) attrs;
		proxy.pyroAttrs = new HashSet<String>();
		for(int i=0; i<attrs_array.length; ++i) {
			proxy.pyroAttrs.add((String) attrs_array[i]);
		}
	} else if(attrs!=null) {
		@SuppressWarnings("unchecked")
		HashSet<String> attrs_set = (HashSet<String>) attrs;
		proxy.pyroAttrs = attrs_set;
	}
	if(oneways instanceof Object[]) {
		Object[] oneways_array = (Object[]) oneways;
		proxy.pyroOneway = new HashSet<String>();
		for(int i=0; i<oneways_array.length; ++i) {
			proxy.pyroOneway.add((String) oneways_array[i]);
		}
	} else if(oneways!=null) {
		@SuppressWarnings("unchecked")
		HashSet<String> oneways_set = (HashSet<String>) oneways;
		proxy.pyroOneway = oneways_set;
	}
	
	if(state[5]!=null) {
		String encodedHmac = (String)state[5];
		if(encodedHmac.startsWith("b64:")) {
			proxy.pyroHmacKey = DatatypeConverter.parseBase64Binary(encodedHmac.substring(4));
		} else {
			throw new PyroException("hmac encoding error");
		}		
	}
	
	proxy.pyroHandshake = state[6];
	// maxretries is not used/supported in pyrolite, so simply ignore it

	return proxy;
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:63,代码来源:PyroProxySerpent.java

示例15: main

import net.razorvine.pyro.PyroProxy; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

		System.out.println("Testing Pyro timezone example server (make sure it's running, with nameserver enabled, and pickle as serializer)...");
		System.out.println("Pyrolite version: "+Config.PYROLITE_VERSION);

		setConfig();

		NameServerProxy ns = NameServerProxy.locateNS(null);
		PyroProxy p = new PyroProxy(ns.lookup("example.timezones"));
		ns.close();

		
		Calendar cal;

		System.out.println("\nPYTZ...:");
		cal = (Calendar) p.call("pytz");
		System.out.println(cal);
		System.out.println("Timezone="+cal.getTimeZone());

		System.out.println("\nDATEUTIL...:");
		cal = (Calendar) p.call("dateutil");
		System.out.println(cal);
		System.out.println("Timezone="+cal.getTimeZone());

		System.out.println("\nECHO Timezone...:");
		cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, 2015);
		cal.set(Calendar.MONTH, Calendar.MAY);
		cal.set(Calendar.DAY_OF_MONTH, 18);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 998);
		cal.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));
		System.out.println("****" + javax.xml.bind.DatatypeConverter.printDateTime(cal));
		Calendar cal2 = (Calendar) p.call("echo", cal);
		System.out.println("****" + javax.xml.bind.DatatypeConverter.printDateTime(cal2));
		System.out.println(cal2);
		System.out.println("Timezone="+cal2.getTimeZone());
		if(!cal.equals(cal2))
			System.err.println("returned calendar is different!");
		
		// tidy up:
		p.close();
	}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:46,代码来源:TimezoneExample.java


注:本文中的net.razorvine.pyro.PyroProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。