diff options
author | slewis | 2009-10-19 21:14:43 +0000 |
---|---|---|
committer | slewis | 2009-10-19 21:14:43 +0000 |
commit | e01daed4d5c9caeec253120a60ce3de053b31a4b (patch) | |
tree | f878584fc4dc71c0108d8f4f102c7b6abb13b4fd /examples | |
parent | bf69d8d70efc74cacde6bfc4b1bee492572bdad7 (diff) | |
download | org.eclipse.ecf-e01daed4d5c9caeec253120a60ce3de053b31a4b.tar.gz org.eclipse.ecf-e01daed4d5c9caeec253120a60ce3de053b31a4b.tar.xz org.eclipse.ecf-e01daed4d5c9caeec253120a60ce3de053b31a4b.zip |
Initial checkin of example loadbalancing app
Diffstat (limited to 'examples')
12 files changed, 355 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.classpath b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.classpath new file mode 100644 index 000000000..64c5e31b7 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.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.consumer/.project b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.project new file mode 100644 index 000000000..85c505a2f --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.examples.loadbalancing.consumer</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.consumer/.settings/org.eclipse.jdt.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..67237f664 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Oct 19 12:13:39 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.consumer/.settings/org.eclipse.pde.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..3c2cd3f69 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Mon Oct 19 12:20:38 PDT 2009 +eclipse.preferences.version=1 +pluginProject.extensions=true +resolve.requirebundle=false diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/META-INF/MANIFEST.MF new file mode 100644 index 000000000..b9027d6c4 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.ecf.examples.loadbalancing.consumer;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.ecf.internal.examples.loadbalancing.consumer.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 +Bundle-ActivationPolicy: lazy +Bundle-Localization: bundle +Require-Bundle: org.eclipse.equinox.common;bundle-version="3.5.1" diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/about.html b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/about.html new file mode 100644 index 000000000..4c79781a5 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/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.consumer/build.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/build.properties new file mode 100644 index 000000000..e25268790 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/build.properties @@ -0,0 +1,11 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + bundle.properties,\ + about.html,\ + plugin.xml +src.includes = about.html,\ + META-INF/,\ + bundle.properties,\ + src/ diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/bundle.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/bundle.properties new file mode 100644 index 000000000..9bd642f81 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/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 Data Processing API +bundleProvider=Eclipse.org - ECF
\ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/plugin.xml b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/plugin.xml new file mode 100644 index 000000000..f03bb4d0c --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/plugin.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + id="DataProcessorConsumer" + point="org.eclipse.core.runtime.applications"> + <application + cardinality="singleton-global" + thread="main" + visible="true"> + <run + class="org.eclipse.ecf.internal.examples.loadbalancing.consumer.DataProcessorConsumerApplication"> + </run> + </application> + </extension> + +</plugin> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/products/Data Processor Consumer (activemq).product b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/products/Data Processor Consumer (activemq).product new file mode 100644 index 000000000..858ece0a3 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/products/Data Processor Consumer (activemq).product @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product name="ECF Load Balancing Example Consumer" uid="org.eclipse.ecf.examples.loadbalancing.consumer" application="org.eclipse.ecf.examples.loadbalancing.consumer.DataProcessorConsumer" version="1.0.0" useFeatures="false" includeLaunchers="true"> + + <configIni use="default"> + </configIni> + + <launcherArgs> + <programArgs>-inputData Are we not drawn onward, we few, drawn onward to new era</programArgs> + <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac> + </launcherArgs> + + <launcher> + <solaris/> + <win useIco="false"> + <bmp/> + </win> + </launcher> + + <vm> + </vm> + + <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.consumer"/> + <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.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/Activator.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/Activator.java new file mode 100644 index 000000000..028b658c6 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/Activator.java @@ -0,0 +1,35 @@ +package org.eclipse.ecf.internal.examples.loadbalancing.consumer; + +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.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/DataProcessorConsumerApplication.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/DataProcessorConsumerApplication.java new file mode 100644 index 000000000..d5cb014be --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.consumer/src/org/eclipse/ecf/internal/examples/loadbalancing/consumer/DataProcessorConsumerApplication.java @@ -0,0 +1,128 @@ +/******************************************************************************* +* 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.consumer; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.IContainerManager; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.examples.loadbalancing.IDataProcessor; +import org.eclipse.ecf.remoteservice.IRemoteService; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; +import org.eclipse.ecf.remoteservice.IRemoteServiceReference; +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 DataProcessorConsumerApplication implements IApplication { + + private static final String LB_SVCCONSUMER_CONTAINER_TYPE = "ecf.jms.activemq.tcp.client"; + private static final String DEFAULT_TARGET_ID = "tcp://localhost:61616/exampleTopic"; + private static final String DEFAULT_INPUT_DATA = "hello there"; + + private BundleContext bundleContext; + private ServiceTracker containerManagerServiceTracker; + + // JMS topic URI that we will connect to in order to lookup/get/use the + // data processor remote service. Note that this topicId can be + // changed by using the -topicId launch parameter...e.g. + // -topicId tcp://myjmdnsbrokerdnsname:61616/myTopicName + private String targetId = DEFAULT_TARGET_ID; + + // Container instance that connects us with the ActiveMQ queue as a message + // producer and publishes the service on the topicId + private IContainer container; + + // Input data that is passed to the data processor + private String inputData = DEFAULT_INPUT_DATA; + + public Object start(IApplicationContext appContext) throws Exception { + bundleContext = Activator.getContext(); + // Process Arguments...i.e. set queueId and topicId if specified + processArgs(appContext); + + // Create container + container = getContainerManagerService().getContainerFactory().createContainer(LB_SVCCONSUMER_CONTAINER_TYPE); + // Create targetID + ID targetID = IDFactory.getDefault().createID(container.getConnectNamespace(),targetId); + + // Get remoteServiceContainerAdapter + IRemoteServiceContainerAdapter remoteServiceAdapter = (IRemoteServiceContainerAdapter) container + .getAdapter(IRemoteServiceContainerAdapter.class); + + // We'll get the remote service references directly with a blocking call to getRemoteServiceReferences + // Note that we could also use non-blocking method: asyncGetRemoteServiceReferences OR we could us + // the org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker. For this case we'll just invoke it + // directly in caller thread. + IRemoteServiceReference [] dataProcessorRefs = remoteServiceAdapter.getRemoteServiceReferences(targetID, IDataProcessor.class.getName(), null); + // Get IRemoteService for first reference (must have at least one) + Assert.isNotNull(dataProcessorRefs); + Assert.isLegal(dataProcessorRefs.length > 0); + + // Get remote service associated with the first reference + IRemoteService remoteService = remoteServiceAdapter.getRemoteService(dataProcessorRefs[0]); + // At this point, the client can choose how to invoke the remote service...e.g. via IRemoteService.callAsync/1 or callSync/2 + // For this example consumer, we'll just get the proxy and invoke it in this thread + IDataProcessor dataProcessorProxy = (IDataProcessor) remoteService.getProxy(); + System.out.println("Calling remote service ref="+dataProcessorRefs[0]+"\n\tinput data="+inputData); + // And then simply call it + String result = dataProcessorProxy.processData(inputData); + // And print out results + System.out.println("\tresult="+result); + // And we're done + stop(); + return IApplication.EXIT_OK; + } + + public void stop() { + 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("-targetId")) { + targetId = originalArgs[i + 1]; + i++; + } else if (originalArgs[i].equals("-inputData")) { + StringBuffer buf = new StringBuffer(); + for(int j=i+1; j < originalArgs.length; j++) { + buf.append(originalArgs[j]).append(" "); + } + inputData = buf.toString(); + return; + } + } + } + + private IContainerManager getContainerManagerService() { + if (containerManagerServiceTracker == null) { + containerManagerServiceTracker = new ServiceTracker(bundleContext, + IContainerManager.class.getName(), null); + containerManagerServiceTracker.open(); + } + return (IContainerManager) containerManagerServiceTracker.getService(); + } + +} |