diff options
author | slewis | 2009-06-11 19:19:45 +0000 |
---|---|---|
committer | slewis | 2009-06-11 19:19:45 +0000 |
commit | 5951e2c58b4ab8deb5a3e1b0cbbe9e3a30094dd6 (patch) | |
tree | d8953743e20c32c3969158fae2b1f00a16e06a24 /examples/bundles/org.eclipse.ecf.examples.eventadmin.app | |
parent | bbcff0df70d935fb2e9a2eee3c663f947446f65a (diff) | |
download | org.eclipse.ecf-5951e2c58b4ab8deb5a3e1b0cbbe9e3a30094dd6.tar.gz org.eclipse.ecf-5951e2c58b4ab8deb5a3e1b0cbbe9e3a30094dd6.tar.xz org.eclipse.ecf-5951e2c58b4ab8deb5a3e1b0cbbe9e3a30094dd6.zip |
Cleaned up AbstractEventAdminApplication and subclasses. Added ActiveMQ and Generic client/server products
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.examples.eventadmin.app')
7 files changed, 246 insertions, 53 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Client.product b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin ActiveMQ Client.product index 271feee2c..271feee2c 100644 --- a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Client.product +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin ActiveMQ Client.product diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Manager.product b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin ActiveMQ Server.product index 95d5c1ede..95d5c1ede 100644 --- a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Manager.product +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin ActiveMQ Server.product diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Client.product b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Client.product new file mode 100644 index 000000000..b2f6eb05a --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Client.product @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product name="EventAdmin Client" uid="org.eclipse.ecf.examples.eventadmin.app.client" application="org.eclipse.ecf.examples.eventadmin.app.EventAdminClient" version="1.0.0" useFeatures="false" includeLaunchers="true"> + + <configIni use="default"> + </configIni> + + <launcherArgs> + <programArgs>-containerType ecf.generic.client +-targetId ecftcp://localhost:3787/server</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.eventadmin"/> + <plugin id="org.eclipse.ecf.examples.eventadmin.app"/> + <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> + + <configurations> + <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" /> + <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" /> + </configurations> + +</product> diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Server.product b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Server.product new file mode 100644 index 000000000..de3872167 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Server.product @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product name="EventAdmin Manager" uid="org.eclipse.ecf.examples.eventadmin.app.manager" application="org.eclipse.ecf.examples.eventadmin.app.EventAdminManager" version="1.0.0" useFeatures="false" includeLaunchers="true"> + + <configIni use="default"> + </configIni> + + <launcherArgs> + <programArgs>-containerType ecf.generic.server +-containerId ecftcp://localhost:3787/server</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.eventadmin"/> + <plugin id="org.eclipse.ecf.examples.eventadmin.app"/> + <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.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> + + <configurations> + <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" /> + <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" /> + </configurations> + +</product> diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java index 3b758622f..08a73ee48 100644 --- a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java @@ -9,7 +9,8 @@ ******************************************************************************/ package org.eclipse.ecf.examples.internal.eventadmin.app; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; import org.eclipse.ecf.core.ContainerConnectException; @@ -31,12 +32,15 @@ import org.osgi.util.tracker.ServiceTracker; public abstract class AbstractEventAdminApplication implements IApplication { + public static final String DEFAULT_TOPIC = "defaultTopic"; + protected BundleContext bundleContext; + // The following must be set in processArgs protected String containerType; protected String containerId; protected String targetId; - protected String topic; + protected String topic = DEFAULT_TOPIC; protected ServiceTracker containerManagerTracker; private final Object appLock = new Object(); @@ -45,21 +49,77 @@ public abstract class AbstractEventAdminApplication implements IApplication { protected ServiceRegistration eventAdminRegistration; protected IContainer container; - public Object start(IApplicationContext context) throws Exception { + protected Object startup(IApplicationContext context) throws Exception { // Get BundleContext bundleContext = Activator.getContext(); + // Process Arguments - processArgs(context.getArguments()); + final String[] args = mungeArguments((String[]) context.getArguments() + .get("application.args")); //$NON-NLS-1$ + processArgs(args); + // Create event admin impl eventAdminImpl = new EventAdminImpl(bundleContext); + // Create, configure, and connect container createConfigureAndConnectContainer(); + // registerEventAdmin registerEventAdmin(); - return new Integer(0); + + return IApplication.EXIT_OK; + } + + protected void shutdown() { + if (eventAdminRegistration != null) { + eventAdminRegistration.unregister(); + eventAdminRegistration = null; + } + if (container != null) { + container.dispose(); + getContainerManager().removeAllContainers(); + container = null; + } + if (containerManagerTracker != null) { + containerManagerTracker.close(); + containerManagerTracker = null; + } + synchronized (appLock) { + done = true; + appLock.notifyAll(); + } + bundleContext = null; + } + + protected Object run() { + waitForDone(); + return IApplication.EXIT_OK; + } + + public Object start(IApplicationContext context) throws Exception { + Object startupResult = startup(context); + if (!startupResult.equals(IApplication.EXIT_OK)) return startupResult; + return run(); + } + + private String[] mungeArguments(String originalArgs[]) { + if (originalArgs == null) + return new String[0]; + final List l = new ArrayList(); + for (int i = 0; i < originalArgs.length; i++) + if (!originalArgs[i].equals("-pdelaunch")) //$NON-NLS-1$ + l.add(originalArgs[i]); + return (String[]) l.toArray(new String[] {}); } - protected abstract void processArgs(Map args); + protected void usage() { + System.out.println("Usage: eclipse.exe -application "+usageApplicationId()+" "+usageParameters()); + } + + protected abstract String usageApplicationId(); + protected abstract String usageParameters(); + + protected abstract void processArgs(String[] args); protected void registerEventAdmin() { // Create properties for event admin @@ -84,24 +144,7 @@ public abstract class AbstractEventAdminApplication implements IApplication { } public void stop() { - if (eventAdminRegistration != null) { - eventAdminRegistration.unregister(); - eventAdminRegistration = null; - } - if (container != null) { - container.dispose(); - getContainerManager().removeAllContainers(); - container = null; - } - if (containerManagerTracker != null) { - containerManagerTracker.close(); - containerManagerTracker = null; - } - synchronized (appLock) { - done = true; - appLock.notifyAll(); - } - bundleContext = null; + shutdown(); } protected void connectContainer(IContainer container, String target) diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java index 3b8fcf90c..0c711a2e9 100644 --- a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java @@ -9,9 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.examples.internal.eventadmin.app; -import java.util.Map; - -import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.equinox.app.IApplication; import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.EventHandler; @@ -24,10 +22,8 @@ public class EventAdminClientApplication extends AbstractEventAdminApplication { private TestSender testSender; private ServiceRegistration testEventHandlerRegistration; - public Object start(IApplicationContext context) throws Exception { - // Do setup in abstract super class - super.start(context); - + protected Object run() { + // XXX for testing, setup an event handler testEventHandlerRegistration = bundleContext.registerService( EventHandler.class.getName(), new TestEventHandler(), null); @@ -39,10 +35,10 @@ public class EventAdminClientApplication extends AbstractEventAdminApplication { // Now just wait until we're stopped waitForDone(); - return new Integer(0); + return IApplication.EXIT_OK; } - public void stop() { + protected void shutdown() { if (testSender != null) { testSender.stop(); testSender = null; @@ -51,14 +47,37 @@ public class EventAdminClientApplication extends AbstractEventAdminApplication { testEventHandlerRegistration.unregister(); testEventHandlerRegistration = null; } - super.stop(); + super.shutdown(); + } + + protected String usageApplicationId() { + return "org.eclipse.ecf.examples.eventadmin.app.EventAdminClient"; } - protected void processArgs(Map args) { + protected String usageParameters() { + StringBuffer buf = new StringBuffer("\n\t-containerType <default:"+DEFAULT_CONTAINER_TYPE+">"); + buf.append("\n\t-targetId <default:"+DEFAULT_CONTAINER_TARGET+">"); + buf.append("\n\t-topic <default:"+DEFAULT_TOPIC+">"); + return buf.toString(); + } + + protected void processArgs(String[] args) { containerType = DEFAULT_CONTAINER_TYPE; containerId = null; targetId = DEFAULT_CONTAINER_TARGET; topic = DEFAULT_TOPIC; - } + for (int i = 0; i < args.length; i++) { + if (args[i].equals("-containerType")) { + containerType = args[i + 1]; + i++; + } else if (args[i].equals("-targetId")) { + targetId = args[i + 1]; + i++; + } else if (args[i].equals("-topic")) { + topic = args[i + 1]; + i++; + } + } + } } diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java index de54c3aea..188dfcbb5 100644 --- a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java +++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java @@ -9,10 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.examples.internal.eventadmin.app; -import java.util.Map; - import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.EventHandler; @@ -21,30 +18,26 @@ public class EventAdminManagerApplication extends AbstractEventAdminApplication private static final String DEFAULT_CONTAINER_TYPE = "ecf.jms.activemq.tcp.manager"; public static final String DEFAULT_CONTAINER_ID = "tcp://localhost:61616/exampleTopic"; - public static final String DEFAULT_TOPIC = "defaultTopic"; private TestSender testSender; private ServiceRegistration testEventHandlerRegistration; - public Object start(IApplicationContext context) throws Exception { - // Do setup in abstract super class - super.start(context); - + protected Object run() { // XXX for testing, setup an event handler testEventHandlerRegistration = bundleContext.registerService( EventHandler.class.getName(), new TestEventHandler(), null); - + // XXX for testing, setup a test sender - testSender = new TestSender(eventAdminImpl, topic, container.getID().getName()); + testSender = new TestSender(eventAdminImpl, topic, container.getID() + .getName()); new Thread(testSender).start(); - - // Now just wait until we're stopped + waitForDone(); - return new Integer(0); + return IApplication.EXIT_OK; } - - public void stop() { + + protected void shutdown() { if (testSender != null) { testSender.stop(); testSender = null; @@ -53,14 +46,38 @@ public class EventAdminManagerApplication extends AbstractEventAdminApplication testEventHandlerRegistration.unregister(); testEventHandlerRegistration = null; } - super.stop(); + super.shutdown(); } - protected void processArgs(Map args) { + protected String usageApplicationId() { + return "org.eclipse.ecf.examples.eventadmin.app.EventAdminManager"; + } + + protected String usageParameters() { + StringBuffer buf = new StringBuffer("\n\t-containerType <default:"+DEFAULT_CONTAINER_TYPE+">"); + buf.append("\n\t-containerId <default:"+DEFAULT_CONTAINER_ID+">"); + buf.append("\n\t-topic <default:"+DEFAULT_TOPIC+">"); + return buf.toString(); + } + + protected void processArgs(String[] args) { containerType = DEFAULT_CONTAINER_TYPE; containerId = DEFAULT_CONTAINER_ID; targetId = null; topic = DEFAULT_TOPIC; + for (int i = 0; i < args.length; i++) { + if (args[i].equals("-containerType")) { + containerType = args[i + 1]; + i++; + } else if (args[i].equals("-containerId")) { + containerId = args[i + 1]; + i++; + } else if (args[i].equals("-topic")) { + topic = args[i + 1]; + i++; + } + } + } } |