Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-10-12 19:39:23 +0000
committerslewis2009-10-12 19:39:23 +0000
commit7b6a2568e20e75f3d56d7f0e113ee95e53561543 (patch)
tree992810d08fd59a87aa8f3c09ec52938e5128c14f
parentb0fc7dc871d77b7f43158419eb8ca4860babeabb (diff)
downloadorg.eclipse.ecf-7b6a2568e20e75f3d56d7f0e113ee95e53561543.tar.gz
org.eclipse.ecf-7b6a2568e20e75f3d56d7f0e113ee95e53561543.tar.xz
org.eclipse.ecf-7b6a2568e20e75f3d56d7f0e113ee95e53561543.zip
Changed properties values, added examples to map and feature on Release_3_1 stream
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/bundle.properties12
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java174
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/Activator.java39
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java89
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java88
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestEventHandler.java24
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestSender.java60
7 files changed, 486 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/bundle.properties b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/bundle.properties
new file mode 100644
index 000000000..54295b580
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/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 RemoteServices Distributed EventAdmin Example Host
+bundleProvider=Eclipse.org - ECF \ No newline at end of file
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
new file mode 100644
index 000000000..7c9c3a0a4
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/AbstractEventAdminApplication.java
@@ -0,0 +1,174 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.ecf.core.ContainerConnectException;
+import org.eclipse.ecf.core.ContainerCreateException;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerFactory;
+import org.eclipse.ecf.core.IContainerManager;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.sharedobject.ISharedObjectContainer;
+import org.eclipse.ecf.core.sharedobject.SharedObjectAddException;
+import org.eclipse.ecf.remoteservice.eventadmin.DistributedEventAdmin;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventConstants;
+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 = DEFAULT_TOPIC;
+
+ protected ServiceTracker containerManagerTracker;
+ private final Object appLock = new Object();
+ private boolean done = false;
+ protected DistributedEventAdmin eventAdminImpl;
+ protected ServiceRegistration eventAdminRegistration;
+ protected IContainer container;
+
+ protected Object startup(IApplicationContext context) throws Exception {
+ // Get BundleContext
+ bundleContext = Activator.getContext();
+
+ // Process Arguments
+ final String[] args = mungeArguments((String[]) context.getArguments()
+ .get("application.args")); //$NON-NLS-1$
+ processArgs(args);
+
+ // Create event admin impl
+ eventAdminImpl = new DistributedEventAdmin(bundleContext);
+
+ // Create, configure, and connect container
+ createConfigureAndConnectContainer();
+
+ // start event admin
+ eventAdminImpl.start();
+ // register as EventAdmin service instance
+ Properties props = new Properties();
+ props.put(EventConstants.EVENT_TOPIC, topic);
+ eventAdminRegistration = bundleContext.registerService("org.osgi.service.event.EventAdmin", eventAdminImpl,props);
+
+ 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 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 waitForDone() {
+ // then just wait here
+ synchronized (appLock) {
+ while (!done) {
+ try {
+ appLock.wait();
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ }
+ }
+ }
+
+ public void stop() {
+ shutdown();
+ }
+
+ protected void createConfigureAndConnectContainer()
+ throws ContainerCreateException, SharedObjectAddException,
+ ContainerConnectException {
+ // get container factory and create container
+ IContainerFactory containerFactory = getContainerManager()
+ .getContainerFactory();
+ container = (containerId == null) ? containerFactory
+ .createContainer(containerType) : containerFactory
+ .createContainer(containerType, new Object[] { containerId });
+
+ // Get socontainer
+ ISharedObjectContainer soContainer = (ISharedObjectContainer) container.getAdapter(ISharedObjectContainer.class);
+ // Add to soContainer, with topic as name
+ soContainer.getSharedObjectManager().addSharedObject(IDFactory.getDefault().createStringID(topic), eventAdminImpl, null);
+
+ // then connect to target Id
+ if (targetId != null) container.connect(IDFactory.getDefault().createID(
+ container.getConnectNamespace(), targetId), null);
+ }
+
+ protected IContainerManager getContainerManager() {
+ if (containerManagerTracker == null) {
+ containerManagerTracker = new ServiceTracker(bundleContext,
+ IContainerManager.class.getName(), null);
+ containerManagerTracker.open();
+ }
+ return (IContainerManager) containerManagerTracker.getService();
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/Activator.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/Activator.java
new file mode 100644
index 000000000..6935a6538
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/Activator.java
@@ -0,0 +1,39 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+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.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
new file mode 100644
index 000000000..4ff651296
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminClientApplication.java
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+import java.util.Properties;
+
+import org.eclipse.equinox.app.IApplication;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+public class EventAdminClientApplication extends AbstractEventAdminApplication {
+
+ private static final String DEFAULT_CONTAINER_TYPE = "ecf.jms.activemq.tcp.client";
+ private static final String DEFAULT_TOPIC = EventAdminManagerApplication.DEFAULT_TOPIC;
+ private static final String DEFAULT_CONTAINER_TARGET = EventAdminManagerApplication.DEFAULT_CONTAINER_ID;
+
+ private TestSender testSender;
+ private ServiceRegistration testEventHandlerRegistration;
+
+ protected Object run() {
+
+ // XXX for testing, setup an event handler
+ Properties props = new Properties();
+ props.put(EventConstants.EVENT_TOPIC, "*");
+ testEventHandlerRegistration = bundleContext.registerService(
+ EventHandler.class.getName(), new TestEventHandler(), props);
+
+ // XXX for testing, setup a test sender
+ testSender = new TestSender(eventAdminImpl, topic, container.getID().getName());
+ new Thread(testSender).start();
+
+ // Now just wait until we're stopped
+ waitForDone();
+
+ return IApplication.EXIT_OK;
+ }
+
+ protected void shutdown() {
+ if (testSender != null) {
+ testSender.stop();
+ testSender = null;
+ }
+ if (testEventHandlerRegistration != null) {
+ testEventHandlerRegistration.unregister();
+ testEventHandlerRegistration = null;
+ }
+ super.shutdown();
+ }
+
+ protected String usageApplicationId() {
+ return "org.eclipse.ecf.examples.eventadmin.app.EventAdminClient";
+ }
+
+ 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
new file mode 100644
index 000000000..e2750cf57
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/EventAdminManagerApplication.java
@@ -0,0 +1,88 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+import java.util.Properties;
+
+import org.eclipse.equinox.app.IApplication;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+public class EventAdminManagerApplication extends AbstractEventAdminApplication
+ implements IApplication {
+
+ private static final String DEFAULT_CONTAINER_TYPE = "ecf.jms.activemq.tcp.manager";
+ public static final String DEFAULT_CONTAINER_ID = "tcp://localhost:61616/exampleTopic";
+
+ private TestSender testSender;
+ private ServiceRegistration testEventHandlerRegistration;
+
+ protected Object run() {
+ Properties props = new Properties();
+ props.put(EventConstants.EVENT_TOPIC, "*");
+ testEventHandlerRegistration = bundleContext.registerService(
+ EventHandler.class.getName(), new TestEventHandler(), props);
+
+ // XXX for testing, setup a test sender
+ testSender = new TestSender(eventAdminImpl, topic, container.getID()
+ .getName());
+ new Thread(testSender).start();
+
+ waitForDone();
+
+ return IApplication.EXIT_OK;
+ }
+
+ protected void shutdown() {
+ if (testSender != null) {
+ testSender.stop();
+ testSender = null;
+ }
+ if (testEventHandlerRegistration != null) {
+ testEventHandlerRegistration.unregister();
+ testEventHandlerRegistration = null;
+ }
+ super.shutdown();
+ }
+
+ 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++;
+ }
+ }
+
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestEventHandler.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestEventHandler.java
new file mode 100644
index 000000000..dfc021758
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestEventHandler.java
@@ -0,0 +1,24 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+public class TestEventHandler implements EventHandler {
+
+ public void handleEvent(Event event) {
+ System.out.println("handleEvent\n\ttopic=" + event.getTopic()
+ + "\n\tmessage=" + event.getProperty("message") + "\n\tsender="
+ + event.getProperty("sender"));
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestSender.java b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestSender.java
new file mode 100644
index 000000000..546c15706
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.eventadmin.app/src/org/eclipse/ecf/examples/internal/eventadmin/app/TestSender.java
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * 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
+ *****************************************************************************/
+package org.eclipse.ecf.examples.internal.eventadmin.app;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
+public class TestSender implements Runnable {
+
+ private static final long DEFAULT_WAITTIME = 2000;
+
+ private long waittime = DEFAULT_WAITTIME;
+
+ private EventAdmin eventAdmin;
+ private String topic;
+ private String sender;
+ private boolean done = false;
+ private long messageCounter = 0L;
+
+ public TestSender(EventAdmin eventAdmin, String topic, String sender) {
+ this.eventAdmin = eventAdmin;
+ this.topic = topic;
+ this.sender = sender;
+ }
+
+ public void run() {
+ synchronized (this) {
+ while (!done) {
+ try {
+ wait(waittime);
+ Map msgProps = new Properties();
+ msgProps.put("message", "message #"
+ + messageCounter++);
+ msgProps.put("sender", sender);
+ eventAdmin.postEvent(new Event(topic, msgProps));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void stop() {
+ synchronized (this) {
+ done = true;
+ notifyAll();
+ }
+ }
+}

Back to the top