diff options
author | slewis | 2009-10-19 21:15:36 +0000 |
---|---|---|
committer | slewis | 2009-10-19 21:15:36 +0000 |
commit | 97faa2f043224fc75277e14a08b419ce415e37fd (patch) | |
tree | c76d3c6eea37df530ac44dd3353c4e13b559fc10 /examples/bundles/org.eclipse.ecf.examples.loadbalancing.server | |
parent | e01daed4d5c9caeec253120a60ce3de053b31a4b (diff) | |
download | org.eclipse.ecf-97faa2f043224fc75277e14a08b419ce415e37fd.tar.gz org.eclipse.ecf-97faa2f043224fc75277e14a08b419ce415e37fd.tar.xz org.eclipse.ecf-97faa2f043224fc75277e14a08b419ce415e37fd.zip |
Initial checkin of example loadbalancing app
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.examples.loadbalancing.server')
13 files changed, 398 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.classpath b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.classpath new file mode 100644 index 000000000..64c5e31b7 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.project b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.project new file mode 100644 index 000000000..79bf32693 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.examples.loadbalancing.server</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.jdt.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..762a0ce65 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Oct 19 09:00:48 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.pde.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..b054028f3 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Mon Oct 19 09:24:37 PDT 2009 +eclipse.preferences.version=1 +pluginProject.extensions=true +resolve.requirebundle=false diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/META-INF/MANIFEST.MF new file mode 100644 index 000000000..782f18c6a --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.ecf.examples.loadbalancing.server;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.ecf.internal.examples.loadbalancing.server.Activator +Bundle-Vendor: %bundleProvider +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: org.eclipse.ecf.core, + org.eclipse.ecf.core.identity;version="3.0.0", + org.eclipse.ecf.examples.loadbalancing, + org.eclipse.ecf.remoteservice, + org.eclipse.equinox.app;version="1.0.0", + org.osgi.framework;version="1.3.0", + org.osgi.util.tracker;version="1.4.0" +Bundle-ActivationPolicy: lazy +Bundle-Localization: bundle +Export-Package: org.eclipse.ecf.internal.examples.loadbalancing.server;x-internal:=true +Require-Bundle: org.eclipse.equinox.common;bundle-version="3.5.1" diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/about.html b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/about.html new file mode 100644 index 000000000..4c79781a5 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 25, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/build.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/build.properties new file mode 100644 index 000000000..2bc669862 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/build.properties @@ -0,0 +1,11 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + bundle.properties,\ + bin/,\ + about.html,\ + plugin.xml +src.includes = bundle.properties,\ + about.html,\ + META-INF/ diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/bundle.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/bundle.properties new file mode 100644 index 000000000..1415b5dba --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/bundle.properties @@ -0,0 +1,12 @@ +################################################################################ +# Copyright (c) 2009 Composent, Inc. and others. +# 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: +# Composent, Inc. - initial API and implementation +################################################################################ +bundleName=ECF Load Balancing Example Server +bundleProvider=Eclipse.org - ECF
\ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/plugin.xml b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/plugin.xml new file mode 100644 index 000000000..052c281bb --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/plugin.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + id="DataProcessorServer" + point="org.eclipse.core.runtime.applications"> + <application + cardinality="singleton-global" + thread="main" + visible="true"> + <run + class="org.eclipse.ecf.internal.examples.loadbalancing.server.DataProcessorServerApplication"> + </run> + </application> + </extension> + +</plugin> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/products/Data Processor Server (activemq).product b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/products/Data Processor Server (activemq).product new file mode 100644 index 000000000..fcd73bc14 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/products/Data Processor Server (activemq).product @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product name="ECF Example Load Balancing Server" uid="org.eclipse.ecf.examples.loadbalancing.server" application="org.eclipse.ecf.examples.loadbalancing.server.DataProcessorServer" version="1.0.0" useFeatures="false" includeLaunchers="false"> + + <configIni use="default"> + </configIni> + + <launcherArgs> + <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac> + </launcherArgs> + + <plugins> + <plugin id="org.eclipse.core.contenttype"/> + <plugin id="org.eclipse.core.jobs"/> + <plugin id="org.eclipse.core.runtime"/> + <plugin id="org.eclipse.core.runtime.compatibility.registry" fragment="true"/> + <plugin id="org.eclipse.ecf"/> + <plugin id="org.eclipse.ecf.datashare"/> + <plugin id="org.eclipse.ecf.discovery"/> + <plugin id="org.eclipse.ecf.examples.loadbalancing"/> + <plugin id="org.eclipse.ecf.examples.loadbalancing.server"/> + <plugin id="org.eclipse.ecf.identity"/> + <plugin id="org.eclipse.ecf.provider"/> + <plugin id="org.eclipse.ecf.provider.datashare"/> + <plugin id="org.eclipse.ecf.provider.jms"/> + <plugin id="org.eclipse.ecf.provider.jms.activemq"/> + <plugin id="org.eclipse.ecf.provider.remoteservice"/> + <plugin id="org.eclipse.ecf.remoteservice"/> + <plugin id="org.eclipse.ecf.sharedobject"/> + <plugin id="org.eclipse.ecf.ssl" fragment="true"/> + <plugin id="org.eclipse.equinox.app"/> + <plugin id="org.eclipse.equinox.common"/> + <plugin id="org.eclipse.equinox.concurrent"/> + <plugin id="org.eclipse.equinox.preferences"/> + <plugin id="org.eclipse.equinox.registry"/> + <plugin id="org.eclipse.osgi"/> + <plugin id="org.eclipse.osgi.services"/> + </plugins> + + +</product> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/Activator.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/Activator.java new file mode 100644 index 000000000..af754b7ba --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/Activator.java @@ -0,0 +1,35 @@ +package org.eclipse.ecf.internal.examples.loadbalancing.server; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + /* + * (non-Javadoc) + * + * @see + * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext ctxt) throws Exception { + context = ctxt; + } + + /* + * (non-Javadoc) + * + * @see + * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + context = null; + } + + public static BundleContext getContext() { + return context; + } + +} diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorImpl.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorImpl.java new file mode 100644 index 000000000..e95f4c329 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorImpl.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource and others. 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.internal.examples.loadbalancing.server; + +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.examples.loadbalancing.IDataProcessor; + +public class DataProcessorImpl implements IDataProcessor { + + private ID containerID; + + public DataProcessorImpl(ID containerID) { + this.containerID = containerID; + } + + /** + * Entry point for IDataProcessor service implementation + */ + public String processData(String data) { + System.out.println("DataProcessorImpl(" + containerID.getName() + + ").processData data=" + data); + if (data == null) return null; + return reverseString(data); + } + + private String reverseString(String data) { + StringBuffer buf = new StringBuffer(data); + buf.reverse(); + return buf.toString(); + } + + public void stop() { + } + +} diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorServerApplication.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorServerApplication.java new file mode 100644 index 000000000..6acae3cf5 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.server/src/org/eclipse/ecf/internal/examples/loadbalancing/server/DataProcessorServerApplication.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource and others. 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.internal.examples.loadbalancing.server; + +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.IContainerManager; +import org.eclipse.ecf.examples.loadbalancing.IDataProcessor; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; +import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; + +public class DataProcessorServerApplication implements IApplication { + + private static final String LB_SERVER_CONTAINER_TYPE = "ecf.jms.activemq.tcp.lb.server"; + private static final String DEFAULT_QUEUE_ID = "tcp://localhost:61616/exampleQueue"; + + private BundleContext bundleContext; + private ServiceTracker containerManagerServiceTracker; + + // Queue that we will attach to as queue message consumer (receiver of + // actual remote method/invocation + // requests). Note that this queueId can be changed by using the -queueId + // launch parameter...e.g. + // -queueId tcp://localhost:61616/myQueueName + private String queueId = DEFAULT_QUEUE_ID; + + // Container instance that connects us with the ActiveMQ queue as a message + // consumer + private IContainer container; + // The IDataProcessor service implementation. This object receives the + // actual + // remote method calls, executes arbitrary code, and returns a result. + private DataProcessorImpl dataProcessorImpl; + // The remote service registration associated with the dataProcessorImpl + private IRemoteServiceRegistration dataProcessorRemoteServiceRegistration; + + public Object start(IApplicationContext appContext) throws Exception { + bundleContext = Activator.getContext(); + // Process Arguments...i.e. set queueId if specified + processArgs(appContext); + + // Create container and connect to given queueId as message consumer + container = getContainerManagerService().getContainerFactory() + .createContainer(LB_SERVER_CONTAINER_TYPE, + new Object[] { queueId }); + + // Get remote service container adapter + IRemoteServiceContainerAdapter remoteServiceContainerAdapter = (IRemoteServiceContainerAdapter) container + .getAdapter(IRemoteServiceContainerAdapter.class); + + // Create the data processor implementation + dataProcessorImpl = new DataProcessorImpl(container.getID()); + + // Register data processor as remote services (with queue consumer + // container) + dataProcessorRemoteServiceRegistration = remoteServiceContainerAdapter + .registerRemoteService(new String[] { IDataProcessor.class + .getName() }, dataProcessorImpl, null); + + // Report success of registration + System.out + .println("Registered data processor. Remote service registration=" + + dataProcessorRemoteServiceRegistration); + + // then just wait for service requests + waitForDone(); + return IApplication.EXIT_OK; + } + + public void stop() { + if (dataProcessorRemoteServiceRegistration != null) { + dataProcessorRemoteServiceRegistration.unregister(); + dataProcessorRemoteServiceRegistration = null; + } + if (dataProcessorImpl != null) { + dataProcessorImpl.stop(); + dataProcessorImpl = null; + } + if (container != null) { + container.dispose(); + container = null; + getContainerManagerService().removeAllContainers(); + } + if (containerManagerServiceTracker != null) { + containerManagerServiceTracker.close(); + containerManagerServiceTracker = null; + } + bundleContext = null; + } + + private void processArgs(IApplicationContext appContext) { + String[] originalArgs = (String[]) appContext.getArguments().get( + "application.args"); + if (originalArgs == null) + return; + for (int i = 0; i < originalArgs.length; i++) { + if (originalArgs[i].equals("-queueId")) { + queueId = originalArgs[i + 1]; + i++; + } + } + } + + private IContainerManager getContainerManagerService() { + if (containerManagerServiceTracker == null) { + containerManagerServiceTracker = new ServiceTracker(bundleContext, + IContainerManager.class.getName(), null); + containerManagerServiceTracker.open(); + } + return (IContainerManager) containerManagerServiceTracker.getService(); + } + + private final Object appLock = new Object(); + private boolean done = false; + + private void waitForDone() { + // then just wait here + synchronized (appLock) { + while (!done) { + try { + appLock.wait(); + } catch (InterruptedException e) { + // do nothing + } + } + } + } + +} |