Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/CommandEnvironment/Doctor.java
38828 views
/*1* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.rmi.*;24import java.rmi.activation.*;2526public class Doctor27extends Activatable28implements Eliza, Retireable29{30// reanimation constructor31public Doctor(ActivationID id, MarshalledObject blah)32throws RemoteException33{34super(id, 0); // export self on port 0 (== assign randomly)35System.out.println("Doctor constructed and exported");36}3738private boolean asked = false;3940// implement Eliza.complain()41public String complain(String plaint)42{43System.out.println("Doctor will see you now");44if (this.asked) {45return ("DO GO ON?");46} else {47this.asked = true;48return ("TELL ME ABOUT YOUR MOTHER");49}50}5152// implement Retireable.retire()53public void retire()54{55System.out.println("Doctor retiring");56try {57Activatable.inactive(this.getID());58ActivationGroup.getSystem().unregisterObject(this.getID());59(new HaraKiri()).start();6061} catch (UnknownObjectException uoe) {62System.err.println("Exception in Activatable.inactive:");63uoe.printStackTrace();6465} catch (ActivationException ae) {66System.err.println("Exception in Activatable.inactive:");67ae.printStackTrace();6869} catch (RemoteException re) {70System.err.println("Exception in Activatable.inactive:");71re.printStackTrace();72}73}7475private static class HaraKiri extends Thread76{77public HaraKiri() {78super("Thread-of-Death");79}8081public void run()82{83try {84Thread.sleep(5000);85} catch (Exception foo) {86}87System.exit(0);88}89}90}919293