KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > connectivity > Client


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package examples.connectivity;
9
10 import org.codehaus.aspectwerkz.connectivity.RemoteProxy;
11
12 /**
13  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14  */

15 public class Client {
16
17     public static void main(String JavaDoc[] args) {
18         run();
19     }
20
21     /**
22      * This example shows two ways of using the remote proxy feature: <p/>1. It creates a client
23      * proxy that creates a matching instance on the server. The client now has seamless access this
24      * new instance on the server. <p/>2. The instance on the server creates a new proxy to another
25      * specific instance on and sends this proxy to the client. The client then have access to this
26      * specific instance. (Proxy created on the server-side using:
27      * <code>RemoteProxy proxy = RemoteProxy.createServerProxy(myInstance, "localhost", 7777);</code>)
28      */

29     private static void run() {
30         // 1)
31
// creates a new remote proxy for the TestImpl1 class which maps to an instance of this
32
// class on the server
33
RemoteProxy proxy1 = RemoteProxy.createClientProxy(
34                 new String JavaDoc[]{
35                     "examples.connectivity.Test1"
36                 }, "examples.connectivity.Test1Impl", "localhost", 6663
37         );
38         // retrieves the proxy the the TestImpl1 instance
39
Test1 mixin1 = (Test1) proxy1.getInstance();
40
41         // 2)
42
// retrieve the proxy to a specific instance created on the server
43
RemoteProxy proxy2 = mixin1.getTest1();
44         // retrieves the proxy the the TestImpl2 instance
45
Test2 mixin2 = (Test2) proxy2.getInstance();
46
47         // 3)
48
// invoke methods on the proxies (executed on the server)
49
System.out.println("Mixin1 says: " + mixin1.test1());
50         System.out.println("Mixin2 says: " + mixin2.test2());
51
52         // 4)
53
// close the proxies (close() must always be called)
54
proxy1.close();
55         proxy2.close();
56     }
57 }
Popular Tags