/*
* ALMA - Atacama Large Millimiter Array (c) European Southern Observatory, 2002 Copyright by ESO (in the framework of the ALMA
* collaboration), All rights reserved
*
* 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 (at your option) 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
*/
package alma.acs.util;
import java.net.InetAddress;
import java.util.Vector;
/**
* Used to figure out the dynamic ports ACS is running under.
*
*
* Caution
* Be careful with the method names:
*
* - getXXX() is static
*
- giveXXX() is instance
*
*
*
* @author dfugate October 15, 2003
*/
public class ACSPorts {
// /**
// * Testing purposes only!
// *
// * @param args Not used!
// */
// public static void main(String[] args) {
// System.out.println(getManagerPort());
// System.out.println(getCDBPort());
// System.out.println(getIP());
// System.out.println("done...");
// }
/**
* Name of environment variable defining base port.
*/
public static final String ACS_BASE_PORT_VARIABLE = "ACS.baseport";
/**
* Default base port (integer ranging from 0-9).
*/
public static final String ACS_BASE_PORT_DEFAULT = "0";
//
// ======================== STATIC ============================
//
// -------- Public API ----------
/**
* @return the "ACS Base Port". This is just an integer ranging from 0-9.
*/
public static int getBasePort() {
return globalInstanceForSystemProperty().giveBasePort();
}
/**
* @return the port manager is running on.
*/
public static String getManagerPort() {
return globalInstanceForSystemProperty().giveManagerPort();
}
/**
* @return the port the CORBA Naming Service is running on.
*/
public static String getNamingServicePort() {
return globalInstanceForSystemProperty().giveNamingServicePort();
}
/**
* @return the port the CORBA Notification Service is running on.
*/
public static String getNotifyServicePort() {
return globalInstanceForSystemProperty().giveNotifyServicePort();
}
/**
* @return the port the CORBA Alarm Notification Service is running on.
*/
public static String getAlarmNotifyServicePort() {
return globalInstanceForSystemProperty().giveAlarmNotifyServicePort();
}
/**
* @return the port the CORBA Logging Service is running on.
*/
public static String getLoggingServicePort() {
return globalInstanceForSystemProperty().giveLoggingServicePort();
}
/**
* @return the port the CORBA Interface Repository is running on.
*/
public static String getIRPort() {
return globalInstanceForSystemProperty().giveIRPort();
}
/**
* @return the port the ACS Logging Service is running on.
*/
public static String getLogPort() {
return globalInstanceForSystemProperty().giveLogPort();
}
/**
* @return the port the ACS CDB is running on.
*/
public static String getCDBPort() {
return globalInstanceForSystemProperty().giveCDBPort();
}
/**
* @return the port the ACS alarm service is running on.
*/
public static String getAlarmServicePort() {
return globalInstanceForSystemProperty().giveAlarmServicePort();
}
/**
* @return the constant port (2970) the ACS Container daemon is running on.
*/
public static String getContainerDaemonPort() {
return globalInstanceForSystemProperty().giveContainerDaemonPort();
}
/**
* @return the constant port (2980) the ACS Services daemon is running on.
*/
public static String getServicesDaemonPort() {
return globalInstanceForSystemProperty().giveServicesDaemonPort();
}
/**
* @return the stringified IP or "localhost" if an error
* were to occur.
*/
public static String getIP() {
return globalInstanceForSystemProperty().giveIP();
}
private static Vector instances = new Vector();
/**
* Returns an instance of this class that is configured for the specified basePort.
*
* In earlier versions of this class, one had to set a system property to
* calculate the ports for different instances.
*
* Note that this will create a new instance only if necessary.
*
* @since v1.5
*/
public static ACSPorts globalInstance(int basePort) {
// could limit the allowed values by doing an "if (instanceIndex < 10)" here
// but maybe we want 20 Acs instances at some point in the future
if (basePort < 0)
throw new IllegalArgumentException("invalid baseport: "+basePort);
// fill up to needed size if necessary -
// unfortunately Vector.ensureCapacity() doesn't do the job
for (int i=instances.size(); i