b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * CDDL HEADER START
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * The contents of this file are subject to the terms of the
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * Common Development and Distribution License (the "License").
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * You may not use this file except in compliance with the License.
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * See LICENSE.txt included in this distribution for the specific
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * language governing permissions and limitations under the License.
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * When distributing Covered Code, include this CDDL HEADER in each
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * file and include the License file at LICENSE.txt.
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * If applicable, add the following below this CDDL HEADER, with the
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * fields enclosed by brackets "[]" replaced with your own identifying
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * information: Portions Copyright [yyyy] [name of copyright owner]
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * CDDL HEADER END
9f5e862909e44377e352d0fed9e5f582ee4e5773Knut Anders Hatlen * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Bergpackage org.opensolaris.opengrok.management.client;
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlenimport org.opensolaris.opengrok.management.Constants;
1ed29ca262fd65b3bd912e2c0c3d4e825c0ddd4dLubos Koscoimport org.opensolaris.opengrok.management.OGAgent;
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * @author Jan S Berg
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String HOST = Constants.JMX_HOST;
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String JMXPORT = Constants.JMX_PORT;
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String RMIPORT = Constants.RMI_PORT;
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String JMXURL = Constants.JMX_URL;
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String INDEXTIMEOUTKEY = "org.opensolaris.opengrok.management.indextimeout";
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String CONNECTIONTIMEOUTKEY = "org.opensolaris.opengrok.management.connectiontimeout";
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String LOGGINGPATHKEY = Constants.LOG_PATH;
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String FILELOGLEVELKEY = "org.opensolaris.opengrok.management.logging.filelevel";
123edc876010aee39f9c9caf2520c418d6b96fcaTrond Norbye public static final String CONSOLELOGLEVELKEY = "org.opensolaris.opengrok.management.logging.consolelevel";
04eceded116c11ab5ed16e40196adbe969b94aabJorgen Austvik private final Properties ogcProperties = new Properties();
f7d9cf264bdd4c0a04823aa684239d52870706c0Lubos Kosco private boolean existingSettings = false; //NOPMD we do change it, but in deep finally block
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * Get settings for the OpenGrok Management Agent Client
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * Try if a config file has been given
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * if not set, try default settings (oga.properties in management directory)
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg * @throws java.io.IOException
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg public SettingsPersistence(String cfgfile) throws IOException {
9f5e862909e44377e352d0fed9e5f582ee4e5773Knut Anders Hatlen try (InputStream in = OGAgent.class.getResourceAsStream("oga.properties")) {
9f5e862909e44377e352d0fed9e5f582ee4e5773Knut Anders Hatlen try (FileInputStream is = new FileInputStream(propertyFile)) {
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen * Get the JMX URL to the agent. Generate a URL from host and port
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen * properties if no URL has been specified.
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen * @return the URL to the agent
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen String url = ogcProperties.getProperty(JMXURL);
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen String host = ogcProperties.getProperty(HOST, "localhost");
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen ogcProperties.getProperty(JMXPORT, "9292"));
7bba4db4d753dfb9f7385c22d04350469988dc54Jens Elkner int rmiport = Integer.parseInt(ogcProperties.getProperty(
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen url = "service:jmx:rmi://" + host + ":" + jmxport +
01bfcfd168ac9fffe2d80a88093acccb88706ef6Knut Anders Hatlen "/jndi/rmi://" + host + ":" + rmiport + "/opengrok";
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg public void setProperty(String key, String val) {
b8f2cc83ded7038d6b2268f028350f59d4c939b1Jan S Berg return Level.parse(ogcProperties.getProperty(FILELOGLEVELKEY));