001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ClusterDaemonProxy.java 9871 2006-11-27 09:55:29Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.management.monitoring;
025:
026: import java.util.Collection;
027:
028: import javax.management.ObjectName;
029:
030: import org.objectweb.jonas.jmx.JonasObjectName;
031:
032: import org.objectweb.util.monolog.api.BasicLevel;
033:
034: /**
035: * ClusterDaemon proxy
036: * It is created when a new element has been found in domain.xml
037: * It holds all the necessary information to go to the ClusterDaemon
038: * @author durieuxp
039: */
040: public class ClusterDaemonProxy extends JMXProxy implements
041: ClusterDaemonProxyMBean {
042:
043: /**
044: * Constructor.
045: * This is called when a ClusterDaemon element has been found in domain.xml.
046: * @param dm the DomainMonitor object reference
047: * @param name cluster daemon name
048: * @param urls possible urls that can be used for connection with the CD
049: */
050: public ClusterDaemonProxy(DomainMonitor dm, String name,
051: Collection urls) {
052: super (dm, name, urls);
053: }
054:
055: /**
056: * Start a Remote JOnAS Server
057: * @param serverName Name of the jonas server
058: * @param otherParams additional parameters to start a server via the ClusterDaemon
059: * @return true if operation succeded
060: */
061: public boolean startServer(String serverName, String otherParams) {
062: logger.log(BasicLevel.DEBUG, "Start remote server: "
063: + serverName);
064: if (!checkConnection()) {
065: // Not yet connected. Try to connect now.
066: if (!connect(getUrls())) {
067: logger.log(BasicLevel.ERROR,
068: "Unable to get connection to cluster daemon "
069: + name);
070: return false;
071: }
072: }
073:
074: // Ask Cluster Daemon to start the Server.
075: String opName = "startJOnAS";
076: String[] opParams = { serverName, getDomain(), otherParams };
077: String[] opSignature = { "java.lang.String",
078: "java.lang.String", "java.lang.String" };
079: try {
080: ObjectName on = JonasObjectName.clusterDaemon();
081: connection.invoke(on, opName, opParams, opSignature);
082: } catch (Exception e) {
083: logger.log(BasicLevel.ERROR, "Cannot start server: " + e);
084: return false;
085: }
086: return true;
087: }
088:
089: /**
090: * Stop a Remote JOnAS Server
091: * @param serverName Name of the jonas server
092: * @param otherParams additional parameters that could be used to stop the server
093: * @return true if operation succeded
094: */
095: public boolean stopServer(String serverName, String otherParams) {
096: logger.log(BasicLevel.DEBUG, "Stop remote server: "
097: + serverName);
098: if (!checkConnection()) {
099: // Not yet connected. Try to connect now.
100: if (!connect(getUrls())) {
101: logger.log(BasicLevel.ERROR,
102: "Unable to get connection to cluster daemon "
103: + name);
104: return false;
105: }
106: }
107:
108: // Ask Cluster Daemon to stop the Server.
109: String opName = "stopJOnAS";
110: String[] opParams = { serverName };
111: String[] opSignature = { "java.lang.String" };
112: try {
113: ObjectName on = JonasObjectName.clusterDaemon();
114: connection.invoke(on, opName, opParams, opSignature);
115: } catch (Exception e) {
116: logger.log(BasicLevel.ERROR, "Cannot stop server: " + e);
117: return false;
118: }
119: return true;
120: }
121:
122: public void startAllServers(String otherParams) {
123: logger.log(BasicLevel.DEBUG, "");
124: if (!checkConnection()) {
125: // Not yet connected. Try to connect now.
126: if (!connect(getUrls())) {
127: logger.log(BasicLevel.ERROR,
128: "Unable to get connection to cluster daemon "
129: + name);
130: return;
131: }
132: }
133:
134: // Ask Cluster Daemon to start all the Servers.
135: String opName = "startAllJOnAS";
136: String[] opParams = { getDomain(), otherParams };
137: String[] opSignature = { "java.lang.String", "java.lang.String" };
138: try {
139: ObjectName on = JonasObjectName.clusterDaemon();
140: connection.invoke(on, opName, opParams, opSignature);
141: } catch (Exception e) {
142: logger.log(BasicLevel.ERROR, "Cannot start server: " + e);
143: // TODO
144: }
145: }
146:
147: public void stopAllServers(String otherParams) {
148: logger.log(BasicLevel.DEBUG, "");
149: if (!checkConnection()) {
150: // Not yet connected. Try to connect now.
151: if (!connect(getUrls())) {
152: logger.log(BasicLevel.ERROR,
153: "Unable to get connection to cluster daemon "
154: + name);
155: return;
156: }
157: }
158:
159: // Ask Cluster Daemon to start all the Servers.
160: String opName = "stopAllJOnAS";
161: String[] opParams = {};
162: String[] opSignature = {};
163: try {
164: ObjectName on = JonasObjectName.clusterDaemon();
165: connection.invoke(on, opName, opParams, opSignature);
166: } catch (Exception e) {
167: logger.log(BasicLevel.ERROR, "Cannot stop server: " + e);
168: // TODO
169: }
170: }
171:
172: /**
173: * Check the MBean server connection and possibly change state
174: */
175: public void checkit() {
176: logger.log(BasicLevel.DEBUG, name);
177:
178: switch (state) {
179: case INITIAL:
180: case UNREACHABLE:
181: if (checkConnection()) {
182: state = RUNNING;
183: } else {
184: if (!connect(getUrls())) {
185: state = UNREACHABLE;
186: } else {
187: state = RUNNING;
188: }
189: }
190: break;
191: }
192: }
193:
194: }
|