1 /* |
|
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.io.*; |
|
25 import java.rmi.*; |
|
26 import java.rmi.server.UnicastRemoteObject; |
|
27 |
|
28 public class ServerImpl |
|
29 extends UnicastRemoteObject |
|
30 implements Server |
|
31 { |
|
32 private String name; |
|
33 Callback cLocal; |
|
34 |
|
35 public ServerImpl(String s) throws java.rmi.RemoteException { |
|
36 super(); |
|
37 name = s; |
|
38 } |
|
39 |
|
40 public String sayHello(Callback c) throws RemoteException { |
|
41 System.out.println("Calling Callback method from the ServerImpl"); |
|
42 cLocal = c; |
|
43 new Thread(new Runnable() { |
|
44 public void run() { |
|
45 System.out.println( |
|
46 "+ running a new thread in sayHello method!"); |
|
47 try { |
|
48 cLocal.callback(); |
|
49 } catch(RemoteException e) { |
|
50 System.out.println( |
|
51 "ServerImpl.main: exception while calling callback " + |
|
52 "method:"); |
|
53 e.printStackTrace(); |
|
54 } |
|
55 } |
|
56 }).start(); |
|
57 return "Hello Callback!"; |
|
58 } |
|
59 |
|
60 public static void main(String args[]) { |
|
61 // Create and install the security manager |
|
62 System.setSecurityManager(new RMISecurityManager()); |
|
63 |
|
64 ServerImpl obj = null; |
|
65 |
|
66 try { |
|
67 obj = new ServerImpl("ServerImpl"); |
|
68 Naming.rebind("/ServerImpl", obj); |
|
69 System.out.println("ServerImpl created and bound in the registry" + |
|
70 " to the name ServerImpl"); |
|
71 System.err.println("DTI_DoneInitializing"); |
|
72 } catch (Exception e) { |
|
73 System.out.println("ServerImpl.main: an exception occurred:"); |
|
74 e.printStackTrace(); |
|
75 System.err.println("DTI_Error"); |
|
76 } |
|
77 |
|
78 } |
|
79 } |
|