karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Mazza <gma...@talend.com>
Subject Re: svn commit: r1177574 - in /karaf/trunk/shell: console/src/main/java/org/apache/karaf/shell/console/jline/Activator.java dev/src/main/java/org/apache/karaf/shell/dev/SystemProperty.java dev/src/main/resources/OSGI-INF/blueprint/shell-dev.xml
Date Fri, 30 Sep 2011 18:28:42 GMT
On 9/30/2011 5:47 AM, gnodet@apache.org wrote:
> Author: gnodet
> Date: Fri Sep 30 09:47:03 2011
> New Revision: 1177574
>
>
> Added: karaf/trunk/shell/dev/src/main/java/org/apache/karaf/shell/dev/SystemProperty.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/shell/dev/src/main/java/org/apache/karaf/shell/dev/SystemProperty.java?rev=1177574&view=auto
> ==============================================================================
> --- karaf/trunk/shell/dev/src/main/java/org/apache/karaf/shell/dev/SystemProperty.java
(added)
> +++ karaf/trunk/shell/dev/src/main/java/org/apache/karaf/shell/dev/SystemProperty.java
Fri Sep 30 09:47:03 2011
> @@ -0,0 +1,56 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.karaf.shell.dev;
> +
> +import java.io.File;
> +
> +import org.apache.felix.gogo.commands.Argument;
> +import org.apache.felix.gogo.commands.Command;
> +import org.apache.felix.gogo.commands.Option;
> +import org.apache.felix.utils.properties.Properties;
> +import org.apache.karaf.shell.console.OsgiCommandSupport;
> +
> +/**
> + * Command that allow access to system properties easily.
> + */
> +@Command(scope = "dev", name = "system-property", description = "Get or set a system
property.")
> +public class SystemProperty extends OsgiCommandSupport {
> +
> +    @Option(name = "-p", aliases = { "--persistent" }, description = "Persist the new
value to the etc/system.properties file")
> +    boolean persistent;
> +
> +    @Argument(index = 0, name = "key", description = "The system property name")
> +    String key;
> +
> +    @Argument(index = 1, name = "value", required = false, description = "New value
for the system property")
> +    String value;
> +
> +    @Override
> +    protected Object doExecute() throws Exception {
> +        if (value != null) {
> +            if (persistent) {
> +                String base = System.getProperty("karaf.base");
> +                Properties props = new Properties(new File(base, "etc/system.properties"));
> +                props.put(key, value);
> +                props.save();
> +            }
> +            return System.setProperty(key, value);
> +        } else {
> +            return System.getProperty(key);
> +        }
> +    }
> +}
>
>
Is it really safe to allow a running Karaf instance to dynamically alter 
its own configuration files?  (Instead of having manual configuration of 
the files prior to starting the container)?  What would be the mechanism 
for Karaf to re-load these changed values from the updated file into its 
memory?

Glen

-- 
Glen Mazza
Talend - http://www.talend.com/products/tsf
blog: http://www.jroller.com/gmazza
Twitter: glenmazza


Mime
View raw message