From bbcff0df70d935fb2e9a2eee3c663f947446f65a Mon Sep 17 00:00:00 2001
From: slewis
Date: Thu, 11 Jun 2009 04:54:52 +0000
Subject: removed content in favor of
org.eclipse.ecf.examples.eventadmin/eventadmin.app projects
---
.../.classpath | 7 -
.../.project | 28 ---
.../.settings/org.eclipse.jdt.core.prefs | 69 -------
.../.settings/org.eclipse.pde.core.prefs | 4 -
.../META-INF/MANIFEST.MF | 18 --
.../about.html | 28 ---
.../build.properties | 10 -
.../bundle.properties | 10 -
.../readme.txt | 7 +
.../remoteservices/eventadmin/EventAdminImpl.java | 226 ---------------------
10 files changed, 7 insertions(+), 400 deletions(-)
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.classpath
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.project
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.settings/org.eclipse.jdt.core.prefs
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.settings/org.eclipse.pde.core.prefs
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/META-INF/MANIFEST.MF
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/about.html
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/build.properties
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/bundle.properties
create mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/readme.txt
delete mode 100644 examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/src/org/eclipse/ecf/examples/remoteservices/eventadmin/EventAdminImpl.java
(limited to 'examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin')
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.classpath b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.classpath
deleted file mode 100644
index 6f3b481ac..000000000
--- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
June 25, 2008
-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 http://www.eclipse.org/legal/epl-v10.html. -For purposes of the EPL, "Program" will mean the Content.
- -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 http://www.eclipse.org.
- - - \ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/build.properties b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/build.properties deleted file mode 100644 index 40ab22e41..000000000 --- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/build.properties +++ /dev/null @@ -1,10 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - about.html,\ - bundle.properties -src.includes = META-INF/,\ - about.html,\ - bundle.properties,\ - src/ diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/bundle.properties b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/bundle.properties deleted file mode 100644 index de1d72435..000000000 --- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/bundle.properties +++ /dev/null @@ -1,10 +0,0 @@ -################################################################################# -# 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 -# -# Contributors: -# EclipseSource - initial API and implementation -################################################################################# -bundleName=ECF RemoteServices EventAdmin Example -bundleProvider=Eclipse.org - ECF \ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/readme.txt b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/readme.txt new file mode 100644 index 000000000..6f3eea32a --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/readme.txt @@ -0,0 +1,7 @@ +The contents of this project have moved to the two projects: + +org.eclipse.ecf/examples/bundles + +org.eclipse.ecf.examples.eventadmin +org.eclipse.ecf.examples.eventadmin.app + diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/src/org/eclipse/ecf/examples/remoteservices/eventadmin/EventAdminImpl.java b/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/src/org/eclipse/ecf/examples/remoteservices/eventadmin/EventAdminImpl.java deleted file mode 100644 index 91e638472..000000000 --- a/examples/bundles/org.eclipse.ecf.examples.remoteservices.eventadmin/src/org/eclipse/ecf/examples/remoteservices/eventadmin/EventAdminImpl.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * 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.examples.remoteservices.eventadmin; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants; -import org.eclipse.ecf.remoteservice.IRemoteCall; -import org.eclipse.ecf.remoteservice.IRemoteService; -import org.eclipse.equinox.concurrent.future.IExecutor; -import org.eclipse.equinox.concurrent.future.IProgressRunnable; -import org.eclipse.equinox.concurrent.future.ThreadsExecutor; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.event.Event; -import org.osgi.service.event.EventAdmin; -import org.osgi.service.event.EventConstants; -import org.osgi.service.event.EventHandler; -import org.osgi.util.tracker.ServiceTracker; - -public class EventAdminImpl implements EventAdmin { - - private BundleContext context; - private IExecutor executor; - private Object executorLock = new Object(); - private ServiceTracker eventHandlerServiceTracker; - private Object eventHandlerSTLock = new Object(); - private long defaultTimeout; - - public EventAdminImpl(BundleContext context, IExecutor executor, - long defaultTimeout) { - this.context = context; - this.executor = executor; - this.defaultTimeout = defaultTimeout; - } - - protected IRemoteService getRemoteServiceForServiceReference( - ServiceReference ref) { - if (ref == null) - return null; - Object remoteProp = ref.getProperty(IDistributionConstants.REMOTE); - if (remoteProp != null && remoteProp instanceof IRemoteService) - return (IRemoteService) remoteProp; - return null; - } - - private ServiceReference[] getEventHandlerServiceReferences(Event event) { - synchronized (eventHandlerSTLock) { - if (eventHandlerServiceTracker == null) { - eventHandlerServiceTracker = new ServiceTracker(context, - EventHandler.class.getName(), null); - eventHandlerServiceTracker.open(); - } - ServiceReference[] refs = eventHandlerServiceTracker - .getServiceReferences(); - List results = new ArrayList(); - if (refs == null) - return null; - for (int i = 0; i < refs.length; i++) { - String eventFilter = (String) refs[i] - .getProperty(EventConstants.EVENT_FILTER); - Filter filter = null; - if (eventFilter != null) { - try { - filter = context.createFilter(eventFilter); - if (event.matches(filter)) - results.add(refs[i]); - } catch (InvalidSyntaxException e) { - logError("getEventHandlers eventFilter=" + eventFilter, - e); - continue; - } - } else - results.add(refs[i]); - } - return (ServiceReference[]) results - .toArray(new ServiceReference[] {}); - } - } - - protected void logError(String string, Throwable e) { - System.err.println(string); - if (e != null) - e.printStackTrace(System.err); - } - - public void postEvent(final Event event) { - ServiceReference[] refs = getEventHandlerServiceReferences(event); - if (refs == null) { - logWarning("postEvent event=" + event - + ". No service references found to post to."); - return; - } - for (int i = 0; i < refs.length; i++) { - IRemoteService remoteService = getRemoteServiceForServiceReference(refs[i]); - // If this is a remote service, then fire the EventHandler - // asynchronously via IRemoteService.fireAsync - if (remoteService != null) - fireAsync(refs[i], remoteService, createRemoteCall(event)); - // Else call the EventHandler asynchronously by using Equinox - // concurrent API - else - fireAsync(refs[i], (EventHandler) context.getService(refs[i]), - event); - } - } - - protected void logWarning(String string) { - System.out.println(string); - } - - protected IRemoteCall createRemoteCall(final Event event) { - return new IRemoteCall() { - - public String getMethod() { - return "handleEvent"; - } - - public Object[] getParameters() { - return new Object[] { event }; - } - - public long getTimeout() { - return defaultTimeout; - } - }; - } - - public void sendEvent(Event event) { - ServiceReference[] eventHandlerRefs = getEventHandlerServiceReferences(event); - if (eventHandlerRefs == null) { - logWarning("sendEvent event=" + event - + ". No service references found to post to."); - return; - } - // Now synchronously call every eventhandler - for (int i = 0; i < eventHandlerRefs.length; i++) - callSync(eventHandlerRefs[i], (EventHandler) context - .getService(eventHandlerRefs[i]), event); - } - - protected void callSync(final ServiceReference serviceReference, - final EventHandler eventHandler, final Event event) { - SafeRunner.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - logCallException( - "Exception in EventHandler.handleEvent. eventHandler=" - + eventHandler + ". serviceReference=" - + serviceReference + ". event=" + event, - exception); - } - - public void run() throws Exception { - eventHandler.handleEvent(event); - } - }); - } - - protected void fireAsync(final ServiceReference serviceReference, - final EventHandler eventHandler, final Event event) { - getExecutor().execute(new IProgressRunnable() { - public Object run(IProgressMonitor arg0) throws Exception { - eventHandler.handleEvent(event); - return null; - } - }, null); - } - - protected IExecutor getExecutor() { - synchronized (executorLock) { - if (executor == null) { - executor = new ThreadsExecutor(); - } - return executor; - } - } - - protected void fireAsync(final ServiceReference serviceReference, - final IRemoteService remoteService, final IRemoteCall call) { - SafeRunner.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - logCallException( - "Exception in IRemoteService.fireAsync. IRemoteService=" - + remoteService + ". serviceReference=" - + serviceReference + ". remoteCall=" + call, - exception); - } - - public void run() throws Exception { - remoteService.fireAsync(call); - } - }); - } - - protected void logCallException(String string, Throwable t) { - System.err.println(string); - if (t != null) - t.printStackTrace(System.err); - } - - public void dispose() { - synchronized (eventHandlerSTLock) { - if (eventHandlerServiceTracker != null) { - eventHandlerServiceTracker.close(); - eventHandlerServiceTracker = null; - } - } - synchronized (executorLock) { - executor = null; - } - context = null; - } -} -- cgit v1.2.1