Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/rmic/newrmic/equivalence/CountServerImpl.java
38867 views
/*1* Copyright (c) 2003, 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*/2223// RMI Activation Functional Test2425import java.rmi.*;26import java.rmi.server.*;27import java.rmi.activation.*;28import java.util.*;2930// CountServerImpl3132public class CountServerImpl33extends Activatable34implements CountInterface {3536private static final String PROG_NAME = "CountServerImpl";37private static final String SERVER_OBJECT = "CountServer";38private static final String CLASS_NAME = "activation.CountServerImpl";3940private static final String POLICY_FILE = "policy_file";4142private static final String USER_DIR =43System.getProperty("user.dir").replace('\\', '/');4445private static final String CODE_LOCATION = "file:"+USER_DIR+"/";4647private static final MarshalledObject DATA = null;48private static ActivationDesc ACTIVATION_DESC = null;4950// Class variable51private static int classCount = 0;5253// Instance variable54private int instanceCount;55private TestInterface ref;5657public CountServerImpl(ActivationID id, MarshalledObject data)58throws RemoteException {59super(id, 0);60instanceCount = 0;61classCount++;62if (data != null) {63try {64ref = (TestInterface)data.get();65ref.ping(SERVER_OBJECT);66}67catch (Exception e) {68System.err.println("Exception: " + e);69}70}71}7273public void ping() throws RemoteException {}7475public int getCount() throws RemoteException {76return instanceCount;77}7879public int incrementCount() throws RemoteException {80return ++instanceCount;81}8283public int decrementCount() throws RemoteException {84return --instanceCount;85}8687public int getClassCount() throws RemoteException {88return classCount;89}9091public String getProperty(String s) throws RemoteException {92return System.getProperty(s);93}9495public void exit() throws RemoteException {96System.exit(0);97}9899public boolean unexportObject(boolean force) {100boolean succeeded = false;101try {102succeeded = Activatable.unexportObject(this, force);103}104catch (Exception e) {105System.err.println("Exception: " + e);106e.printStackTrace();107}108return succeeded;109}110111public ActivationID getActivationID() throws RemoteException {112return super.getID();113}114115public void inactive()116throws RemoteException, ActivationException, UnknownObjectException {117118//ShutDown s = new ShutDown(super.getID(),this,ShutDown.NORMAL_SHUTDOWN);119}120121public void unregister()122throws RemoteException, ActivationException, UnknownObjectException {123unregister(super.getID());124}125126public void register()127throws RemoteException, ActivationException, UnknownObjectException {128register(ACTIVATION_DESC);129}130131public ActivationGroupID getCurrentGroupID() throws RemoteException {132return ActivationGroup.currentGroupID();133}134135private static void setup() {136137try {138139CountInterface rsi; // Remote server interface140141System.setSecurityManager(new RMISecurityManager());142143rsi = (CountInterface)Activatable.register(ACTIVATION_DESC);144System.out.println("Got stub for "+SERVER_OBJECT+" implementation");145146Naming.rebind(SERVER_OBJECT, rsi);147System.out.println("Exported "+SERVER_OBJECT+" implementation");148149} catch (Exception e) {150System.err.println("Exception: " + e);151e.printStackTrace();152}153}154155public static void main(String[] args) {156157try {158Properties props = new Properties();159props.setProperty("java.security.policy", POLICY_FILE);160161ActivationGroupDesc agd = new ActivationGroupDesc(props, null);162163ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd);164165ACTIVATION_DESC = new ActivationDesc(agid,166CLASS_NAME, CODE_LOCATION, DATA, false);167}168catch (Exception e) {169System.err.println("Exception: " + e);170e.printStackTrace();171}172173setup();174}175}176177178