|
1 /* |
|
2 * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 import java.rmi.*; |
|
25 import java.rmi.activation.*; |
|
26 |
|
27 public class Doctor |
|
28 extends Activatable |
|
29 implements Eliza, Retireable |
|
30 { |
|
31 // reanimation constructor |
|
32 public Doctor(ActivationID id, MarshalledObject blah) |
|
33 throws RemoteException |
|
34 { |
|
35 super(id, 0); // export self on port 0 (== assign randomly) |
|
36 System.out.println("Doctor constructed and exported"); |
|
37 } |
|
38 |
|
39 private boolean asked = false; |
|
40 |
|
41 // implement Eliza.complain() |
|
42 public String complain(String plaint) |
|
43 { |
|
44 System.out.println("Doctor will see you now"); |
|
45 if (this.asked) { |
|
46 return ("DO GO ON?"); |
|
47 } else { |
|
48 this.asked = true; |
|
49 return ("TELL ME ABOUT YOUR MOTHER"); |
|
50 } |
|
51 } |
|
52 |
|
53 // implement Retireable.retire() |
|
54 public void retire() |
|
55 { |
|
56 System.out.println("Doctor retiring"); |
|
57 try { |
|
58 Activatable.inactive(this.getID()); |
|
59 ActivationGroup.getSystem().unregisterObject(this.getID()); |
|
60 (new HaraKiri()).start(); |
|
61 |
|
62 } catch (UnknownObjectException uoe) { |
|
63 System.err.println("Exception in Activatable.inactive:"); |
|
64 uoe.printStackTrace(); |
|
65 |
|
66 } catch (ActivationException ae) { |
|
67 System.err.println("Exception in Activatable.inactive:"); |
|
68 ae.printStackTrace(); |
|
69 |
|
70 } catch (RemoteException re) { |
|
71 System.err.println("Exception in Activatable.inactive:"); |
|
72 re.printStackTrace(); |
|
73 } |
|
74 } |
|
75 |
|
76 private static class HaraKiri extends Thread |
|
77 { |
|
78 public HaraKiri() { |
|
79 super("Thread-of-Death"); |
|
80 } |
|
81 |
|
82 public void run() |
|
83 { |
|
84 try { |
|
85 Thread.sleep(5000); |
|
86 } catch (Exception foo) { |
|
87 } |
|
88 System.exit(0); |
|
89 } |
|
90 } |
|
91 } |