J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 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 | // RMI Activation Functional Test |
| 25 | |
| 26 | import java.rmi.*; |
| 27 | import java.rmi.activation.*; |
| 28 | import java.util.*; |
| 29 | |
| 30 | // DayTimeServerImpl |
| 31 | |
| 32 | public class DayTimeServerImpl |
| 33 | extends Activatable |
| 34 | implements DayTimeInterface { |
| 35 | |
| 36 | private static final String PROG_NAME = "DayTimeServerImpl"; |
| 37 | private static final String SERVER_OBJECT = "DayTimeServer"; |
| 38 | private static final String CLASS_NAME = "activation.DayTimeServerImpl"; |
| 39 | |
| 40 | private static final String POLICY_FILE = "policy_file"; |
| 41 | |
| 42 | private static final String USER_DIR = |
| 43 | System.getProperty("user.dir").replace('\\', '/'); |
| 44 | |
| 45 | private static final String CODE_LOCATION = "file:"+USER_DIR+"/"; |
| 46 | |
| 47 | private static final MarshalledObject DATA = null; |
| 48 | private static ActivationDesc ACTIVATION_DESC = null; |
| 49 | |
| 50 | private TestInterface ref; |
| 51 | |
| 52 | public void ping() throws RemoteException {} |
| 53 | |
| 54 | public ActivationID getActivationID() throws RemoteException { |
| 55 | return super.getID(); |
| 56 | } |
| 57 | |
| 58 | public DayTimeServerImpl(ActivationID id, MarshalledObject data) |
| 59 | throws RemoteException { |
| 60 | super(id, 0); |
| 61 | if (data != null) { |
| 62 | try { |
| 63 | ref = (TestInterface)data.get(); |
| 64 | ref.ping(SERVER_OBJECT); |
| 65 | } |
| 66 | catch (Exception e) { |
| 67 | System.err.println("Exception: " + e); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | public Date getDayTime() throws RemoteException { |
| 73 | return new Date(); |
| 74 | } |
| 75 | |
| 76 | public void exit() throws RemoteException { |
| 77 | System.exit(0); |
| 78 | } |
| 79 | |
| 80 | public void inactive() |
| 81 | throws RemoteException, ActivationException, UnknownObjectException { |
| 82 | |
| 83 | //ShutDown s = new ShutDown(super.getID(),this,ShutDown.NORMAL_SHUTDOWN); |
| 84 | } |
| 85 | |
| 86 | public void unregister() |
| 87 | throws RemoteException, ActivationException, UnknownObjectException { |
| 88 | unregister(super.getID()); |
| 89 | } |
| 90 | |
| 91 | public void register() |
| 92 | throws RemoteException, ActivationException, UnknownObjectException { |
| 93 | register(ACTIVATION_DESC); |
| 94 | } |
| 95 | |
| 96 | public ActivationGroupID getCurrentGroupID() throws RemoteException { |
| 97 | return ActivationGroup.currentGroupID(); |
| 98 | } |
| 99 | |
| 100 | private static void setup() { |
| 101 | |
| 102 | try { |
| 103 | |
| 104 | DayTimeInterface rsi; // Remote server interface |
| 105 | |
| 106 | System.setSecurityManager(new RMISecurityManager()); |
| 107 | |
| 108 | rsi = (DayTimeInterface)Activatable.register(ACTIVATION_DESC); |
| 109 | System.out.println("Got stub for "+SERVER_OBJECT+" implementation"); |
| 110 | |
| 111 | Naming.rebind(SERVER_OBJECT, rsi); |
| 112 | System.out.println("Exported "+SERVER_OBJECT+" implementation"); |
| 113 | |
| 114 | } catch (Exception e) { |
| 115 | System.err.println("Exception: " + e); |
| 116 | e.printStackTrace(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | public static void main(String[] args) { |
| 121 | |
| 122 | try { |
| 123 | Properties props = new Properties(); |
| 124 | props.setProperty("java.security.policy", POLICY_FILE); |
| 125 | |
| 126 | ActivationGroupDesc agd = new ActivationGroupDesc(props, null); |
| 127 | |
| 128 | ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd); |
| 129 | |
| 130 | ACTIVATION_DESC = new ActivationDesc(agid, |
| 131 | CLASS_NAME, CODE_LOCATION, DATA, false); |
| 132 | } |
| 133 | catch (Exception e) { |
| 134 | System.err.println("Exception: " + e); |
| 135 | e.printStackTrace(); |
| 136 | } |
| 137 | |
| 138 | setup(); |
| 139 | } |
| 140 | } |