You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by David Blevins <da...@visi.com> on 2006/10/09 01:18:17 UTC
Re: svn commit: r454210 - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/util/ server/openejb-server/src/main/java/org/apache/openejb/server/ server/openejb-server/src/main/resources/META-INF/
Actually, everything that's using System.getProperty or
System.getProperties should be instead using SystemInstance.get
().getProperty/getProperties
Perhaps I didn't describe the intention of it clearly, but it's
basically mean to be exactly how you describe PropertiesService --
i.e. the one and only place where properties are retrieved.
I swear at one point in February I yanked all usage of
System.getProperties for systemInstance.getProperties(), but it
doesn't look like it made it into svn :( I recall it being a big
issue for the tomcat "one openejb per webapp" scenario where usage of
System.getProperties was a real problem.
-David
On Oct 8, 2006, at 2:08 PM, jlaskowski@apache.org wrote:
> Author: jlaskowski
> Date: Sun Oct 8 14:08:14 2006
> New Revision: 454210
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=454210
> Log:
> More XBean-isation - add PropertiesService that will keep track of
> (un)setting properties
>
> Added:
> incubator/openejb/trunk/openejb3/container/openejb-core/src/
> main/java/org/apache/openejb/util/PropertiesService.java (with
> props)
> Modified:
> incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Main.java
> incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Server.java
> incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> resources/META-INF/openejb-server.xml (contents, props changed)
>
> Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/
> main/java/org/apache/openejb/util/PropertiesService.java
> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/
> container/openejb-core/src/main/java/org/apache/openejb/util/
> PropertiesService.java?view=auto&rev=454210
> ======================================================================
> ========
> --- incubator/openejb/trunk/openejb3/container/openejb-core/src/
> main/java/org/apache/openejb/util/PropertiesService.java (added)
> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/
> main/java/org/apache/openejb/util/PropertiesService.java Sun Oct 8
> 14:08:14 2006
> @@ -0,0 +1,119 @@
> +/**
> + * 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.openejb.util;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import java.util.Properties;
> +
> +/**
> + * Manages properties so any property modifications are handled here.
> + *
> + * It lets us track the properties used and possibly remove some.
> They are all
> + * scattered in many places and it's so hard to keep track of them.
> + *
> + * The class holds all OpenEJB properties and optionally can amend
> the
> + * environment.
> + *
> + * The aim of this class is to establish one place to keep the
> properties and
> + * eventually remove the need to set System properties to
> communicate between
> + * parts and possibly yet lay out a foundation for setting them up
> in JNDI or
> + * some other means
> + *
> + * TODO: Should this class be concerned with concurrency issues?
> + *
> + * @org.apache.xbean.XBean element="propertiesService"
> + *
> + * @version $Rev$ $Date$
> + */
> +public class PropertiesService {
> + private Properties props = new Properties();
> +
> + /**
> + * Should properties be passed on to the environment?
> + */
> + private boolean passOn = true;
> +
> + /**
> + * Should the service query environment properties upon
> initialization?
> + */
> + private boolean queryEnvOnInit = true;
> +
> + public PropertiesService() {
> + if (queryEnvOnInit) {
> + props.putAll(System.getProperties());
> + }
> + }
> +
> + /**
> + * Set value to a property. Optionally set System property via
> + * {@link System#setProperty(String, String)}
> + *
> + * @param name
> + * property name
> + * @param value
> + * property value
> + * @return previous property value or null if the value hasn't
> been assigned
> + * yet
> + */
> + public String setProperty(String name, String value) {
> + if (passOn) {
> + System.setProperty(name, value);
> + }
> + return (String) props.setProperty(name, value);
> + }
> +
> + public String getProperty(String name) {
> + return (String) props.get(name);
> + }
> +
> + /**
> + * ISSUE: It might be of help to differentiate between
> unavailable property
> + * and boolean property set to false
> + *
> + * @param name
> + * property name
> + * @return true if property keyed by name is set; false otherwise
> + */
> + public boolean isSet(String name) {
> + return props.containsKey(name);
> + }
> +
> + public void putAll(Properties props) {
> + props.putAll(props);
> + }
> +
> + public Properties getProperties() {
> + return props;
> + }
> +
> + public boolean isPassOn() {
> + return passOn;
> + }
> +
> + public void setPassOn(boolean passOn) {
> + this.passOn = passOn;
> + }
> +
> + public boolean isQueryEnvOnInit() {
> + return queryEnvOnInit;
> + }
> +
> + public void setQueryEnvOnInit(boolean queryEnvOnInit) {
> + this.queryEnvOnInit = queryEnvOnInit;
> + }
> +}
>
> Propchange: incubator/openejb/trunk/openejb3/container/openejb-core/
> src/main/java/org/apache/openejb/util/PropertiesService.java
> ----------------------------------------------------------------------
> --------
> svn:executable = *
>
> Propchange: incubator/openejb/trunk/openejb3/container/openejb-core/
> src/main/java/org/apache/openejb/util/PropertiesService.java
> ----------------------------------------------------------------------
> --------
> svn:keywords = Date Rev Author Id Revision HeadURL
>
> Modified: incubator/openejb/trunk/openejb3/server/openejb-server/
> src/main/java/org/apache/openejb/server/Main.java
> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/
> server/openejb-server/src/main/java/org/apache/openejb/server/
> Main.java?view=diff&rev=454210&r1=454209&r2=454210
> ======================================================================
> ========
> --- incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Main.java (original)
> +++ incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Main.java Sun Oct 8 14:08:14 2006
> @@ -23,28 +23,41 @@
>
> import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.util.JarUtils;
> +import org.apache.openejb.util.PropertiesService;
> import
> org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
> import org.apache.xbean.spring.context.SpringApplicationContext;
> -import org.apache.xbean.spring.context.v2.XBeanXmlBeanFactory;
> -import
> org.springframework.context.support.AbstractXmlApplicationContext;
> -import org.springframework.core.io.ClassPathResource;
>
> /**
> - * Assemble OpenEJB instance and boot it up
> + * Assemble OpenEJB instance and boot it up
> */
> public class Main {
>
> private static final String helpBase = "META-INF/
> org.apache.openejb.cli/";
>
> + // TODO: Remove the static initializer once Main is fully
> XBean-ized
> + private static final SpringApplicationContext factory;
> + static {
> + factory = new ClassPathXmlApplicationContext("META-INF/
> openejb-server.xml");
> + }
> +
> public static void main(String args[]) {
>
> try {
> + PropertiesService propertiesService =
> (PropertiesService) factory.getBean("propertiesService");
> Properties props = parseArguments(args);
> - SystemInstance.init(props);
> + // FIXME: Remove parseArguments and let
> propertiesService take care of properties mgmt
> + propertiesService.putAll(props);
> +
> + // FIXME: Enable XBean-ized SystemInstance
> + //SystemInstance system = (SystemInstance)
> factory.getBean("system");
> +
> + SystemInstance.init(propertiesService.getProperties());
> SystemInstance system = SystemInstance.get();
> File libs = system.getHome().getDirectory("lib");
> system.getClassPath().addJarsToPath(libs);
> - initServer(props);
> +
> + Server server = (Server) factory.getBean("server");
> + server.start();
> } catch (DontStartServerException e) {
>
> } catch (Exception e) {
> @@ -53,11 +66,15 @@
> }
>
> /**
> - * Parse arguments and override any {@link System} properties
> returned via {@link System#getProperties()}.
> - *
> - * @param args command line arguments
> + * Parse arguments and override any {@link System} properties
> returned via
> + * {@link System#getProperties()}.
> + *
> + * @param args
> + * command line arguments
> * @return properties as defined in System and on the command
> line
> - * @throws DontStartServerException thrown as an indication to
> not boot up OpenEJB instance, e.g. after printing out properties,
> help, etc.
> + * @throws DontStartServerException
> + * thrown as an indication to not boot up OpenEJB
> instance, e.g.
> + * after printing out properties, help, etc.
> */
> private static Properties parseArguments(String args[]) throws
> DontStartServerException {
> Properties props = new Properties();
> @@ -99,10 +116,8 @@
> props.setProperty("openejb.server.admin-ip",
> args[++i]);
> }
> } else if (args[i].startsWith("--local-copy")) {
> - if (args[i].endsWith("false") ||
> - args[i].endsWith("FALSE") ||
> - args[i].endsWith("no") ||
> - args[i].endsWith("NO")) {
> + if (args[i].endsWith("false") || args[i].endsWith
> ("FALSE") || args[i].endsWith("no")
> + || args[i].endsWith("NO")) {
> props.setProperty("openejb.localcopy", "false");
> } else {
> props.setProperty("openejb.localcopy", "true");
> @@ -133,9 +148,9 @@
> try {
> JarUtils.setHandlerSystemProperty();
> versionInfo.load(new URL("resource:/openejb-
> version.properties").openConnection().getInputStream());
> - } catch (java.io.IOException e) {
> - }
> - System.out.println("OpenEJB Remote Server " +
> versionInfo.get("version") + " build: " + versionInfo.get
> ("date") + "-" + versionInfo.get("time"));
> + } catch (java.io.IOException e) {}
> + System.out.println("OpenEJB Remote Server " +
> versionInfo.get("version") + " build: "
> + + versionInfo.get("date") + "-" + versionInfo.get
> ("time"));
> System.out.println("" + versionInfo.get("url"));
> }
>
> @@ -146,8 +161,7 @@
> Properties versionInfo = new Properties();
> versionInfo.load(new URL("resource:/openejb-
> version.properties").openConnection().getInputStream());
> header += versionInfo.get("version");
> - } catch (java.io.IOException e) {
> - }
> + } catch (java.io.IOException e) {}
>
> System.out.println(header);
>
> @@ -159,8 +173,7 @@
> System.out.write(b);
> b = in.read();
> }
> - } catch (java.io.IOException e) {
> - }
> + } catch (java.io.IOException e) {}
> }
>
> private static void printExamples() {
> @@ -170,8 +183,7 @@
> Properties versionInfo = new Properties();
> versionInfo.load(new URL("resource:/openejb-
> version.properties").openConnection().getInputStream());
> header += versionInfo.get("version");
> - } catch (java.io.IOException e) {
> - }
> + } catch (java.io.IOException e) {}
>
> System.out.println(header);
>
> @@ -183,22 +195,8 @@
> System.out.write(b);
> b = in.read();
> }
> - } catch (java.io.IOException e) {
> - }
> - }
> -
> - private static void initServer(Properties props) throws
> Exception {
> - //Server server = new Server();
> -// FIXME: XBeanXmlBeanFactory vs AbstractXmlApplicationContext
> -// XBeanXmlBeanFactory factory = new XBeanXmlBeanFactory
> (new ClassPathResource("META-INF/openejb-server.xml"));
> -// Server server = (Server) factory.getBean("server");
> - SpringApplicationContext factory = new
> ClassPathXmlApplicationContext("META-INF/openejb-server.xml");
> - Server server = (Server) factory.getBean("server");
> - server.init(props);
> - server.start();
> + } catch (java.io.IOException e) {}
> }
> }
>
> -class DontStartServerException extends Exception {
> -}
> -
> +class DontStartServerException extends Exception {}
>
> Modified: incubator/openejb/trunk/openejb3/server/openejb-server/
> src/main/java/org/apache/openejb/server/Server.java
> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/
> server/openejb-server/src/main/java/org/apache/openejb/server/
> Server.java?view=diff&rev=454210&r1=454209&r2=454210
> ======================================================================
> ========
> --- incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Server.java (original)
> +++ incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> java/org/apache/openejb/server/Server.java Sun Oct 8 14:08:14 2006
> @@ -23,6 +23,7 @@
> import org.apache.openejb.OpenEJB;
> import org.apache.openejb.util.Logger;
> import org.apache.openejb.util.Messages;
> +import org.apache.openejb.util.PropertiesService;
> import org.apache.openejb.util.SafeToolkit;
>
> /**
> @@ -37,7 +38,10 @@
> private Messages _messages = new Messages
> ("org.apache.openejb.server");
> private Logger logger = Logger.getInstance
> ("OpenEJB.server.remote", "org.apache.openejb.server");
>
> + // FIXME: Remove it completely once we ensure
> PropertiesService (below) works well
> Properties props;
> +
> + private PropertiesService propertiesService;
>
> static Server server;
> private ServiceManager manager;
> @@ -50,19 +54,32 @@
> return server;
> }
>
> + // TODO: Remove it once init() suits our (initialisation) needs
> public void init(java.util.Properties props) throws Exception {
> this.props = props;
>
> - OpenEJB.init(props, new ServerFederation());
> + OpenEJB.init(propertiesService.getProperties(), new
> ServerFederation());
>
> if (System.getProperty("openejb.nobanner") == null) {
> System.out.println("[init] OpenEJB Remote Server");
> }
>
> - // it's injected by XBean
> - // @see openejb-server.xml
> - // FIXME: Remove it once we're certain it works well
> (which should be in a couple of commits)
> - //manager = ServiceManager.getManager();
> + manager.init();
> + }
> +
> + /**
> + * Copy of {@link #init(Properties)} to XBean-ize it
> + *
> + * @throws Exception
> + */
> + public void init() throws Exception {
> +
> + OpenEJB.init(propertiesService.getProperties(), new
> ServerFederation());
> +
> + if (!propertiesService.isSet("openejb.nobanner")) {
> + System.out.println("[init] OpenEJB Remote Server");
> + }
> +
> manager.init();
> }
>
> @@ -88,6 +105,10 @@
>
> public void setServiceManager(ServiceManager serviceManager) {
> this.manager = serviceManager;
> + }
> +
> + public void setPropertiesService(PropertiesService
> propertiesService) {
> + this.propertiesService = propertiesService;
> }
> }
>
>
> Modified: incubator/openejb/trunk/openejb3/server/openejb-server/
> src/main/resources/META-INF/openejb-server.xml
> URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/
> server/openejb-server/src/main/resources/META-INF/openejb-
> server.xml?view=diff&rev=454210&r1=454209&r2=454210
> ======================================================================
> ========
> --- incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> resources/META-INF/openejb-server.xml (original)
> +++ incubator/openejb/trunk/openejb3/server/openejb-server/src/main/
> resources/META-INF/openejb-server.xml Sun Oct 8 14:08:14 2006
> @@ -1,5 +1,5 @@
> <!--
> -
> +
> 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.
> @@ -7,7 +7,7 @@
> (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
> + 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,
> @@ -19,9 +19,17 @@
>
> <!-- $Rev$ $Date$ -->
>
> -<beans xmlns:o="http://openejb.apache.org/schemas/server">
> - <o:server id="server">
> +<beans xmlns:s="http://openejb.apache.org/schemas/server"
> xmlns:c="http://openejb.apache.org/schemas/core"
> + xmlns:l="http://openejb.apache.org/schemas/loader">
> + <s:server id="server" init-method="init">
> <property name="serviceManager" ref="serviceManager" />
> - </o:server>
> + <property name="propertiesService" ref="propertiesService" />
> + </s:server>
> + <c:propertiesService id="propertiesService" />
> <bean id="serviceManager"
> class="org.apache.openejb.server.ServiceManager" factory-
> method="getManager" />
> + <!--
> + - FIXME: The only singleton class with lots of static code
> - really hard to get it XBean-ized properly
> + -
> + <l:system factory-method="get" init-method="init" />
> + -->
> </beans>
>
> Propchange: incubator/openejb/trunk/openejb3/server/openejb-server/
> src/main/resources/META-INF/openejb-server.xml
> ----------------------------------------------------------------------
> --------
> svn:keywords = Date Rev Author Id Revision HeadURL
>
>
Re: svn commit: r454210 - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/util/ server/openejb-server/src/main/java/org/apache/openejb/server/ server/openejb-server/src/main/resources/META-INF/
Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On 10/9/06, David Blevins <da...@visi.com> wrote:
> Actually, everything that's using System.getProperty or
> System.getProperties should be instead using SystemInstance.get
> ().getProperty/getProperties
>
> Perhaps I didn't describe the intention of it clearly, but it's
> basically mean to be exactly how you describe PropertiesService --
> i.e. the one and only place where properties are retrieved.
Let me then yank the PropertiesService and replace it with
SystemInstance. I had an enormous trouble getting my head around
SystemInstance and thus likely my misunderstanding of its use. Thanks
for pointing it out.
The less code to maintain the better.
Jacek
--
Jacek Laskowski
http://www.laskowski.net.pl