Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-06-17 09:37:20 +0000
committerEike Stepper2008-06-17 09:37:20 +0000
commite6666a79afd30c4b3615d13579a8332cb5fd7912 (patch)
treee7f349666f62ba8c74e24ae45b62f87cc59c8555 /plugins
parent76b0ccac8f6bcb28c3cc99afe43e88c282d1f1d1 (diff)
downloadcdo-e6666a79afd30c4b3615d13579a8332cb5fd7912.tar.gz
cdo-e6666a79afd30c4b3615d13579a8332cb5fd7912.tar.xz
cdo-e6666a79afd30c4b3615d13579a8332cb5fd7912.zip
[234041] Prepare graduation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=234041
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/ManualTCPExample.java112
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/StandaloneTCPExample.java (renamed from plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/bundle/Examples.java)21
3 files changed, 126 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
index 1c3d7ac1f3..90a855d075 100644
--- a/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.examples/META-INF/MANIFEST.MF
@@ -13,3 +13,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resoluti
org.eclipse.net4j.tcp;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.tests.model1;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.emf.cdo.internal.examples,
+ org.eclipse.emf.cdo.internal.examples.bundle
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/ManualTCPExample.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/ManualTCPExample.java
new file mode 100644
index 0000000000..f72f4fb574
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/ManualTCPExample.java
@@ -0,0 +1,112 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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.examples;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class ManualTCPExample
+{
+ @SuppressWarnings("restriction")
+ public static void main(String[] args)
+ {
+ // Enable logging and tracing
+ OMPlatform.INSTANCE.setDebugging(true);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+
+ // Prepare receiveExecutor
+ final ThreadGroup threadGroup = new ThreadGroup("net4j");
+ ExecutorService receiveExecutor = Executors.newCachedThreadPool(new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ Thread thread = new Thread(threadGroup, r);
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
+
+ // Prepare bufferProvider
+ IBufferProvider bufferProvider = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferProvider);
+
+ // Prepare protocolFactoryRegistry
+ IFactory protocolFactory = new org.eclipse.emf.internal.cdo.protocol.CDOClientProtocolFactory();
+ IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry = new HashMapRegistry<IFactoryKey, IFactory>();
+ protocolFactoryRegistry.put(protocolFactory.getKey(), protocolFactory);
+ LifecycleUtil.activate(protocolFactoryRegistry);
+
+ // Prepare selector
+ org.eclipse.net4j.internal.tcp.TCPSelector selector = new org.eclipse.net4j.internal.tcp.TCPSelector();
+ selector.activate();
+
+ // Prepare connector
+ org.eclipse.net4j.internal.tcp.TCPClientConnector connector = new org.eclipse.net4j.internal.tcp.TCPClientConnector();
+ connector.setReceiveExecutor(receiveExecutor);
+ connector.setBufferProvider(bufferProvider);
+ connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
+ connector.setSelector(selector);
+ connector.setNegotiator(null);
+ connector.setHost("localhost");
+ connector.setPort(2036);
+ connector.activate();
+
+ // Create configuration
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(connector);
+ configuration.setRepositoryName("repo1");
+
+ // Open session
+ CDOSession session = configuration.openSession();
+ session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+
+ // Open transaction
+ CDOTransaction transaction = session.openTransaction();
+
+ // Get or create resource
+ CDOResource resource = transaction.getOrCreateResource("/path/to/my/resource");
+
+ // Work with the resource and commit the transaction
+ EObject object = Model1Factory.eINSTANCE.createCompany();
+ resource.getContents().add(object);
+ transaction.commit();
+
+ // Cleanup
+ session.close();
+ connector.deactivate();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/bundle/Examples.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/StandaloneTCPExample.java
index 5f9dde43eb..594e329ea3 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/bundle/Examples.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/internal/examples/StandaloneTCPExample.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.emf.cdo.internal.examples.bundle;
+package org.eclipse.emf.cdo.internal.examples;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOSessionConfiguration;
@@ -18,18 +18,26 @@ import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Model1Package;
import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.emf.ecore.EObject;
/**
* @author Eike Stepper
*/
-public class Examples
+public class StandaloneTCPExample
{
- public static void commonPattern()
+ public static void main(String[] args)
{
- IConnector connector = getConnector();
+ IManagedContainer container = ContainerUtil.createContainer();
+ Net4jUtil.prepareContainer(container); // Register Net4j factories
+ TCPUtil.prepareContainer(container); // Register TCP factories
+ CDOUtil.prepareContainer(container, false); // Register CDO factories
+ IConnector connector = TCPUtil.getConnector(container, "localhost:2036");
CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
configuration.setConnector(connector);
@@ -47,9 +55,4 @@ public class Examples
transaction.commit();
session.close();
}
-
- private static IConnector getConnector()
- {
- throw new UnsupportedOperationException();
- }
}

Back to the top