01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package examples.connectivity;
08:
09: import org.codehaus.aspectwerkz.connectivity.RemoteProxy;
10:
11: /**
12: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
13: */
14: public class Client {
15:
16: public static void main(String[] args) {
17: run();
18: }
19:
20: /**
21: * This example shows two ways of using the remote proxy feature: <p/>1. It creates a client
22: * proxy that creates a matching instance on the server. The client now has seamless access this
23: * new instance on the server. <p/>2. The instance on the server creates a new proxy to another
24: * specific instance on and sends this proxy to the client. The client then have access to this
25: * specific instance. (Proxy created on the server-side using:
26: * <code>RemoteProxy proxy = RemoteProxy.createServerProxy(myInstance, "localhost", 7777);</code>)
27: */
28: private static void run() {
29: // 1)
30: // creates a new remote proxy for the TestImpl1 class which maps to an instance of this
31: // class on the server
32: RemoteProxy proxy1 = RemoteProxy.createClientProxy(
33: new String[] { "examples.connectivity.Test1" },
34: "examples.connectivity.Test1Impl", "localhost", 6663);
35: // retrieves the proxy the the TestImpl1 instance
36: Test1 mixin1 = (Test1) proxy1.getInstance();
37:
38: // 2)
39: // retrieve the proxy to a specific instance created on the server
40: RemoteProxy proxy2 = mixin1.getTest1();
41: // retrieves the proxy the the TestImpl2 instance
42: Test2 mixin2 = (Test2) proxy2.getInstance();
43:
44: // 3)
45: // invoke methods on the proxies (executed on the server)
46: System.out.println("Mixin1 says: " + mixin1.test1());
47: System.out.println("Mixin2 says: " + mixin2.test2());
48:
49: // 4)
50: // close the proxies (close() must always be called)
51: proxy1.close();
52: proxy2.close();
53: }
54: }
|