📄 adminmodule.java
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2004 - 2006 ScalAgent Distributed Technologies * Copyright (C) 2004 Bull SA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Initial developer(s): Frederic Maistre (Bull SA) * Contributor(s): ScalAgent Distributed Technologies * Benoit Pelletier (Bull SA) */package org.objectweb.joram.client.jms.admin;import org.objectweb.joram.client.jms.Destination;import org.objectweb.joram.client.jms.Queue;import org.objectweb.joram.client.jms.Topic;import org.objectweb.joram.client.jms.TopicConnectionFactory;import org.objectweb.joram.client.jms.Message;import org.objectweb.joram.client.jms.ha.local.TopicHALocalConnectionFactory;import org.objectweb.joram.client.jms.ha.tcp.TopicHATcpConnectionFactory;import org.objectweb.joram.client.jms.local.TopicLocalConnectionFactory;import org.objectweb.joram.client.jms.tcp.TopicTcpConnectionFactory;import org.objectweb.joram.shared.admin.*;import java.net.ConnectException;import java.net.UnknownHostException;import java.util.Enumeration;import java.util.Hashtable;import java.util.List;import java.util.Properties;import java.util.Vector;import java.io.Reader;import java.io.FileReader;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.FileNotFoundException;import javax.jms.*;import org.objectweb.joram.client.jms.JoramTracing;import org.objectweb.util.monolog.api.BasicLevel;/** * The <code>AdminModule</code> class allows to set an administrator * connection to a given JORAM server, and provides administration and * monitoring methods at a server/platform level. */public class AdminModule{ public static final String ADM_NAME_PROPERTY = "JoramAdminXML"; public static final String DEFAULT_ADM_NAME = "default"; public static final String REQUEST_TIMEOUT_PROP = "org.objectweb.joram.client.jms.admin.requestTimeout"; public static final long DEFAULT_REQUEST_TIMEOUT = 120000; /** The identifier of the server the module is connected to. */ private static int localServer; /** The host name or IP address this client is connected to. */ protected static String localHost; /** The port number of the client connection. */ protected static int localPort; /** The connection used to link the administrator and the platform. */ private static TopicConnection cnx = null; /** The requestor for sending the synchronous requests. */ private static AdminRequestor requestor; /** ObjectMessage sent to the platform. */ private static ObjectMessage requestMsg; /** ObjectMessage received from the platform. */ private static ObjectMessage replyMsg; /** Reply object received from the platform. */ protected static AdminReply reply; private static int requestCounter; private static long requestTimeout = Long.getLong(REQUEST_TIMEOUT_PROP, DEFAULT_REQUEST_TIMEOUT).longValue(); /** <code>true</code> if the underlying a JORAM HA server is defined */ private static boolean isHa = false; /** * This method execute the XML script file that the path is given in * parameter. * * @since 4.3.12 */ public static void main(String[] args) { try { AdminModule.executeXMLAdmin(args[0]); } catch (Exception exc) { exc.printStackTrace(); } } /** * Opens a connection dedicated to administering with the Joram server * which parameters are wrapped by a given * <code>TopicConnectionFactory</code>. * * @param cnxFact The TopicConnectionFactory to use for connecting. * @param name Administrator's name. * @param password Administrator's password. * * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void connect(javax.jms.TopicConnectionFactory cnxFact, String name, String password) throws ConnectException, AdminException { if (cnx != null) return; try { cnx = cnxFact.createTopicConnection(name, password); requestor = new AdminRequestor(cnx); cnx.start(); org.objectweb.joram.client.jms.FactoryParameters params = null; if (cnxFact instanceof javax.jms.XATopicConnectionFactory) params = ((org.objectweb.joram.client.jms.XAConnectionFactory) cnxFact).getParameters(); else params = ((org.objectweb.joram.client.jms.ConnectionFactory) cnxFact).getParameters(); localHost = params.getHost(); localPort = params.getPort(); // Getting the id of the local server: localServer = requestor.getLocalServerId(); } catch (JMSSecurityException exc) { if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) JoramTracing.dbgClient.log( BasicLevel.DEBUG, "", exc); throw new AdminException(exc.getMessage()); } catch (JMSException exc) { if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) JoramTracing.dbgClient.log( BasicLevel.DEBUG, "", exc); throw new ConnectException("Connecting failed: " + exc); } } /** * Opens a TCP connection with the Joram server running on a given host and * listening to a given port. * * @param host The name or IP address of the host the server is running on. * @param port The number of the port the server is listening to. * @param name Administrator's name. * @param password Administrator's password. * @param cnxTimer Timer in seconds during which connecting to the server * is attempted. * * @exception UnknownHostException If the host is invalid. * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void connect(String hostName, int port, String name, String password, int cnxTimer) throws UnknownHostException, ConnectException, AdminException { connect(hostName,port,name,password,cnxTimer, "org.objectweb.joram.client.jms.tcp.ReliableTcpClient"); } /** * Opens a TCP connection with the Joram server running on a given host and * listening to a given port. * * @param host The name or IP address of the host the server is running on. * @param port The number of the port the server is listening to. * @param name Administrator's name. * @param password Administrator's password. * @param cnxTimer Timer in seconds during which connecting to the server * is attempted. * @param reliableClass Reliable class name. * * @exception UnknownHostException If the host is invalid. * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void connect(String hostName, int port, String name, String password, int cnxTimer, String reliableClass) throws UnknownHostException, ConnectException, AdminException { javax.jms.TopicConnectionFactory cnxFact =null; if (isHa) { String urlHa = "hajoram://" + hostName + ":" + port; cnxFact = TopicHATcpConnectionFactory.create(urlHa); } else { cnxFact = TopicTcpConnectionFactory.create(hostName, port, reliableClass); } ((org.objectweb.joram.client.jms.ConnectionFactory) cnxFact).getParameters().connectingTimer = cnxTimer; connect(cnxFact, name, password); } /** * Opens a TCP connection with the Joram server running on the default * "locahost" host and listening to the default 16010 port. * * @param name Administrator's name. * @param password Administrator's password. * @param cnxTimer Timer in seconds during which connecting to the server * is attempted. * * @exception UnknownHostException Never thrown. * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void connect(String name, String password, int cnxTimer) throws UnknownHostException, ConnectException, AdminException { connect("localhost", 16010, name, password, cnxTimer); } /** * Opens a TCP connection with the Joram server running on the default * "locahost" host and listening to the default 16010 port. * * @param name Administrator's name. * @param password Administrator's password. * @param cnxTimer Timer in seconds during which connecting to the server * is attempted. * @param reliableClass Reliable class name. * * @exception UnknownHostException Never thrown. * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void connect(String name, String password, int cnxTimer, String reliableClass) throws UnknownHostException, ConnectException, AdminException { connect("localhost", 16010, name, password, cnxTimer, reliableClass); } /** * Opens a connection with the collocated JORAM server. * * @param name Administrator's name. * @param password Administrator's password. * * @exception ConnectException If connecting fails. * @exception AdminException If the administrator identification is * incorrect. */ public static void collocatedConnect(String name, String password) throws ConnectException, AdminException { JoramTracing.dbgClient.log( BasicLevel.DEBUG, "isHa=" + isHa); if (isHa) { connect(TopicHALocalConnectionFactory.create(), name, password); } else { connect(TopicLocalConnectionFactory.create(), name, password); } } /** Closes the administration connection. */ public static void disconnect() { try { if (cnx == null) return; cnx.close(); } catch (JMSException exc) {} cnx = null; } /** * Stops a given server of the platform. * <p> * The request fails if the target server does not belong to the platform. * * @param serverId Identifier of the server to stop. * * @exception ConnectException If the connection fails. * @exception AdminException If the request fails. */ public static void stopServer(int serverId) throws ConnectException, AdminException { try { doRequest(new StopServerRequest(serverId)); if (serverId == localServer) cnx = null; } // ConnectException is intercepted if stopped server is local server. catch (ConnectException exc) { if (serverId != localServer) throw exc; cnx = null; } } /** * Stops the platform local server. * * @exception ConnectException If the connection fails. * @exception AdminException Never thrown. */ public static void stopServer() throws ConnectException, AdminException { stopServer(localServer); } /** * Adds a server to the platform. * * @param serverId Id of the added server * @param hostName Address of the host where the added server is started * @param domainName Name of the domain where the server is added * @param port Listening port of the server in the specified domain * @param serverName Name of the added server * * @exception ConnectException If the connection fails. * @exception AdminException If the request fails. */ public static void addServer(int sid, String hostName, String domainName, int port, String serverName)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -