test/jdk/sun/rmi/rmic/newrmic/equivalence/AgentServerImpl.java
author zgu
Tue, 07 Nov 2017 09:37:45 -0500
changeset 47802 18dccdc438d7
parent 47216 71c04702a3d5
permissions -rw-r--r--
8189688: NMT: Report per-class load metadata information Summary: Report per-class loader metadata info via NMT jcmd metadata sub-command Reviewed-by: stuefe, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Server accepts agents and could test for validity.  Acts as both a home
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * server and a regular server.  The agent will jump to this host and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * the server will create a thread and allow the agent to run inside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * it.  The agent just queries the system.properties for machine info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class AgentServerImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    implements AgentServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * @exception RemoteException If a network problem occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public AgentServerImpl() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        // Could use to set up state of server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Instantiates Agent Server Implementation and sets security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // Set the security Manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        //System.setSecurityManager(new MyRMISecurityManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            AgentServerImpl server = new AgentServerImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            Naming.rebind("/AgentServer", server);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            System.out.println("Ready to receive agents.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                System.err.println("DTI_DoneInitializing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                System.err.println("DTI_Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            System.err.println("Did not establish server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Remote method called by Agent to have server accept it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public synchronized void accept(Agent agent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        throws RemoteException //, InvalidAgentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        Thread t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // Could check validity of agent here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // checkValid(agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // Create new thread to run agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        t = new Thread(agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        System.out.println("Agent Accepted: " + t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // Start agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        t.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Remote method called by Agent to return to final server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public synchronized void returnHome(Agent agent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        throws RemoteException //, InvalidAgentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Enumeration info = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        boolean bErrorsOccurred = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // Could check validity of agent here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // checkValid(agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // Grab and print collected info from agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        info = agent.getInfo().elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        System.out.println("Collected information:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        while (info.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.out.println("     " + (String) info.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        System.out.println("\nErrors:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        System.out.println(agent.getErrors());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if(!(agent.getErrors()).equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                bErrorsOccurred = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if(bErrorsOccurred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                System.err.println("DTI_Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                System.err.println("DTI_DoneExecuting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                System.err.println("DTI_DoneExecuting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}