summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-27 10:20:13 (EDT)
committerEike Stepper2007-09-27 10:20:13 (EDT)
commitd5df78d996d208c08ab1664bea0e98dd5e2d5a93 (patch)
tree4dd87982066e493413552b74bfc10cc5f87cfab0
parent9bab05937283397c62984158d8ab8497f12b8821 (diff)
downloadcdo-d5df78d996d208c08ab1664bea0e98dd5e2d5a93.zip
cdo-d5df78d996d208c08ab1664bea0e98dd5e2d5a93.tar.gz
cdo-d5df78d996d208c08ab1664bea0e98dd5e2d5a93.tar.bz2
[204795] Provide Net4j Server initialization
https://bugs.eclipse.org/bugs/show_bug.cgi?id=204795
-rw-r--r--features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/cdo-server.xml2
-rw-r--r--features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/net4j-server.xml6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryConfiguratorNew.java197
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java131
7 files changed, 156 insertions, 221 deletions
diff --git a/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/cdo-server.xml b/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/cdo-server.xml
index af5e2bc..d8ecb24 100644
--- a/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/cdo-server.xml
+++ b/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/cdo-server.xml
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<cdoServer>
+ <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"/>
+
<repository name="repo1">
<property name="overrideUUID" value="1ff5d226-b1f0-40fb-aba2-0c31b38c764f"/>
<property name="supportingAudits" value="true"/>
diff --git a/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/net4j-server.xml b/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/net4j-server.xml
deleted file mode 100644
index d610cc1..0000000
--- a/features/org.eclipse.emf.cdo.server-feature/rootfiles/net4j-config/net4j-server.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<net4jServer>
-
- <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"/>
-
-</net4jServer>
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryConfiguratorNew.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryConfiguratorNew.java
deleted file mode 100644
index 504d3e9..0000000
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RepositoryConfiguratorNew.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreFactory;
-
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.om.OMPlatform;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class RepositoryConfiguratorNew implements IElementProcessor
-{
- private File configFile;
-
- private Document document;
-
- public RepositoryConfiguratorNew()
- {
- configFile = getConfigFile();
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof Repository)
- {
- element = process(container, factoryType, description, (Repository)element);
- }
-
- return element;
- }
-
- protected Repository process(IManagedContainer container, String factoryType, String name, Repository repository)
- {
- try
- {
- Element repositoryConfig = getRepositoryConfig(name);
- if (repositoryConfig != null)
- {
- Element storeConfig = getStoreConfig(repositoryConfig);
- IStore store = createStore(storeConfig);
- store.setRepository(repository);
-
- Map<String, String> properties = getProperties(repositoryConfig, 1);
- repository.setProperties(properties);
- }
- else
- {
- OM.LOG.warn("No configuration found for repository " + name);
- }
-
- return repository;
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- protected Element getRepositoryConfig(String name) throws ParserConfigurationException, SAXException, IOException
- {
- Document document = getDocument();
- NodeList elements = document.getElementsByTagName("repository");
- for (int i = 0; i < elements.getLength(); i++)
- {
- Element repositoryConfig = (Element)elements.item(i);
- String repositoryName = repositoryConfig.getAttribute("name");
- if (ObjectUtil.equals(repositoryName, name))
- {
- return repositoryConfig;
- }
- }
-
- return null;
- }
-
- protected File getConfigFile()
- {
- return OMPlatform.INSTANCE.getConfigFile("cdo.server.xml");
- }
-
- protected Document getDocument() throws ParserConfigurationException, SAXException, IOException
- {
- if (document == null)
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- document = builder.parse(configFile);
- }
-
- return document;
- }
-
- protected IStore createStore(Element storeConfig) throws CoreException
- {
- String type = storeConfig.getAttribute("type");
- IStoreFactory storeFactory = getStoreFactory(type);
- return storeFactory.createStore(storeConfig);
- }
-
- protected IStoreFactory getStoreFactory(String type) throws CoreException
- {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, "storeFactories");
- for (IConfigurationElement element : elements)
- {
- if (ObjectUtil.equals(element.getName(), "storeFactory"))
- {
- String storeType = element.getAttribute("storeType");
- if (ObjectUtil.equals(storeType, type))
- {
- return (IStoreFactory)element.createExecutableExtension("class");
- }
- }
- }
-
- throw new IllegalStateException("Store factory not found: " + type);
- }
-
- protected Element getStoreConfig(Element repositoryConfig)
- {
- NodeList storeConfigs = repositoryConfig.getElementsByTagName("store");
- if (storeConfigs.getLength() != 1)
- {
- String repositoryName = repositoryConfig.getAttribute("name");
- throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName);
- }
-
- return (Element)storeConfigs.item(0);
- }
-
- public static Map<String, String> getProperties(Element element, int levels)
- {
- Map<String, String> properties = new HashMap<String, String>();
- collectProperties(element, "", properties, levels);
- return properties;
- }
-
- private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
- {
- if ("property".equals(element.getNodeName()))
- {
- String name = element.getAttribute("name");
- String value = element.getAttribute("value");
- properties.put(prefix + name, value);
- prefix += name + ".";
- }
-
- if (levels > 0)
- {
- NodeList childNodes = element.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++)
- {
- Node childNode = childNodes.item(i);
- if (childNode instanceof Element)
- {
- collectProperties((Element)childNode, prefix, properties, levels - 1);
- }
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java
index 8f1de72..7c0b37d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java
@@ -11,15 +11,16 @@
package org.eclipse.emf.cdo.internal.server.bundle;
import org.eclipse.emf.cdo.internal.server.RepositoryConfigurator;
-import org.eclipse.emf.cdo.internal.server.RepositoryFactory;
import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.IAcceptor;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.OSGiApplication;
+import org.eclipse.internal.net4j.Net4jConfigurator;
+
import java.io.File;
/**
@@ -29,10 +30,10 @@ public class CDOServerApplication extends OSGiApplication
{
public static final String ID = OM.BUNDLE_ID + ".app";
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOServerApplication.class);
-
private IRepository[] repositories;
+ private IAcceptor[] acceptors;
+
public CDOServerApplication()
{
super(ID);
@@ -45,31 +46,35 @@ public class CDOServerApplication extends OSGiApplication
File configFile = OMPlatform.INSTANCE.getConfigFile("cdo-server.xml");
if (configFile != null && configFile.exists())
{
- if (TRACER.isEnabled()) TRACER.format("Configuring repositories from {0}", configFile.getAbsolutePath());
- RepositoryConfigurator configurator = new RepositoryConfigurator(IPluginContainer.INSTANCE);
- repositories = configurator.configure(configFile);
+ RepositoryConfigurator repositoryConfigurator = new RepositoryConfigurator(IPluginContainer.INSTANCE);
+ repositories = repositoryConfigurator.configure(configFile);
+
+ Net4jConfigurator net4jConfigurator = new Net4jConfigurator(IPluginContainer.INSTANCE);
+ acceptors = net4jConfigurator.configure(configFile);
}
else
{
- OM.LOG.warn("Repository config file not found: " + configFile.getAbsolutePath());
+ OM.LOG.warn("CDO server configuration not found: " + configFile.getAbsolutePath());
}
}
@Override
protected void doStop() throws Exception
{
- if (repositories != null)
+ if (acceptors != null)
{
- for (IRepository repository : repositories)
+ for (IAcceptor acceptor : acceptors)
{
- LifecycleUtil.deactivate(repository);
+ LifecycleUtil.deactivate(acceptor);
}
}
- Object[] elements = IPluginContainer.INSTANCE.getElements(RepositoryFactory.PRODUCT_GROUP);
- for (Object element : elements)
+ if (repositories != null)
{
- System.out.println("Container: " + element);
+ for (IRepository repository : repositories)
+ {
+ LifecycleUtil.deactivate(repository);
+ }
}
super.doStop();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java
index d421555..f92ef16 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java
@@ -43,10 +43,6 @@ public abstract class OM
public static final OMLogger LOG = BUNDLE.logger();
- // static void start() throws Exception
- // {
- // }
-
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
index 6cdedfb..5d2c35e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/OM.java
@@ -16,6 +16,7 @@ import org.eclipse.net4j.internal.util.om.log.EclipseLoggingBridge;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.log.OMLogger;
@@ -65,6 +66,7 @@ public abstract class OM
OM.BUNDLE.setBundleContext(context);
((OSGiBundle)OM.BUNDLE).start();
+ // TODO Make configurable
PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}");
AbstractPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
AbstractPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
@@ -78,6 +80,8 @@ public abstract class OM
}
traceStart(context);
+ IPluginContainer container = IPluginContainer.INSTANCE;
+ if (TRACER.isEnabled()) TRACER.format("Plugin container created: {0}", container);
}
public void stop(BundleContext context) throws Exception
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java
new file mode 100644
index 0000000..d35fe35
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java
@@ -0,0 +1,131 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.internal.net4j;
+
+import org.eclipse.net4j.IAcceptor;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class Net4jConfigurator
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, Net4jConfigurator.class);
+
+ private IManagedContainer container;
+
+ public Net4jConfigurator(IManagedContainer container)
+ {
+ this.container = container;
+ }
+
+ public IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ public IAcceptor[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException,
+ CoreException
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Configuring Net4j server from " + configFile.getAbsolutePath());
+ }
+
+ List<IAcceptor> acceptors = new ArrayList<IAcceptor>();
+ Document document = getDocument(configFile);
+ NodeList elements = document.getElementsByTagName("acceptor");
+ for (int i = 0; i < elements.getLength(); i++)
+ {
+ Element acceptorConfig = (Element)elements.item(i);
+ String type = acceptorConfig.getAttribute("type");
+ String listenAddr = acceptorConfig.getAttribute("listenAddr");
+ String port = acceptorConfig.getAttribute("port");
+ String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port);
+
+ IAcceptor acceptor = (IAcceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description);
+ acceptors.add(acceptor);
+ }
+
+ return acceptors.toArray(new IAcceptor[acceptors.size()]);
+ }
+
+ protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(configFile);
+ }
+
+ protected Element getStoreConfig(Element repositoryConfig)
+ {
+ NodeList storeConfigs = repositoryConfig.getElementsByTagName("store");
+ if (storeConfigs.getLength() != 1)
+ {
+ String repositoryName = repositoryConfig.getAttribute("name");
+ throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName);
+ }
+
+ return (Element)storeConfigs.item(0);
+ }
+
+ public static Map<String, String> getProperties(Element element, int levels)
+ {
+ Map<String, String> properties = new HashMap<String, String>();
+ collectProperties(element, "", properties, levels);
+ return properties;
+ }
+
+ private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
+ {
+ if ("property".equals(element.getNodeName()))
+ {
+ String name = element.getAttribute("name");
+ String value = element.getAttribute("value");
+ properties.put(prefix + name, value);
+ prefix += name + ".";
+ }
+
+ if (levels > 0)
+ {
+ NodeList childNodes = element.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ Node childNode = childNodes.item(i);
+ if (childNode instanceof Element)
+ {
+ collectProperties((Element)childNode, prefix, properties, levels - 1);
+ }
+ }
+ }
+ }
+} \ No newline at end of file