0N/A/*
2362N/A * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.activation.*;
0N/A
0N/Apublic class Doctor
0N/A extends Activatable
0N/A implements Eliza, Retireable
0N/A{
0N/A // reanimation constructor
0N/A public Doctor(ActivationID id, MarshalledObject blah)
0N/A throws RemoteException
0N/A {
0N/A super(id, 0); // export self on port 0 (== assign randomly)
0N/A System.out.println("Doctor constructed and exported");
0N/A }
0N/A
0N/A private boolean asked = false;
0N/A
0N/A // implement Eliza.complain()
0N/A public String complain(String plaint)
0N/A {
0N/A System.out.println("Doctor will see you now");
0N/A if (this.asked) {
0N/A return ("DO GO ON?");
0N/A } else {
0N/A this.asked = true;
0N/A return ("TELL ME ABOUT YOUR MOTHER");
0N/A }
0N/A }
0N/A
0N/A // implement Retireable.retire()
0N/A public void retire()
0N/A {
0N/A System.out.println("Doctor retiring");
0N/A try {
0N/A Activatable.inactive(this.getID());
0N/A ActivationGroup.getSystem().unregisterObject(this.getID());
0N/A (new HaraKiri()).start();
0N/A
0N/A } catch (UnknownObjectException uoe) {
0N/A System.err.println("Exception in Activatable.inactive:");
0N/A uoe.printStackTrace();
0N/A
0N/A } catch (ActivationException ae) {
0N/A System.err.println("Exception in Activatable.inactive:");
0N/A ae.printStackTrace();
0N/A
0N/A } catch (RemoteException re) {
0N/A System.err.println("Exception in Activatable.inactive:");
0N/A re.printStackTrace();
0N/A }
0N/A }
0N/A
0N/A private static class HaraKiri extends Thread
0N/A {
0N/A public HaraKiri() {
0N/A super("Thread-of-Death");
0N/A }
0N/A
0N/A public void run()
0N/A {
0N/A try {
0N/A Thread.sleep(5000);
0N/A } catch (Exception foo) {
0N/A }
0N/A System.exit(0);
0N/A }
0N/A }
0N/A}