diff options
author | slewis | 2009-10-19 21:16:46 +0000 |
---|---|---|
committer | slewis | 2009-10-19 21:16:46 +0000 |
commit | 7c8e7b86121f28ea076534da841f07bdf6453287 (patch) | |
tree | 0b88145598938bacb86089baa0ec2754ed7f2701 /examples/bundles | |
parent | 97faa2f043224fc75277e14a08b419ce415e37fd (diff) | |
download | org.eclipse.ecf-7c8e7b86121f28ea076534da841f07bdf6453287.tar.gz org.eclipse.ecf-7c8e7b86121f28ea076534da841f07bdf6453287.tar.xz org.eclipse.ecf-7c8e7b86121f28ea076534da841f07bdf6453287.zip |
Initial checkin of example loadbalancing app
Diffstat (limited to 'examples/bundles')
12 files changed, 374 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.classpath b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.classpath new file mode 100644 index 000000000..64c5e31b7 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.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.servicehost/.project b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.project new file mode 100644 index 000000000..bf577ae43 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.examples.loadbalancing.servicehost</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.servicehost/.settings/org.eclipse.jdt.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..89fb0efd3 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Oct 19 11:04:06 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.servicehost/.settings/org.eclipse.pde.core.prefs b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..4dfff9304 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Mon Oct 19 11:18:36 PDT 2009 +eclipse.preferences.version=1 +pluginProject.extensions=true +resolve.requirebundle=false diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1d0ae9e0f --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.ecf.examples.loadbalancing.servicehost;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.ecf.internal.examples.loadbalancing.servicehost.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 +Export-Package: org.eclipse.ecf.internal.examples.loadbalancing.servicehost;x-internal:=true +Require-Bundle: org.eclipse.equinox.common;bundle-version="3.5.1" + diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/about.html b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/about.html new file mode 100644 index 000000000..4c79781a5 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/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.servicehost/build.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/build.properties new file mode 100644 index 000000000..e25268790 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/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.servicehost/bundle.properties b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/bundle.properties new file mode 100644 index 000000000..1c350eebf --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/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 Service Host +bundleProvider=Eclipse.org - ECF
\ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/plugin.xml b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/plugin.xml new file mode 100644 index 000000000..6f45b894a --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/plugin.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + id="DataProcessorServiceHost" + point="org.eclipse.core.runtime.applications"> + <application + cardinality="singleton-global" + thread="main" + visible="true"> + <run + class="org.eclipse.ecf.internal.examples.loadbalancing.servicehost.DataProcessorServiceHostApplication"> + </run> + </application> + </extension> + +</plugin> diff --git a/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/products/Data Processor Service Host (activemq).product b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/products/Data Processor Service Host (activemq).product new file mode 100644 index 000000000..7eabfdb0a --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/products/Data Processor Service Host (activemq).product @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product name="ECF Example Load Balancing Service Host" uid="org.eclipse.ecf.examples.loadbalancing.servicehost" application="org.eclipse.ecf.examples.loadbalancing.servicehost.DataProcessorServiceHost" 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.servicehost"/> + <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.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/Activator.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/Activator.java new file mode 100644 index 000000000..4bf9c4d60 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/Activator.java @@ -0,0 +1,34 @@ +package org.eclipse.ecf.internal.examples.loadbalancing.servicehost; + +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.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/DataProcessorServiceHostApplication.java b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/DataProcessorServiceHostApplication.java new file mode 100644 index 000000000..10a037238 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.loadbalancing.servicehost/src/org/eclipse/ecf/internal/examples/loadbalancing/servicehost/DataProcessorServiceHostApplication.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * 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.servicehost; + +import java.util.Properties; + +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 DataProcessorServiceHostApplication implements IApplication { + + private static final String LB_SVCHOST_CONTAINER_TYPE = "ecf.jms.activemq.tcp.manager.lb.svchost"; + public static final String DEFAULT_QUEUE_ID = "tcp://localhost:61616/exampleQueue"; + private static final String DEFAULT_TOPIC_ID = "tcp://localhost:61616/exampleTopic"; + private static final String LOAD_BALANCING_SERVICE_PROPERTY = "jms.queue.loadbalance"; + + private BundleContext bundleContext; + private ServiceTracker containerManagerServiceTracker; + + // JMS Queue URI that we will attach to as queue message producer (to issue + // actual remote method/invocation + // requests to server consumers). Note that this queueId can be changed by + // using the -queueId launch parameter...e.g.: + // -queueId tcp://myjmdnsbrokerdnsname:61616/myQueueName + private String queueId = DEFAULT_QUEUE_ID; + // JMS topic URI that we will register remote service registrations on... + // so that service consumers can lookup/get/use remote services. Note that + // this + // topicId can be changed by using the -topicId launch parameter...e.g. + // -topicId tcp://myjmdnsbrokerdnsname:61616/myTopicName + private String topicId = DEFAULT_TOPIC_ID; + + // Container instance that connects us with the ActiveMQ queue as a message + // producer and publishes the service on the topicId + private IContainer container; + // The service host remote service registration. This is used simply to + // unregister the service when this application is stopped + private IRemoteServiceRegistration dataProcessorServiceHostRegistration; + + public Object start(IApplicationContext appContext) throws Exception { + bundleContext = Activator.getContext(); + // Process Arguments...i.e. set queueId and topicId if specified + processArgs(appContext); + + // Create container of appropriate type, and with the topicId and + // queueId set + // upon construction + container = getContainerManagerService().getContainerFactory() + .createContainer(LB_SVCHOST_CONTAINER_TYPE, + new Object[] { topicId, queueId }); + + // Get IRemoteServiceContainerAdapter + IRemoteServiceContainerAdapter remoteServiceAdapter = (IRemoteServiceContainerAdapter) container + .getAdapter(IRemoteServiceContainerAdapter.class); + + Properties properties = new Properties(); + // This is setting (currently) magical service property that indicates + // that + // this service registration is a load balancing service host + properties.put(LOAD_BALANCING_SERVICE_PROPERTY, "true"); + // Register the remote service with the IDataProcessor interface as it's + // service registration. + // Note that the LOAD_BALANCING_SERVICE_PROPERTY allows a new Object to + // be specified as the implementation. + // This object does not implement the IDataProcessor service interface, + // but it is not actually used. Rather, + // the LOAD_BALANCING_SERVICE_PROPERTY set to "true" specifies that for + // this container the remote service + // requests are proxied and forwarded to the JMS queue (where they are + // load balanced among the n servers + // that are consumers from that queue) + dataProcessorServiceHostRegistration = remoteServiceAdapter + .registerRemoteService(new String[] { IDataProcessor.class + .getName() }, new Object(), properties); + + System.out.println("Registered service host with registration=" + + dataProcessorServiceHostRegistration); + + // wait for remote service requests until stopped + waitForDone(); + + return IApplication.EXIT_OK; + } + + public void stop() { + if (dataProcessorServiceHostRegistration != null) { + dataProcessorServiceHostRegistration.unregister(); + dataProcessorServiceHostRegistration = 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++; + } else if (originalArgs[i].equals("-topicId")) { + topicId = 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 + } + } + } + } + +} |