Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/rmic/newrmic/equivalence/AgentServerImpl.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*/2223import java.rmi.*;24import java.rmi.server.*;25import java.util.*;26import java.io.*;272829/**30* Server accepts agents and could test for validity. Acts as both a home31* server and a regular server. The agent will jump to this host and32* the server will create a thread and allow the agent to run inside of33* it. The agent just queries the system.properties for machine info.34*/35public class AgentServerImpl36extends UnicastRemoteObject37implements AgentServer38{3940/**41* Constructor42*43* @exception RemoteException If a network problem occurs.44*/45public AgentServerImpl() throws RemoteException {46// Could use to set up state of server47}4849/**50* Instantiates Agent Server Implementation and sets security51* manager52*/53public static void main(String args[]) {5455// Set the security Manager56//System.setSecurityManager(new MyRMISecurityManager());5758try {59AgentServerImpl server = new AgentServerImpl();60Naming.rebind("/AgentServer", server);61System.out.println("Ready to receive agents.");62System.err.println("DTI_DoneInitializing");63} catch (Exception e) {64System.err.println("DTI_Error");65System.err.println("Did not establish server");66e.printStackTrace();67}68}6970/**71* Remote method called by Agent to have server accept it.72*/73public synchronized void accept(Agent agent)74throws RemoteException //, InvalidAgentException75{76Thread t;7778// Could check validity of agent here79// checkValid(agent);8081// Create new thread to run agent82t = new Thread(agent);8384System.out.println("Agent Accepted: " + t);8586// Start agent87t.start();88}8990/**91* Remote method called by Agent to return to final server.92*/93public synchronized void returnHome(Agent agent)94throws RemoteException //, InvalidAgentException95{96Enumeration info = null;97boolean bErrorsOccurred = false;9899// Could check validity of agent here100// checkValid(agent);101102// Grab and print collected info from agent103info = agent.getInfo().elements();104System.out.println("Collected information:");105while (info.hasMoreElements()) {106System.out.println(" " + (String) info.nextElement());107}108109System.out.println("\nErrors:");110System.out.println(agent.getErrors());111if(!(agent.getErrors()).equals(""))112bErrorsOccurred = true;113114if(bErrorsOccurred)115{116System.err.println("DTI_Error");117System.err.println("DTI_DoneExecuting");118}119else120{121System.err.println("DTI_DoneExecuting");122}123124}125}126127128