corba/src/share/classes/com/sun/corba/se/impl/activation/ServerTableEntry.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
package com.sun.corba.se.impl.activation;
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * @author      Anita Jindal
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 * @since       JDK1.2
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import com.sun.corba.se.spi.activation.Server;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.spi.activation.EndPointInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.spi.activation.ORBAlreadyRegistered;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import com.sun.corba.se.spi.activation.ORBPortInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import com.sun.corba.se.spi.activation.InvalidORBid;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.spi.activation.ServerHeldDown;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.spi.activation.IIOP_CLEAR_TEXT;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.logging.ActivationSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.HashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.util.Iterator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.util.NoSuchElementException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
public class ServerTableEntry
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    private final static int DE_ACTIVATED = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    private final static int ACTIVATING   = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
    private final static int ACTIVATED    = 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    private final static int RUNNING      = 3;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    private final static int HELD_DOWN    = 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    private String printState()
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        String str = "UNKNOWN";
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        switch (state) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
        case (DE_ACTIVATED) : str = "DE_ACTIVATED"; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        case (ACTIVATING  ) : str = "ACTIVATING  "; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        case (ACTIVATED   ) : str = "ACTIVATED   "; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        case (RUNNING     ) : str = "RUNNING     "; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        case (HELD_DOWN   ) : str = "HELD_DOWN   "; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
        default: break;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        return str;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    private final static long waitTime    = 2000;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    private static final int ActivationRetryMax = 5;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    // state of each entry
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    private int state;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    private int serverId;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    private HashMap orbAndPortInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    private Server serverObj;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    private ServerDef serverDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    private Process process;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    private int activateRetryCount=0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    private String activationCmd;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    private ActivationSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        return "ServerTableEntry[" + "state=" + printState() +
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            " serverId=" + serverId +
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            " activateRetryCount=" + activateRetryCount + "]" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    // get the string needed to make the activation command
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    private static String javaHome, classPath, fileSep, pathSep;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        javaHome  = System.getProperty("java.home");
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        classPath = System.getProperty("java.class.path");
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        fileSep   = System.getProperty("file.separator");
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        pathSep   = System.getProperty("path.separator");
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    ServerTableEntry( ActivationSystemException wrapper,
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        int serverId, ServerDef serverDef, int initialPort,
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        String dbDirName, boolean verify, boolean debug )
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        this.wrapper = wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
        this.serverId = serverId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        this.serverDef = serverDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        this.debug = debug ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        // create a HashMap with capacity 255
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        // Since all methods are synchronized, we don't need any
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        // additional synchronization mechanisms
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        orbAndPortInfo = new HashMap(255);
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        activateRetryCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        state = ACTIVATING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        // compute the activation command
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        activationCmd =
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            // add path to the java vm
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            javaHome + fileSep + "bin" + fileSep + "java " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            // add any arguments to the server Java VM
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
            serverDef.serverVmArgs + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
            // add ORB properties
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
            "-Dioser=" + System.getProperty( "ioser" ) + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            "-D" + ORBConstants.INITIAL_PORT_PROPERTY   + "=" + initialPort + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            "-D" + ORBConstants.DB_DIR_PROPERTY         + "=" + dbDirName + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
            "-D" + ORBConstants.ACTIVATED_PROPERTY      + "=true " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
            "-D" + ORBConstants.SERVER_ID_PROPERTY      + "=" + serverId + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            "-D" + ORBConstants.SERVER_NAME_PROPERTY    + "=" + serverDef.serverName + " " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            // we need to pass in the verify flag, so that the server is not
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            // launched, when we try to validate its definition during registration
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            // into the RepositoryImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
            (verify ? "-D" + ORBConstants.SERVER_DEF_VERIFY_PROPERTY + "=true ": "") +
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
            // add classpath to the server
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            "-classpath " + classPath +
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
            (serverDef.serverClassPath.equals("") == true ? "" : pathSep) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            serverDef.serverClassPath +
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            // add server class name and arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
            " com.sun.corba.se.impl.activation.ServerMain " + serverDef.serverArgs
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
            // Add the debug flag, if any
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
            + (debug ? " -debug" : "") ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        if (debug) System.out.println(
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
                                      "ServerTableEntry constructed with activation command " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                                      activationCmd);
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
     * Verify whether the server definition is valid.
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    public int verify()
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                System.out.println("Server being verified w/" + activationCmd);
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
            process = Runtime.getRuntime().exec(activationCmd);
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            int result = process.waitFor();
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
                printDebug( "verify", "returns " + ServerMain.printResult( result ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                printDebug( "verify", "returns unknown error because of exception " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
                            e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
            return ServerMain.UNKNOWN_ERROR;
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    private void printDebug(String method, String msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
        System.out.println("ServerTableEntry: method  =" + method);
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
        System.out.println("ServerTableEntry: server  =" + serverId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
        System.out.println("ServerTableEntry: state   =" + printState());
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        System.out.println("ServerTableEntry: message =" + msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        System.out.println();
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    synchronized void activate() throws org.omg.CORBA.SystemException
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        state = ACTIVATED;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
                printDebug("activate", "activating server");
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
            process = Runtime.getRuntime().exec(activationCmd);
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            deActivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                printDebug("activate", "throwing premature process exit");
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
            throw wrapper.unableToStartProcess() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    synchronized void register(Server server)
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        if (state == ACTIVATED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
            serverObj = server;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
            //state = RUNNING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
            //notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
                printDebug("register", "process registered back");
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
                printDebug("register", "throwing premature process exit");
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
            throw wrapper.serverNotExpectedToRegister() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    synchronized void registerPorts( String orbId, EndPointInfo [] endpointList)
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        throws ORBAlreadyRegistered
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        // find if the ORB is already registered, then throw an exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        if (orbAndPortInfo.containsKey(orbId)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            throw new ORBAlreadyRegistered(orbId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        // store all listener ports and their types
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
        int numListenerPorts = endpointList.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        EndPointInfo [] serverListenerPorts = new EndPointInfo[numListenerPorts];
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        for (int i = 0; i < numListenerPorts; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            serverListenerPorts[i] = new EndPointInfo (endpointList[i].endpointType, endpointList[i].port);
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            System.out.println("registering type: " + serverListenerPorts[i].endpointType  +  "  port  " + serverListenerPorts[i].port);
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        // put this set of listener ports in the HashMap associated
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        // with the orbId
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
        orbAndPortInfo.put(orbId, serverListenerPorts);
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        if (state == ACTIVATED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
            state = RUNNING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
            notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        // _REVISIT_, If the state is not equal to ACTIVATED then it is a bug
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        // need to log that error, once the Logging framework is in place
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        // for rip-int.
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            printDebug("registerPorts", "process registered Ports");
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    void install()
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
        Server localServerObj = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        synchronized ( this ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            if (state == RUNNING)
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
                localServerObj = serverObj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
                throw wrapper.serverNotRunning() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        if (localServerObj != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            localServerObj.install() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    void uninstall()
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        Server localServerObj = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        Process localProcess = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        synchronized (this) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            localServerObj = serverObj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
            localProcess = process;
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
            if (state == RUNNING) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                deActivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
                throw wrapper.serverNotRunning() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            if (localServerObj != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                localServerObj.shutdown(); // shutdown the server
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
                localServerObj.uninstall() ; // call the uninstall
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
            if (localProcess != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
                localProcess.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
            // what kind of exception should be thrown
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    synchronized void holdDown()
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        state = HELD_DOWN;
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            printDebug( "holdDown", "server held down" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
        notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    synchronized void deActivate()
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        state = DE_ACTIVATED;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
            printDebug( "deActivate", "server deactivated" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    synchronized void checkProcessHealth( ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        // If the State in the ServerTableEntry is RUNNING and the
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        // Process was shut down abnormally, The method will change the
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
        // server state as De-Activated.
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        if( state == RUNNING ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
                int exitVal = process.exitValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            } catch (IllegalThreadStateException e1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
            synchronized ( this ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
                // Clear the PortInformation as it is old
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
                orbAndPortInfo.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                // Move the state to De-Activated, So that the next
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                // call to this server will re-activate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                deActivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    synchronized boolean isValid()
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        if ((state == ACTIVATING) || (state == HELD_DOWN)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
                printDebug( "isValid", "returns true" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            int exitVal = process.exitValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        } catch (IllegalThreadStateException e1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        if (state == ACTIVATED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
            if (activateRetryCount < ActivationRetryMax) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
                if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                    printDebug("isValid", "reactivating server");
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                activateRetryCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                activate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
                printDebug("isValid", "holding server down");
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
            holdDown();
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        deActivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    synchronized ORBPortInfo[] lookup(String endpointType) throws ServerHeldDown
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        while ((state == ACTIVATING) || (state == ACTIVATED)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
                wait(waitTime);
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
                if (!isValid()) break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
            } catch(Exception e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
        ORBPortInfo[] orbAndPortList = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
        if (state == RUNNING) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
            orbAndPortList = new ORBPortInfo[orbAndPortInfo.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
            Iterator setORBids = orbAndPortInfo.keySet().iterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                int numElements = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                int i;
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
                int port;
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
                while (setORBids.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
                    String orbId = (String) setORBids.next();
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                    // get an entry corresponding to orbId
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
                    EndPointInfo [] serverListenerPorts = (EndPointInfo []) orbAndPortInfo.get(orbId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
                    port = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
                    // return the port corresponding to the endpointType
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                    for (i = 0; i < serverListenerPorts.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
                        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
                            System.out.println("lookup num-ports " + serverListenerPorts.length + "   " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
                                serverListenerPorts[i].endpointType + "   " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
                                serverListenerPorts[i].port );
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
                        if ((serverListenerPorts[i].endpointType).equals(endpointType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
                            port = serverListenerPorts[i].port;
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
                    orbAndPortList[numElements] = new ORBPortInfo(orbId, port);
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
                    numElements++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
            } catch (NoSuchElementException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                // have everything in the table
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
            return orbAndPortList;
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
            printDebug("lookup", "throwing server held down error");
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
        throw new ServerHeldDown( serverId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    synchronized EndPointInfo[] lookupForORB(String orbId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        throws ServerHeldDown, InvalidORBid
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        while ((state == ACTIVATING) || (state == ACTIVATED)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                wait(waitTime);
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
                if (!isValid()) break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
            } catch(Exception e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        EndPointInfo[] portList = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        if (state == RUNNING) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                // get an entry corresponding to orbId
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
                EndPointInfo [] serverListenerPorts = (EndPointInfo []) orbAndPortInfo.get(orbId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
                portList = new EndPointInfo[serverListenerPorts.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
                // return the port corresponding to the endpointType
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
                for (int i = 0; i < serverListenerPorts.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                   if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                      System.out.println("lookup num-ports " + serverListenerPorts.length + "   "
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
                             + serverListenerPorts[i].endpointType + "   " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
                             serverListenerPorts[i].port );
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
                   portList[i] = new EndPointInfo(serverListenerPorts[i].endpointType, serverListenerPorts[i].port);
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
            } catch (NoSuchElementException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
                // no element in HashMap corresponding to ORBid found
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                throw new InvalidORBid();
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
            return portList;
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
            printDebug("lookup", "throwing server held down error");
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        throw new ServerHeldDown( serverId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
    synchronized String[] getORBList()
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
        String [] orbList = new String[orbAndPortInfo.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        Iterator setORBids = orbAndPortInfo.keySet().iterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
            int numElements = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
            while (setORBids.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
                String orbId = (String) setORBids.next();
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
                orbList[numElements++] = orbId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        } catch (NoSuchElementException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
            // have everything in the table
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        return orbList;
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
    int getServerId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
        return serverId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
    boolean isActive()
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        return (state == RUNNING) || (state == ACTIVATED);
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
    synchronized void destroy()
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        Server localServerObj = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        Process localProcess = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        synchronized (this) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
            localServerObj = serverObj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
            localProcess = process;
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
            deActivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
            if (localServerObj != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                localServerObj.shutdown();
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
                printDebug( "destroy", "server shutdown successfully" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                printDebug( "destroy",
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                            "server shutdown threw exception" + ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
            // ex.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
            if (localProcess != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                localProcess.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
                printDebug( "destroy", "process destroyed successfully" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                printDebug( "destroy",
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                            "process destroy threw exception" + ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            // ex.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    private boolean debug = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
}