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