Management.java revision 591
364N/A/*
364N/A * CDDL HEADER START
364N/A *
364N/A * The contents of this file are subject to the terms of the
364N/A * Common Development and Distribution License (the "License").
364N/A * You may not use this file except in compliance with the License.
364N/A *
364N/A * See LICENSE.txt included in this distribution for the specific
364N/A * language governing permissions and limitations under the License.
364N/A *
364N/A * When distributing Covered Code, include this CDDL HEADER in each
364N/A * file and include the License file at LICENSE.txt.
364N/A * If applicable, add the following below this CDDL HEADER, with the
364N/A * fields enclosed by brackets "[]" replaced with your own identifying
364N/A * information: Portions Copyright [yyyy] [name of copyright owner]
364N/A *
364N/A * CDDL HEADER END
364N/A */
364N/A
364N/A/*
364N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
364N/A * Use is subject to license terms.
364N/A */
364N/Apackage org.opensolaris.opengrok.management;
364N/A
364N/Aimport java.util.Date;
364N/Aimport java.util.Properties;
364N/Aimport java.util.logging.Logger;
364N/Aimport javax.management.MBeanRegistration;
364N/Aimport javax.management.MBeanServer;
364N/Aimport javax.management.ObjectName;
364N/Aimport org.opensolaris.opengrok.Info;
364N/A
364N/Apublic final class Management implements ManagementMBean, MBeanRegistration {
364N/A
364N/A private static Management managementInstance = null;
364N/A private final static Logger log = Logger.getLogger("org.opensolaris.opengrok");
364N/A private final Properties ogaProperties;
364N/A private final long startTime; // Stores the time this bean is created
364N/A private Boolean update = Boolean.FALSE;
364N/A private Integer noThreads = Integer.valueOf(1);
364N/A private String[] subFiles = new String[]{};
364N/A private String configurationFile = null;
364N/A private String publishHost = null;
364N/A
364N/A /**
364N/A * The only constructor is private, so other classes will only get an
364N/A * instance through the static factory method getInstance().
364N/A */
364N/A private Management(Properties ogaProperties) {
364N/A startTime = System.currentTimeMillis();
364N/A this.ogaProperties = ogaProperties;
364N/A updateProperties();
364N/A }
364N/A
364N/A private void updateProperties() {
364N/A update = Boolean.parseBoolean(ogaProperties.getProperty("org.opensolaris.opengrok.indexer.updatedatabase"));
364N/A noThreads = Integer.parseInt(ogaProperties.getProperty("org.opensolaris.opengrok.indexer.numberofthreads"));
364N/A configurationFile = ogaProperties.getProperty("org.opensolaris.opengrok.configuration.file");
364N/A String subfiles = ogaProperties.getProperty("org.opensolaris.opengrok.indexer.subfiles");
364N/A if (subfiles != null) {
364N/A subFiles = subfiles.split(",");
364N/A }
364N/A publishHost = ogaProperties.getProperty("org.opensolaris.opengrok.indexer.publishserver.url");
367N/A
364N/A }
364N/A
364N/A /**
364N/A * Static factory method to get an instance of Management.
364N/A * @param ogaProperties The properties to use
364N/A * @return A management instance to use
364N/A */
364N/A @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
364N/A public static synchronized Management getInstance(Properties ogaProperties) {
364N/A if (managementInstance == null) {
364N/A managementInstance = new Management(ogaProperties);
364N/A }
364N/A return managementInstance;
364N/A }
364N/A
364N/A /**
364N/A * Static factory method to get an instance of management.
364N/A * Returns null if Management has not been initialized yet.
364N/A */
364N/A public static Management getInstance() {
367N/A return managementInstance;
364N/A }
364N/A
/**
* Get a selected property from configuration.
* @return String with property value
*/
public String getProperty(String key) {
return ogaProperties.getProperty(key);
}
/**
* Set a selected property in the configuration.
* @param key the String key for the property to be set.
* $param value the String value for the property to be set.
*/
public void setProperty(String key, String value) {
if (key == null) {
log.severe("Trying to set property with key == null");
return;
}
ogaProperties.setProperty(key, value);
saveProperties();
}
private void saveProperties() {
throw new UnsupportedOperationException("Not yet implemented");
}
public ObjectName preRegister(MBeanServer server, ObjectName name) {
return name;
}
public void postRegister(Boolean registrationDone) {
// not used
}
public void preDeregister() {
// not used
}
public void postDeregister() {
// not used
}
/**
* Stops the agent, so it is not restarted.
*/
public void stop() {
log.warning("STOPPING AGENT!");
//WrapperManager.stop(0);
}
public String getSystemProperty(String key) {
return System.getProperty(key);
}
public void setSystemProperty(String key, String value) {
if (key == null) {
log.severe("Trying to set property with key == null");
return;
}
System.setProperty(key, value);
}
public String getAllSystemProperties() {
return System.getProperties().toString();
}
public String getSystemEnvProperty(String key) {
return System.getenv(key);
}
public String getAllSystemEnvProperties() {
return System.getenv().toString();
}
/**
* Get the time (in milliseconds since 1970) when the agent was started
* @return long time when the agent was started, in milliseconds.
*/
public long getStartTime() {
return startTime;
}
/**
* Get a Date object with the time the agent was started.
* @return Date with the starting date
*/
public Date getStartDate() {
return new Date(startTime);
}
/**
* Get the version tag for the agent
* @return String the version tag for this agent
*/
public String getVersion() {
return Info.getFullVersion();
}
public void setUpdateIndexDatabase(Boolean val) {
this.update = val;
}
public Boolean getUpdateIndexDatabase() {
return update;
}
public void setNumberOfThreads(Integer val) {
this.noThreads = val;
}
public Integer getNumberOfThreads() {
return noThreads;
}
public void setSubFiles(String[] sublist) {
this.subFiles = (sublist == null) ? null : (String[]) sublist.clone();
}
@SuppressWarnings("PMD.MethodReturnsInternalArray")
public String[] getSubFiles() {
return (subFiles == null) ? null : (String[]) subFiles.clone();
}
public String getConfigurationFile() {
return configurationFile;
}
public String getPublishServerURL() {
return publishHost;
}
}