author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sun, 19 Jul 2009 19:44:48 +0200 | |
changeset 101 | 176448af80fa |
parent 92 | 0bc2646daa82 |
permissions | -rw-r--r-- |
92
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
2 |
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
3 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
* Redistribution and use in source and binary forms, with or |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
* without modification, are permitted provided that the following |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
* conditions are met: |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
* -Redistributions of source code must retain the above copyright |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
* notice, this list of conditions and the following disclaimer. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
* -Redistribution in binary form must reproduce the above copyright |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
* notice, this list of conditions and the following disclaimer in |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
* the documentation and/or other materials provided with the |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
* distribution. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
* Neither the name of Sun Microsystems, Inc. or the names of |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
* contributors may be used to endorse or promote products derived |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
* from this software without specific prior written permission. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
* This software is provided "AS IS," without a warranty of any |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
* EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
* NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
* USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
* ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
* |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
* You acknowledge that Software is not designed, licensed or |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
* intended for use in the design, construction, operation or |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
* maintenance of any nuclear facility. |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
*/ |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
package example.hello; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
import java.rmi.registry.Registry; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
import java.rmi.registry.LocateRegistry; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
import java.rmi.RemoteException; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
import java.rmi.server.UnicastRemoteObject; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
public class Server implements Hello { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
public Server () { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
} |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
50 |
public String sayHello () { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
51 |
return "Hello, world!"; |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
52 |
} |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
53 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
54 |
public static void main (String args[]) { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
55 |
try { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
56 |
Server obj = new Server (); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
57 |
Hello stub = (Hello) UnicastRemoteObject.exportObject (obj, 0); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
58 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
59 |
// Bind the remote object's stub in the registry |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
60 |
Registry registry = LocateRegistry.getRegistry (); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
61 |
registry.bind ("Hello", stub); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
62 |
|
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
63 |
System.err.println ("Server ready"); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
64 |
} catch (Exception e) { |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
65 |
System.err.println ("Server exception: " + e.toString ()); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
66 |
e.printStackTrace (); |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
67 |
} |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
68 |
} |
0bc2646daa82
RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
69 |
} |