1 /* 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package com.sun.jmx.snmp.daemon; 28 29 30 31 /** 32 * Defines generic behaviour for the server 33 * part of a connector or an adaptor. Most connectors or adaptors extend <CODE>CommunicatorServer</CODE> 34 * and inherit this behaviour. Connectors or adaptors that do not fit into this model do not extend 35 * <CODE>CommunicatorServer</CODE>. 36 * <p> 37 * An <CODE>CommunicatorServer</CODE> is an active object, it listens for client requests 38 * and processes them in its own thread. When necessary, a <CODE>CommunicatorServer</CODE> 39 * creates other threads to process multiple requests concurrently. 40 * <p> 41 * A <CODE>CommunicatorServer</CODE> object can be stopped by calling the <CODE>stop</CODE> 42 * method. When it is stopped, the <CODE>CommunicatorServer</CODE> no longer listens to client 43 * requests and no longer holds any thread or communication resources. 44 * It can be started again by calling the <CODE>start</CODE> method. 45 * <p> 46 * A <CODE>CommunicatorServer</CODE> has a <CODE>state</CODE> property which reflects its 47 * activity. 48 * <p> 49 * <TABLE> 50 * <TR><TH>CommunicatorServer</TH> <TH>State</TH></TR> 51 * <TR><TD><CODE>stopped</CODE></TD> <TD><CODE>OFFLINE</CODE></TD></TR> 52 * <TR><TD><CODE>starting</CODE></TD> <TD><CODE>STARTING</CODE></TD></TR> 53 * <TR><TD><CODE>running</CODE></TD> <TD><CODE>ONLINE</CODE></TD></TR> 54 * <TR><TD><CODE>stopping</CODE></TD> <TD><CODE>STOPPING</CODE></TD></TR> 55 * </TABLE> 56 * <p> 57 * The <CODE>STARTING</CODE> state marks the transition from <CODE>OFFLINE</CODE> to 58 * <CODE>ONLINE</CODE>. 59 * <p> 60 * The <CODE>STOPPING</CODE> state marks the transition from <CODE>ONLINE</CODE> to 61 * <CODE>OFFLINE</CODE>. This occurs when the <CODE>CommunicatorServer</CODE> is 62 * finishing or interrupting active requests. 63 * <p> 64 * A <CODE>CommunicatorServer</CODE> may serve several clients concurrently. The 65 * number of concurrent clients can be limited using the property 66 * <CODE>maxActiveClientCount</CODE>. The default value of this property is 67 * defined by the subclasses. 68 * <p> 69 * When a <CODE>CommunicatorServer</CODE> is unregistered from the MBeanServer, 70 * it is stopped automatically. 71 * 72 * <p><b>This API is a Sun Microsystems internal API and is subject 73 * to change without notice.</b></p> 74 */ 75 76 public interface CommunicatorServerMBean { 77 78 /** 79 * Starts this <CODE>CommunicatorServer</CODE>. 80 * <p> 81 * Has no effect if this <CODE>CommunicatorServer</CODE> is <CODE>ONLINE</CODE> or 82 * <CODE>STOPPING</CODE>. 83 */ 84 public void start() ; 85 86 /** 87 * Stops this <CODE>CommunicatorServer</CODE>. 88 * <p> 89 * Has no effect if this <CODE>CommunicatorServer</CODE> is <CODE>OFFLINE</CODE> or 90 * <CODE>STOPPING</CODE>. 91 */ 92 public void stop() ; 93 94 /** 95 * Tests if the <CODE>CommunicatorServer</CODE> is active. 96 * 97 * @return True if connector is <CODE>ONLINE</CODE>; false otherwise. 98 */ 99 public boolean isActive() ; 100 101 /** 102 * Waits untill either the State attribute of this MBean equals the specified <VAR>state</VAR> parameter, 103 * or the specified <VAR>timeOut</VAR> has elapsed. The method <CODE>waitState</CODE> returns with a boolean value indicating whether 104 * the specified <VAR>state</VAR> parameter equals the value of this MBean's State attribute at the time the method terminates. 105 * 106 * Two special cases for the <VAR>timeOut</VAR> parameter value are: 107 * <UL><LI> if <VAR>timeOut</VAR> is negative then <CODE>waitState</CODE> returns immediately (i.e. does not wait at all),</LI> 108 * <LI> if <VAR>timeOut</VAR> equals zero then <CODE>waitState</CODE> waits untill the value of this MBean's State attribute 109 * is the same as the <VAR>state</VAR> parameter (i.e. will wait indefinitely if this condition is never met).</LI></UL> 110 * 111 * @param state The value of this MBean's State attribute 112 * to wait for. <VAR>state</VAR> can be one of: 113 * <ul> 114 * <li><CODE>CommunicatorServer.OFFLINE</CODE>,</li> 115 * <li><CODE>CommunicatorServer.ONLINE</CODE>,</li> 116 * <li><CODE>CommunicatorServer.STARTING</CODE>,</li> 117 * <li><CODE>CommunicatorServer.STOPPING</CODE>.</li> 118 * </ul> 119 * @param timeOut The maximum time to wait for, in 120 * milliseconds, if positive. 121 * Infinite time out if 0, or no waiting at all if negative. 122 * 123 * @return true if the value of this MBean's State attribute is the 124 * same as the <VAR>state</VAR> parameter; false otherwise. 125 */ 126 public boolean waitState(int state , long timeOut) ; 127 128 /** 129 * Gets the state of this <CODE>CommunicatorServer</CODE> as an integer. 130 * 131 * @return <CODE>ONLINE</CODE>, <CODE>OFFLINE</CODE>, <CODE>STARTING</CODE> or <CODE>STOPPING</CODE>. 132 */ 133 public int getState() ; 134 135 /** 136 * Gets the state of this <CODE>CommunicatorServer</CODE> as a string. 137 * 138 * @return One of the strings "ONLINE", "OFFLINE", "STARTING" or "STOPPING". 139 */ 140 public String getStateString() ; 141 142 /** 143 * Gets the host name used by this <CODE>CommunicatorServer</CODE>. 144 * 145 * @return The host name used by this <CODE>CommunicatorServer</CODE>. 146 */ 147 public String getHost() ; 148 149 /** 150 * Gets the port number used by this <CODE>CommunicatorServer</CODE>. 151 * 152 * @return The port number used by this <CODE>CommunicatorServer</CODE>. 153 */ 154 public int getPort() ; 155 156 /** 157 * Sets the port number used by this <CODE>CommunicatorServer</CODE>. 158 * 159 * @param port The port number used by this <CODE>CommunicatorServer</CODE>. 160 * 161 * @exception java.lang.IllegalStateException This method has been invoked 162 * while the communicator was ONLINE or STARTING. 163 */ 164 public void setPort(int port) throws java.lang.IllegalStateException ; 165 166 /** 167 * Gets the protocol being used by this <CODE>CommunicatorServer</CODE>. 168 * @return The protocol as a string. 169 */ 170 public abstract String getProtocol() ; 171 }