Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 82511 Details for
Bug 202278
[eventadmin] Remove event adapters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.equinox.event.patch
clipboard.txt (text/plain), 135.04 KB, created by
Chris Aniszczyk
on 2007-11-08 22:35:54 EST
(
hide
)
Description:
org.eclipse.equinox.event.patch
Filename:
MIME Type:
Creator:
Chris Aniszczyk
Created:
2007-11-08 22:35:54 EST
Size:
135.04 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.event >Index: src/org/eclipse/equinox/event/mapper/LogReaderServiceListener.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/LogReaderServiceListener.java >diff -N src/org/eclipse/equinox/event/mapper/LogReaderServiceListener.java >--- src/org/eclipse/equinox/event/mapper/LogReaderServiceListener.java 26 Jul 2006 18:04:12 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,26 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.log.LogReaderService; >- >-/** >- * @version $Revision: 1.1 $ >- */ >-public interface LogReaderServiceListener { >- public void logReaderServiceAdding(ServiceReference reference, >- LogReaderService service); >- >- public void logReaderServiceRemoved(ServiceReference reference, >- LogReaderService service); >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/FrameworkEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/FrameworkEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/FrameworkEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/FrameworkEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,72 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.Bundle; >-import org.osgi.framework.FrameworkEvent; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class FrameworkEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String HEADER = "org/osgi/framework/FrameworkEvent"; >- public static final String STARTLEVEL_CHANGED = "STARTLEVEL_CHANGED"; >- public static final String STARTED = "STARTED"; >- public static final String PACKAGES_REFRESHED = "PACKAGES_REFRESHED"; >- public static final String ERROR = "ERROR"; >- protected FrameworkEvent event; >- >- public FrameworkEventAdapter(FrameworkEvent event, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.event = event; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case FrameworkEvent.ERROR : >- typename = ERROR; >- break; >- case FrameworkEvent.PACKAGES_REFRESHED : >- typename = PACKAGES_REFRESHED; >- break; >- case FrameworkEvent.STARTED : >- typename = STARTED; >- break; >- case FrameworkEvent.STARTLEVEL_CHANGED : >- typename = STARTLEVEL_CHANGED; >- break; >- default : >- return null; >- } >- String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- Bundle bundle = event.getBundle(); >- if (bundle != null) { >- putBundleProperties(properties, bundle); >- } >- Throwable t = event.getThrowable(); >- if (t != null) { >- putExceptionProperties(properties, t); >- } >- properties.put(Constants.EVENT, event); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/WireAdminEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/WireAdminEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/WireAdminEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/WireAdminEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,107 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >-import org.osgi.service.wireadmin.Wire; >-import org.osgi.service.wireadmin.WireAdminEvent; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class WireAdminEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String TOPIC = "org/osgi/service/wireadmin/WireAdminEvent"; >- public static final String WIRE_CREATED = "WIRE_CREATED"; >- public static final String WIRE_CONNECTED_T = "WIRE_CONNECTED"; >- public static final String WIRE_UPDATED = "WIRE_UPDATED"; >- public static final String WIRE_TRACE = "WIRE_TRACE"; >- public static final String WIRE_DISCONNECTED = "WIRE_DISCONNECTED"; >- public static final String WIRE_DELETED = "WIRE_DELETED"; >- public static final String PRODUCER_EXCEPTION = "PRODUCER_EXCEPTION"; >- public static final String CONSUMER_EXCEPTION = "CONSUMER_EXCEPTION"; >- // constants for Event properties >- public static final String WIRE = "wire"; >- public static final String WIRE_FLAVORS = "wire.flavors"; >- public static final String WIRE_SCOPE = "wire.scope"; >- public static final String WIRE_CONNECTED_P = "wire.connected"; >- public static final String WIRE_VALID = "wire.valid"; >- private WireAdminEvent event; >- >- public WireAdminEventAdapter(WireAdminEvent event, EventAdmin admin) { >- super(admin); >- this.event = event; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case WireAdminEvent.WIRE_CONNECTED : >- typename = WIRE_CONNECTED_T; >- break; >- case WireAdminEvent.WIRE_CREATED : >- typename = WIRE_CREATED; >- break; >- case WireAdminEvent.WIRE_UPDATED : >- typename = WIRE_UPDATED; >- break; >- case WireAdminEvent.WIRE_DELETED : >- typename = WIRE_DELETED; >- break; >- case WireAdminEvent.WIRE_DISCONNECTED : >- typename = WIRE_DISCONNECTED; >- break; >- case WireAdminEvent.WIRE_TRACE : >- typename = WIRE_TRACE; >- break; >- case WireAdminEvent.PRODUCER_EXCEPTION : >- typename = PRODUCER_EXCEPTION; >- break; >- case WireAdminEvent.CONSUMER_EXCEPTION : >- typename = CONSUMER_EXCEPTION; >- break; >- default : >- return null; >- } >- String topic = TOPIC + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- Throwable t = event.getThrowable(); >- if (t != null) { >- putExceptionProperties(properties, t); >- } >- ServiceReference ref = event.getServiceReference(); >- if (ref == null) { >- throw new RuntimeException("WireAdminEvent's getServiceReference() returns null."); >- } >- putServiceReferenceProperties(properties, ref); >- Wire wire = event.getWire(); >- if (wire != null) { >- properties.put(WIRE, wire); >- if (wire.getFlavors() != null) { >- properties.put(WIRE_FLAVORS, classes2strings(wire.getFlavors())); >- } >- if (wire.getScope() != null) { >- properties.put(WIRE_SCOPE, wire.getScope()); >- } >- properties.put(WIRE_CONNECTED_P, new Boolean(wire.isConnected())); >- properties.put(WIRE_VALID, new Boolean(wire.isValid())); >- } >- properties.put(Constants.EVENT, event); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/EventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/EventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/EventAdapter.java >--- src/org/eclipse/equinox/event/mapper/EventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,100 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.Bundle; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public abstract class EventAdapter { >- final EventAdmin eventAdmin; >- >- /** >- * @param event >- * @param eventAdmin >- */ >- public EventAdapter(EventAdmin eventAdmin) { >- this.eventAdmin = eventAdmin; >- } >- >- /** >- * @return event >- */ >- public abstract Event convert(); >- >- public void redeliver() { >- Event converted = convert(); >- if (converted != null) { >- redeliverInternal(converted); >- } >- } >- >- /** >- * subclasses should override this method if it wants to use sendEvent() >- * instead. >- */ >- protected void redeliverInternal(Event converted) { >- eventAdmin.postEvent(converted); >- } >- >- public void putBundleProperties(Hashtable properties, Bundle bundle) { >- // assertion bundle != null >- properties.put(Constants.BUNDLE_ID, new Long(bundle.getBundleId())); >- String symbolicName = bundle.getSymbolicName(); >- if (symbolicName != null) { >- properties.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName); >- } >- properties.put(Constants.BUNDLE, bundle); >- } >- >- public void putExceptionProperties(Hashtable properties, Throwable t) { >- // assertion t != null >- properties.put(Constants.EXCEPTION, t); >- properties.put(Constants.EXCEPTION_CLASS, t.getClass().getName()); >- String message = t.getMessage(); >- if (message != null) { >- properties.put(Constants.EXCEPTION_MESSAGE, t.getMessage()); >- } >- } >- >- public void putServiceReferenceProperties(Hashtable properties, ServiceReference ref) { >- // assertion ref != null >- properties.put(Constants.SERVICE, ref); >- properties.put(Constants.SERVICE_ID, ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)); >- Object o = ref.getProperty(org.osgi.framework.Constants.SERVICE_PID); >- if ((o != null) && (o instanceof String)) { >- properties.put(Constants.SERVICE_PID, (String) o); >- } >- Object o2 = ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS); >- if ((o2 != null) && (o2 instanceof String[])) { >- properties.put(Constants.SERVICE_OBJECTCLASS, (String[]) o2); >- } >- } >- >- /* >- * Utility function for converting classes into strings >- */ >- public String[] classes2strings(Class classes[]) { >- if ((classes == null) || (classes.length == 0)) >- return null; >- String[] strings = new String[classes.length]; >- for (int i = 0; i < classes.length; i++) { >- strings[i] = classes[i].getName(); >- } >- return strings; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/ServiceEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/ServiceEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/ServiceEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/ServiceEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,64 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.ServiceEvent; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.3 $ >- */ >-public class ServiceEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String HEADER = "org/osgi/framework/ServiceEvent"; >- public static final String UNREGISTERING = "UNREGISTERING"; >- public static final String MODIFIED = "MODIFIED"; >- public static final String REGISTERED = "REGISTERED"; >- private ServiceEvent event; >- >- public ServiceEventAdapter(ServiceEvent event, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.event = event; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case ServiceEvent.REGISTERED : >- typename = REGISTERED; >- break; >- case ServiceEvent.MODIFIED : >- typename = MODIFIED; >- break; >- case ServiceEvent.UNREGISTERING : >- typename = UNREGISTERING; >- break; >- default : >- return null; >- } >- String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- ServiceReference ref = event.getServiceReference(); >- if (ref != null) { >- putServiceReferenceProperties(properties, ref); >- } >- properties.put(Constants.EVENT, event); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/Constants.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/Constants.java >diff -N src/org/eclipse/equinox/event/mapper/Constants.java >--- src/org/eclipse/equinox/event/mapper/Constants.java 26 Jul 2006 18:04:12 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,33 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event.mapper; >- >-/** >- * @version $Revision: 1.1 $ >- */ >-public interface Constants { >- // constants for Event common properties; event specific properties are >- // defined in the corresponding event adapter. >- public static final String BUNDLE = "bundle"; >- public static final String BUNDLE_ID = "bundle.id"; >- public static final String BUNDLE_SYMBOLICNAME = "bundle.symbolicName"; >- public static final String EVENT = "event"; >- public static final String EXCEPTION = "exception"; >- public static final String EXCEPTION_CLASS = "exception.class"; >- public static final String EXCEPTION_MESSAGE = "exception.message"; >- public static final String MESSAGE = "message"; >- public static final String SERVICE = "service"; >- public static final String SERVICE_ID = "service.id"; >- public static final String SERVICE_OBJECTCLASS = "service.objectClass"; >- public static final String SERVICE_PID = "service.pid"; >- public static final String TIMESTAMP = "timestamp"; >- public static final char TOPIC_SEPARATOR = '/'; >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/UserAdminEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/UserAdminEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/UserAdminEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/UserAdminEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,79 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >-import org.osgi.service.useradmin.Role; >-import org.osgi.service.useradmin.UserAdminEvent; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class UserAdminEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String TOPIC = "org/osgi/service/useradmin/UserAdminEvent"; >- public static final String ROLE_CREATED = "ROLE_CREATED"; >- public static final String ROLE_CHANGED = "ROLE_CHANGED"; >- public static final String ROLE_REMOVED = "ROLE_REMOVED"; >- // constants for Event properties >- public static final String ROLE = "role"; >- public static final String ROLE_NAME = "role.name"; >- public static final String ROLE_TYPE = "role.type"; >- private UserAdminEvent event; >- >- public UserAdminEventAdapter(UserAdminEvent event, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.event = event; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case UserAdminEvent.ROLE_CREATED : >- typename = ROLE_CREATED; >- break; >- case UserAdminEvent.ROLE_CHANGED : >- typename = ROLE_CHANGED; >- break; >- case UserAdminEvent.ROLE_REMOVED : >- typename = ROLE_REMOVED; >- break; >- default : >- return null; >- } >- String topic = TOPIC + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- ServiceReference ref = event.getServiceReference(); >- if (ref == null) { >- throw new RuntimeException("UserAdminEvent's getServiceReference() returns null."); >- } >- putServiceReferenceProperties(properties, ref); >- Role role = event.getRole(); >- if (role == null) { >- throw new RuntimeException("UserAdminEvent's getRole() returns null."); >- } >- if (role != null) { >- properties.put(ROLE, role); >- properties.put(ROLE_NAME, role.getName()); >- properties.put(ROLE_TYPE, new Integer(role.getType())); >- } >- properties.put(Constants.EVENT, event); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/LogReaderServiceTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/LogReaderServiceTracker.java >diff -N src/org/eclipse/equinox/event/mapper/LogReaderServiceTracker.java >--- src/org/eclipse/equinox/event/mapper/LogReaderServiceTracker.java 26 Jul 2006 18:04:12 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,53 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import org.osgi.framework.BundleContext; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.log.LogReaderService; >-import org.osgi.util.tracker.ServiceTracker; >- >-/** >- * @version $Revision: 1.1 $ >- */ >-public class LogReaderServiceTracker extends ServiceTracker { >- private final LogReaderServiceListener listener; >- private ServiceReference reference; >- >- public LogReaderServiceTracker(BundleContext context, >- LogReaderServiceListener listener) { >- super(context, LogReaderService.class.getName(), null); >- this.listener = listener; >- } >- >- public Object addingService(ServiceReference reference) { >- Object object = super.addingService(reference); >- if ((object != null) && (this.reference == null) >- && (object instanceof LogReaderService)) { >- this.reference = reference; >- listener.logReaderServiceAdding(reference, >- (LogReaderService) object); >- } >- return object; >- } >- >- public void removedService(ServiceReference reference, Object service) { >- if ((service != null) && (this.reference.equals(reference)) >- && (service instanceof LogReaderService)) { >- listener.logReaderServiceRemoved(reference, >- (LogReaderService) service); >- this.reference = null; >- } >- super.removedService(reference, service); >- //this method calls ungetService() >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/EventRedeliverer.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/EventRedeliverer.java >diff -N src/org/eclipse/equinox/event/mapper/EventRedeliverer.java >--- src/org/eclipse/equinox/event/mapper/EventRedeliverer.java 26 Jul 2006 18:04:12 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,307 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Dictionary; >-import java.util.Hashtable; >-import org.osgi.framework.*; >-import org.osgi.service.cm.ConfigurationEvent; >-import org.osgi.service.cm.ConfigurationListener; >-import org.osgi.service.event.EventAdmin; >-import org.osgi.service.log.LogEntry; >-import org.osgi.service.log.LogListener; >-import org.osgi.service.log.LogReaderService; >-import org.osgi.service.upnp.UPnPDevice; >-import org.osgi.service.upnp.UPnPEventListener; >-import org.osgi.service.upnp.UPnPService; >-import org.osgi.service.useradmin.UserAdminEvent; >-import org.osgi.service.useradmin.UserAdminListener; >-import org.osgi.service.wireadmin.WireAdminEvent; >-import org.osgi.service.wireadmin.WireAdminListener; >-import org.osgi.service.wireadmin.WireConstants; >-import org.osgi.util.tracker.ServiceTracker; >- >-/** >- * Main class for redeliver special events like FrameworkEvents via EventAdmin. >- * >- * >- * @version $Revision: 1.1 $ >- */ >-public class EventRedeliverer implements FrameworkListener, BundleListener, >- ServiceListener, LogListener, LogReaderServiceListener, >- ConfigurationListener, WireAdminListener, UPnPEventListener, >- UserAdminListener { >- private ServiceTracker eventAdminTracker; >- private LogReaderServiceTracker logTracker; >- private LogReaderService reader; >- private final static boolean DEBUG = false; >- private BundleContext bc; >- private ServiceRegistration configurationListenerReg; >- private ServiceRegistration wireAdminListenerReg; >- private ServiceRegistration upnpEventListenerReg; >- private ServiceRegistration userAdminListenerReg; >- >- public EventRedeliverer(BundleContext bc) { >- this.bc = bc; >- } >- >- public void close() { >- if (logTracker != null) { >- logTracker.close(); >- logTracker = null; >- } >- if (eventAdminTracker != null) { >- eventAdminTracker.close(); >- eventAdminTracker = null; >- } >- if (reader != null) { >- reader.removeLogListener(this); >- } >- reader = null; >- bc.removeFrameworkListener(this); >- bc.removeBundleListener(this); >- bc.removeServiceListener(this); >- if (configurationListenerReg != null) { >- configurationListenerReg.unregister(); >- configurationListenerReg = null; >- } >- if (wireAdminListenerReg != null) { >- wireAdminListenerReg.unregister(); >- wireAdminListenerReg = null; >- } >- if (upnpEventListenerReg != null) { >- upnpEventListenerReg.unregister(); >- upnpEventListenerReg = null; >- } >- if (userAdminListenerReg != null) { >- userAdminListenerReg.unregister(); >- userAdminListenerReg = null; >- } >- } >- >- /** >- * prepare any service trackers and register event listeners which are >- * necessary to obtain events to be mapped >- */ >- public void open() { >- // open ServiceTracker for EventAdmin >- eventAdminTracker = new ServiceTracker(bc, EventAdmin.class.getName(), >- null); >- eventAdminTracker.open(); >- // open ServiceTracker for LogReaderService >- logTracker = new LogReaderServiceTracker(bc, this); >- logTracker.open(); >- // add legacy event listener for framework level event >- bc.addFrameworkListener(this); >- bc.addBundleListener(this); >- bc.addServiceListener(this); >- // register configurationListener >- configurationListenerReg = bc.registerService( >- ConfigurationListener.class.getName(), this, null); >- // register WireAdminListener >- Hashtable ht = new Hashtable(); >- // create an event mask to receive all the types of WireAdminEvent >- Integer mask = new Integer(WireAdminEvent.WIRE_CONNECTED >- | WireAdminEvent.WIRE_CREATED | WireAdminEvent.WIRE_DELETED >- | WireAdminEvent.WIRE_DISCONNECTED | WireAdminEvent.WIRE_TRACE >- | WireAdminEvent.WIRE_UPDATED >- | WireAdminEvent.CONSUMER_EXCEPTION >- | WireAdminEvent.PRODUCER_EXCEPTION); >- ht.put(WireConstants.WIREADMIN_EVENTS, mask); >- wireAdminListenerReg = bc.registerService(WireAdminListener.class >- .getName(), this, ht); >- // register UPnPEventListener >- // create a Filter object to receive all the UPnP events >- Hashtable ht2 = new Hashtable(); >- Filter filter = null; >- try { >- filter = bc.createFilter("(|(|(" + UPnPDevice.TYPE + "=*)(" >- + UPnPDevice.ID + "=*))(|(" + UPnPService.TYPE + "=*)(" >- + UPnPService.ID + "=*)))"); >- } >- catch (InvalidSyntaxException e) { >- System.out >- .println("Exception thrown while trying to create Filter. " >- + e); >- e.printStackTrace(System.out); >- } >- if (filter != null) { >- ht2.put(UPnPEventListener.UPNP_FILTER, filter); >- upnpEventListenerReg = bc.registerService(UPnPEventListener.class >- .getName(), this, ht2); >- } >- // register usrAdminListener >- userAdminListenerReg = bc.registerService(UserAdminListener.class >- .getName(), this, null); >- } >- >- private EventAdmin getEventAdmin() { >- if (eventAdminTracker == null) >- return null; >- return (EventAdmin) eventAdminTracker.getService(); >- } >- >- /** >- * @param event >- * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent) >- */ >- public void frameworkEvent(FrameworkEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new FrameworkEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- private void printNoEventAdminError() { >- if (DEBUG) { >- System.out.println(this.getClass().getName() >- + ": Cannot find the EventAdmin."); >- } >- } >- >- /** >- * @param event >- * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent) >- */ >- public void bundleChanged(BundleEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new BundleEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param event >- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent) >- */ >- public void serviceChanged(ServiceEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new ServiceEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param entry >- * @see org.osgi.service.log.LogListener#logged(org.osgi.service.log.LogEntry) >- */ >- public void logged(LogEntry entry) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new LogEntryAdapter(entry, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param reference >- * @param service >- * @see org.eclipse.equinox.event.mapper.LogReaderServiceListener#logReaderServiceAdding(org.osgi.framework.ServiceReference, >- * org.osgi.service.log.LogReaderService) >- */ >- public void logReaderServiceAdding(ServiceReference reference, >- LogReaderService service) { >- if (reader != null) { >- return; >- } >- reader = service; >- reader.addLogListener(this); >- } >- >- /** >- * @param reference >- * @param service >- * @see org.eclipse.equinox.event.mapper.LogReaderServiceListener#logReaderServiceRemoved(org.osgi.framework.ServiceReference, >- * org.osgi.service.log.LogReaderService) >- */ >- public void logReaderServiceRemoved(ServiceReference reference, >- LogReaderService service) { >- if ((reader != null) && reader.equals(service)) { >- reader.removeLogListener(this); >- reader = null; >- } >- // ungetService() will be called after returning to >- // LogReaderServiceTracker's removedService() method. >- } >- >- /** >- * @param event >- * @see org.osgi.service.cm.ConfigurationListener#configurationEvent(org.osgi.service.cm.ConfigurationEvent) >- */ >- public void configurationEvent(ConfigurationEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new ConfigurationEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param event >- * @see org.osgi.service.wireadmin.WireAdminListener#wireAdminEvent(org.osgi.service.wireadmin.WireAdminEvent) >- */ >- public void wireAdminEvent(WireAdminEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new WireAdminEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param deviceId >- * @param serviceId >- * @param events >- * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, >- * java.lang.String, java.util.Dictionary) >- */ >- public void notifyUPnPEvent(String deviceId, String serviceId, >- Dictionary events) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new UPnPEventAdapter(deviceId, serviceId, events, eventAdmin)) >- .redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >- >- /** >- * @param event >- * @see org.osgi.service.useradmin.UserAdminListener#roleChanged(org.osgi.service.useradmin.UserAdminEvent) >- */ >- public void roleChanged(UserAdminEvent event) { >- EventAdmin eventAdmin = getEventAdmin(); >- if (eventAdmin != null) { >- (new UserAdminEventAdapter(event, eventAdmin)).redeliver(); >- } >- else { >- printNoEventAdminError(); >- } >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/UPnPEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/UPnPEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/UPnPEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/UPnPEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,57 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Dictionary; >-import java.util.Hashtable; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class UPnPEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String TOPIC = "org/osgi/service/upnp/UPnPEvent"; >- // constants for Event properties >- public static final String UPNP_DEVICEID = "upnp.deviceId"; >- public static final String UPNP_SERVICEID = "upnp.serviceId"; >- public static final String UPNP_EVENTS = "upnp.events"; >- private String deviceId; >- private String serviceId; >- private Dictionary events; >- >- public UPnPEventAdapter(String deviceId, String serviceId, Dictionary events, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.deviceId = deviceId; >- this.serviceId = serviceId; >- this.events = events; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- Hashtable properties = new Hashtable(); >- if (deviceId != null) { >- properties.put(UPNP_DEVICEID, deviceId); >- } >- if (serviceId != null) { >- properties.put(UPNP_SERVICEID, serviceId); >- } >- if (events != null) { >- properties.put(UPNP_EVENTS, events); >- } >- Event converted = new Event(TOPIC, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/ConfigurationEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/ConfigurationEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/ConfigurationEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/ConfigurationEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,68 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.cm.ConfigurationEvent; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class ConfigurationEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String HEADER = "org/osgi/service/cm/ConfigurationEvent"; >- public static final String CM_UPDATED = "CM_UPDATED"; >- public static final String CM_DELETED = "CM_DELETED"; >- // constants for Event properties >- public static final String CM_FACTORY_PID = "cm.factoryPid"; >- public static final String CM_PID = "cm.pid"; >- private ConfigurationEvent event; >- >- public ConfigurationEventAdapter(ConfigurationEvent event, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.event = event; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case ConfigurationEvent.CM_UPDATED : >- typename = CM_UPDATED; >- break; >- case ConfigurationEvent.CM_DELETED : >- typename = CM_DELETED; >- break; >- default : >- return null; >- } >- String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- ServiceReference ref = event.getReference(); >- if (ref == null) { >- throw new RuntimeException("ServiceEvent.getServiceReference() is null"); >- } >- properties.put(CM_PID, event.getPid()); >- if (event.getFactoryPid() != null) { >- properties.put(CM_FACTORY_PID, event.getFactoryPid()); >- } >- putServiceReferenceProperties(properties, ref); >- // assert objectClass includes >- // "org.osgi.service.cm.ConfigurationAdmin" >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/LogEntryAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/LogEntryAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/LogEntryAdapter.java >--- src/org/eclipse/equinox/event/mapper/LogEntryAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,78 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.Bundle; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >-import org.osgi.service.log.LogEntry; >-import org.osgi.service.log.LogService; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class LogEntryAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String TOPIC = "org/osgi/service/log/LogEntry"; >- // constants for Event properties >- public static final String TIMESTAMP = "timestamp"; >- public static final String MESSAGE = "message"; >- public static final String LOG_LEVEL = "log.level"; >- public static final String LOG_ENTRY = "log.entry"; >- private LogEntry entry; >- >- public LogEntryAdapter(LogEntry entry, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.entry = entry; >- } >- >- /** >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String topic = TOPIC; >- int level = entry.getLevel(); >- switch (level) { >- case LogService.LOG_ERROR : >- case LogService.LOG_WARNING : >- case LogService.LOG_INFO : >- case LogService.LOG_DEBUG : >- break; >- default : >- // other log levels are represented by their decimal value >- topic += Constants.TOPIC_SEPARATOR + level; >- } >- Hashtable properties = new Hashtable(); >- Bundle bundle = entry.getBundle(); >- if (bundle == null) { >- throw new RuntimeException("LogEntry.getBundle() returns null"); >- } >- putBundleProperties(properties, bundle); >- Throwable t = entry.getException(); >- if (t != null) { >- putExceptionProperties(properties, t); >- } >- ServiceReference ref = entry.getServiceReference(); >- if (ref != null) { >- putServiceReferenceProperties(properties, ref); >- } >- properties.put(LOG_ENTRY, entry); >- properties.put(LOG_LEVEL, new Integer(entry.getLevel())); >- if (entry.getMessage() != null) >- properties.put(MESSAGE, entry.getMessage()); >- properties.put(TIMESTAMP, new Long(entry.getTime())); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/mapper/BundleEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/mapper/BundleEventAdapter.java >diff -N src/org/eclipse/equinox/event/mapper/BundleEventAdapter.java >--- src/org/eclipse/equinox/event/mapper/BundleEventAdapter.java 24 Oct 2007 16:47:31 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,83 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event.mapper; >- >-import java.util.Hashtable; >-import org.osgi.framework.Bundle; >-import org.osgi.framework.BundleEvent; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventAdmin; >- >-/** >- * @version $Revision: 1.2 $ >- */ >-public class BundleEventAdapter extends EventAdapter { >- // constants for Event topic substring >- public static final String HEADER = "org/osgi/framework/BundleEvent"; >- public static final String INSTALLED = "INSTALLED"; >- public static final String STOPPED = "STOPPED"; >- public static final String STARTED = "STARTED"; >- public static final String UPDATED = "UPDATED"; >- public static final String UNINSTALLED = "UNINSTALLED"; >- public static final String RESOLVED = "RESOLVED"; >- public static final String UNRESOLVED = "UNRESOLVED"; >- private BundleEvent event; >- >- public BundleEventAdapter(BundleEvent event, EventAdmin eventAdmin) { >- super(eventAdmin); >- this.event = event; >- } >- >- /** >- * @return event >- * @see org.eclipse.equinox.event.mapper.EventAdapter#convert() >- */ >- public Event convert() { >- String typename = null; >- switch (event.getType()) { >- case BundleEvent.INSTALLED : >- typename = INSTALLED; >- break; >- case BundleEvent.STOPPED : >- typename = STOPPED; >- break; >- case BundleEvent.STARTED : >- typename = STARTED; >- break; >- case BundleEvent.UPDATED : >- typename = UPDATED; >- break; >- case BundleEvent.UNINSTALLED : >- typename = UNINSTALLED; >- break; >- case BundleEvent.RESOLVED : >- typename = RESOLVED; >- break; >- case BundleEvent.UNRESOLVED : >- typename = UNRESOLVED; >- break; >- default : >- // unknown events must be send as their decimal value >- typename = "" + event.getType(); >- } >- String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >- Hashtable properties = new Hashtable(); >- Bundle bundle = event.getBundle(); >- if (bundle == null) { >- throw new RuntimeException("BundleEvent.getBundle() returns null"); >- } else { >- putBundleProperties(properties, bundle); >- } >- properties.put(Constants.EVENT, event); >- Event converted = new Event(topic, properties); >- return converted; >- } >-} >\ No newline at end of file >Index: src/org/eclipse/equinox/event/EventAdminImpl.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/EventAdminImpl.java >diff -N src/org/eclipse/equinox/event/EventAdminImpl.java >--- src/org/eclipse/equinox/event/EventAdminImpl.java 13 Jul 2007 14:41:19 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,156 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation. >- * 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event; >- >-import java.security.Permission; >-import java.util.Iterator; >-import java.util.Set; >-import org.eclipse.osgi.framework.eventmgr.*; >-import org.eclipse.osgi.util.NLS; >-import org.osgi.framework.BundleContext; >-import org.osgi.service.event.*; >-import org.osgi.service.log.LogService; >- >-/** >- * Implementation of org.osgi.service.event.EventAdmin. EventAdminImpl uses >- * org.eclipse.osgi.framework.eventmgr.EventManager. It is assumeed >- * org.eclipse.osgi.framework.eventmgr package is exported by some other bundle. >- */ >-public class EventAdminImpl implements EventAdmin { >- private final LogTracker log; >- private final EventHandlerTracker handlers; >- private volatile EventManager eventManager; >- >- /** >- * Constructor for EventAdminImpl. >- * >- * @param context BundleContext >- */ >- EventAdminImpl(BundleContext context) { >- super(); >- log = new LogTracker(context, System.out); >- handlers = new EventHandlerTracker(context, log); >- } >- >- /** >- * This method should be called before registering EventAdmin service >- */ >- void start() { >- log.open(); >- ThreadGroup eventGroup = new ThreadGroup("Equinox Event Admin"); //$NON-NLS-1$ >- eventGroup.setDaemon(true); >- eventManager = new EventManager(EventAdminMsg.EVENT_ASYNC_THREAD_NAME, eventGroup); >- handlers.open(); >- } >- >- /** >- * This method should be called after unregistering EventAdmin service >- */ >- void stop() { >- handlers.close(); >- eventManager.close(); >- eventManager = null; // signify we have stopped >- log.close(); >- } >- >- /** >- * @param event >- * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event) >- */ >- public void postEvent(Event event) { >- dispatchEvent(event, true); >- } >- >- /** >- * @param event >- * @see org.osgi.service.event.EventAdmin#sendEvent(org.osgi.service.event.Event) >- */ >- public void sendEvent(Event event) { >- dispatchEvent(event, false); >- } >- >- /** >- * Internal main method for sendEvent() and postEvent(). Dispatching an >- * event to EventHandler. All exceptions are logged except when dealing with >- * LogEntry. >- * >- * @param event to be delivered >- * @param isAsync must be set to true for syncronous event delivery, false >- * for asyncronous delivery. >- */ >- private void dispatchEvent(Event event, boolean isAsync) { >- // keep a local copy in case we are stopped in the middle of dispatching >- EventManager currentManager = eventManager; >- if (currentManager == null) { >- // EventAdmin is stopped >- return; >- } >- if (event == null) { >- log.log(LogService.LOG_ERROR, EventAdminMsg.EVENT_NULL_EVENT); >- // continue from here will result in an NPE below; the spec for EventAdmin does not allow for null here >- } >- >- String topic = event.getTopic(); >- >- try { >- checkTopicPermissionPublish(topic); >- } catch (SecurityException e) { >- String msg = NLS.bind(EventAdminMsg.EVENT_NO_TOPICPERMISSION_PUBLISH, event.getTopic()); >- log.log(LogService.LOG_ERROR, msg); >- // must throw a security exception here according to the EventAdmin spec >- throw e; >- } >- >- Set eventHandlers = handlers.getHandlers(topic); >- // If there are no handlers, then we are done >- if (eventHandlers.size() == 0) { >- return; >- } >- >- SecurityManager sm = System.getSecurityManager(); >- Permission perm = (sm == null) ? null : new TopicPermission(topic, TopicPermission.SUBSCRIBE); >- >- EventListeners listeners = new EventListeners(); >- Iterator iter = eventHandlers.iterator(); >- while (iter.hasNext()) { >- EventHandlerWrapper wrapper = (EventHandlerWrapper) iter.next(); >- listeners.addListener(wrapper, perm); >- } >- >- // Create the listener queue for this event delivery >- ListenerQueue listenerQueue = new ListenerQueue(currentManager); >- // Add the listeners to the queue and associate them with the event >- // dispatcher >- listenerQueue.queueListeners(listeners, handlers); >- // Deliver the event to the listeners. >- if (isAsync) { >- listenerQueue.dispatchEventAsynchronous(0, event); >- } >- else { >- listenerQueue.dispatchEventSynchronous(0, event); >- } >- } >- >- /** >- * Checks if the caller bundle has right PUBLISH TopicPermision. >- * >- * @param topic >- * @throws SecurityException if the caller does not have the right to PUBLISH TopicPermission >- */ >- private void checkTopicPermissionPublish(String topic) throws SecurityException{ >- SecurityManager sm = System.getSecurityManager(); >- if (sm == null) >- return; >- sm.checkPermission(new TopicPermission(topic, TopicPermission.PUBLISH)); >- } >- >-} >Index: src/org/eclipse/equinox/event/EventHandlerTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/EventHandlerTracker.java >diff -N src/org/eclipse/equinox/event/EventHandlerTracker.java >--- src/org/eclipse/equinox/event/EventHandlerTracker.java 24 Oct 2007 16:47:31 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,200 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event; >- >-import java.security.Permission; >-import java.util.*; >-import org.eclipse.osgi.framework.eventmgr.EventDispatcher; >-import org.osgi.framework.BundleContext; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventHandler; >-import org.osgi.service.log.LogService; >-import org.osgi.util.tracker.ServiceTracker; >- >-public class EventHandlerTracker extends ServiceTracker implements EventDispatcher { >- private final LogService log; >- //* List<EventHandlerWrapper> of all handlers with topic of "*" >- private final List globalWildcard; >- // Map<String,List<EventHandlerWrapper>> key is topic prefix of partial wildcard >- private final Map partialWildcard; >- // Map<String,List<EventHandlerWrapper>> key is topic name >- private final Map topicName; >- >- public EventHandlerTracker(BundleContext context, LogService log) { >- super(context, EventHandler.class.getName(), null); >- this.log = log; >- globalWildcard = new ArrayList(); >- partialWildcard = new HashMap(); >- topicName = new HashMap(); >- } >- >- public Object addingService(ServiceReference reference) { >- EventHandlerWrapper wrapper = new EventHandlerWrapper(reference, context, log); >- synchronized (this) { >- if (wrapper.init()) { >- bucket(wrapper); >- } >- } >- return wrapper; >- } >- >- public void modifiedService(ServiceReference reference, Object service) { >- EventHandlerWrapper wrapper = (EventHandlerWrapper) service; >- synchronized (this) { >- unbucket(wrapper); >- if (wrapper.init()) { >- bucket(wrapper); >- return; >- } >- } >- >- wrapper.flush(); // needs to be called outside sync region >- } >- >- public void removedService(ServiceReference reference, Object service) { >- EventHandlerWrapper wrapper = (EventHandlerWrapper) service; >- synchronized (this) { >- unbucket(wrapper); >- } >- wrapper.flush(); // needs to be called outside sync region >- } >- >- /** >- * Place the wrapper into the appropriate buckets. >- * This is a performance optimization for event delivery. >- * >- * @param wrapper The wrapper to place in buckets. >- * @GuardedBy this >- */ >- private void bucket(EventHandlerWrapper wrapper) { >- final String[] topics = wrapper.getTopics(); >- final int length = (topics == null) ? 0 : topics.length; >- for (int i = 0; i < length; i++) { >- String topic = topics[i]; >- // global wildcard >- if (topic.equals("*")) { //$NON-NLS-1$ >- globalWildcard.add(wrapper); >- } >- // partial wildcard >- else if (topic.endsWith("/*")) { //$NON-NLS-1$ >- String key = topic.substring(0, topic.length() - 2); // Strip off "/*" from the end >- List wrappers = (List) partialWildcard.get(key); >- if (wrappers == null) { >- wrappers = new ArrayList(); >- partialWildcard.put(key, wrappers); >- } >- wrappers.add(wrapper); >- } >- // simple topic name >- else { >- List wrappers = (List) topicName.get(topic); >- if (wrappers == null) { >- wrappers = new ArrayList(); >- topicName.put(topic, wrappers); >- } >- wrappers.add(wrapper); >- } >- } >- } >- >- /** >- * Remove the wrapper from the buckets. >- * >- * @param wrapper The wrapper to remove from the buckets. >- * @GuardedBy this >- */ >- private void unbucket(EventHandlerWrapper wrapper) { >- final String[] topics = wrapper.getTopics(); >- final int length = (topics == null) ? 0 : topics.length; >- for (int i = 0; i < length; i++) { >- String topic = topics[i]; >- // global wilcard >- if (topic.equals("*")) { //$NON-NLS-1$ >- globalWildcard.remove(wrapper); >- } >- // partial wildcard >- else if (topic.endsWith("/*")) { //$NON-NLS-1$ >- String key = topic.substring(0, topic.length() - 2); // Strip off "/*" from the end >- List wrappers = (List) partialWildcard.get(key); >- if (wrappers != null) { >- wrappers.remove(wrapper); >- if (wrappers.size() == 0) { >- partialWildcard.remove(key); >- } >- } >- } >- // simple topic name >- else { >- List wrappers = (List) topicName.get(topic); >- if (wrappers != null) { >- wrappers.remove(wrapper); >- if (wrappers.size() == 0) { >- topicName.remove(topic); >- } >- } >- } >- } >- } >- >- /** >- * Return the set of handlers which subscribe to the event topic. >- * A set is used to ensure a handler is not called for an event more than once. >- * >- * @param topic >- * @return a set of handlers >- */ >- public synchronized Set getHandlers(final String topic) { >- // Use a set to remove duplicates >- Set handlers = new HashSet(); >- >- // Add the "*" handlers >- handlers.addAll(globalWildcard); >- >- // Add the handlers with partial matches >- if (partialWildcard.size() > 0) { >- int index = topic.length(); >- while (index >= 0) { >- String subTopic = topic.substring(0, index); // First subtopic is the complete topic. >- List wrappers = (List) partialWildcard.get(subTopic); >- if (wrappers != null) { >- handlers.addAll(wrappers); >- } >- // Strip the last level from the topic. For example, org/osgi/framework becomes org/osgi. >- // Wildcard topics are inserted into the map with the "/*" stripped off. >- index = subTopic.lastIndexOf('/'); >- } >- } >- >- // Add the handlers for matching topic names >- List wrappers = (List) topicName.get(topic); >- if (wrappers != null) { >- handlers.addAll(wrappers); >- } >- >- return handlers; >- } >- >- /** >- * Dispatches Event to EventHandlers >- * >- * @param eventListener >- * @param listenerObject >- * @param eventAction >- * @param eventObject >- * @see org.eclipse.osgi.framework.eventmgr.EventDispatcher#dispatchEvent(java.lang.Object, >- * java.lang.Object, int, java.lang.Object) >- */ >- public void dispatchEvent(Object eventListener, Object listenerObject, int eventAction, Object eventObject) { >- ((EventHandlerWrapper) eventListener).handleEvent((Event) eventObject, (Permission) listenerObject); >- } >-} >Index: src/org/eclipse/equinox/event/EventHandlerWrapper.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/EventHandlerWrapper.java >diff -N src/org/eclipse/equinox/event/EventHandlerWrapper.java >--- src/org/eclipse/equinox/event/EventHandlerWrapper.java 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,184 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event; >- >-import java.security.Permission; >-import org.eclipse.osgi.util.NLS; >-import org.osgi.framework.*; >-import org.osgi.service.event.*; >-import org.osgi.service.log.LogService; >- >-/** >- * A wrapper for EventHandlers. This class caches property values and >- * performs final checks before calling the wrapped handler. >- * >- */ >-public class EventHandlerWrapper { >- private final ServiceReference reference; >- private final LogService log; >- private final BundleContext context; >- private EventHandler handler; >- private String[] topics; >- private Filter filter; >- >- /** >- * Create an EventHandlerWrapper. >- >- * @param reference Reference to the EventHandler >- * @param context Bundle Context of the Event Admin bundle >- * @param log LogService object for logging >- */ >- public EventHandlerWrapper(ServiceReference reference, BundleContext context, LogService log) { >- this.reference = reference; >- this.context = context; >- this.log = log; >- } >- >- /** >- * Cache values from service properties >- * >- * @return true if the handler should be called; false if the handler should not be called >- */ >- public synchronized boolean init() { >- topics = null; >- filter = null; >- >- // Get topic names >- Object o = reference.getProperty(EventConstants.EVENT_TOPIC); >- if (o instanceof String) { >- topics = new String[] {(String)o}; >- } >- else if (o instanceof String[]) { >- topics = (String[]) o; >- } >- >- if (topics == null) { >- return false; >- } >- >- // get filter >- o = reference.getProperty(EventConstants.EVENT_FILTER); >- if (o instanceof String) { >- try { >- filter = context.createFilter((String)o); >- } >- catch (InvalidSyntaxException e) { >- log.log(LogService.LOG_ERROR,NLS.bind(EventAdminMsg.EVENT_INVALID_HANDLER_FILTER, o), e); >- return false; >- } >- } >- >- return true; >- } >- >- /** >- * Flush the handler service if it has been obtained. >- */ >- public void flush() { >- synchronized (this) { >- if (handler == null) { >- return; >- } >- handler = null; >- } >- context.ungetService(reference); >- } >- >- /** >- * Get the event topics for the wrapped handler. >- * >- * @return The wrapped handler's event topics >- */ >- public synchronized String[] getTopics() { >- return topics; >- } >- >- /** >- * Return the wrapped handler. >- * @return The wrapped handler. >- */ >- private EventHandler getHandler() { >- synchronized (this) { >- // if we already have a handler, return it >- if (handler != null) { >- return handler; >- } >- } >- >- // we don't have the handler, so lets get it outside the sync region >- EventHandler tempHandler = (EventHandler)context.getService(reference); >- >- synchronized (this) { >- // do we still need the handler we just got? >- if (handler == null) { >- handler = tempHandler; >- return handler; >- } >- // get the current handler >- tempHandler = handler; >- } >- >- // unget the handler we just got since we don't need it >- context.ungetService(reference); >- >- // return the current handler (copied into the local var) >- return tempHandler; >- } >- >- /** >- * Get the filter object >- * >- * @return The handler's filter >- */ >- private synchronized Filter getFilter() { >- return filter; >- } >- >- /** >- * Dispatch event to handler. Perform final tests before actually calling the handler. >- * >- * @param event The event to dispatch >- * @param perm The permission to be checked >- */ >- public void handleEvent(Event event, Permission perm) { >- Bundle bundle = reference.getBundle(); >- // is service unregistered? >- if (bundle == null) { >- return; >- } >- >- // filter match >- Filter eventFilter = getFilter(); >- if ((eventFilter != null) && !event.matches(eventFilter)) { >- return; >- } >- >- // permission check >- if ((perm != null) && (!bundle.hasPermission(perm))) { >- return; >- } >- >- // get handler service >- EventHandler handlerService = getHandler(); >- if (handlerService == null) { >- return; >- } >- >- try { >- handlerService.handleEvent(event); >- } >- catch (Throwable t) { >- // log/handle any Throwable thrown by the listener >- log.log(LogService.LOG_ERROR, NLS.bind(EventAdminMsg.EVENT_DISPATCH_HANDLER_EXCEPTION, event, handlerService), t); >- } >- } >-} >Index: src/org/eclipse/equinox/event/LogMessages.properties >=================================================================== >RCS file: src/org/eclipse/equinox/event/LogMessages.properties >diff -N src/org/eclipse/equinox/event/LogMessages.properties >--- src/org/eclipse/equinox/event/LogMessages.properties 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,17 +0,0 @@ >-############################################################################### >-# Copyright (c) 2005, 2006 IBM Corporation 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: >-# IBM Corporation - initial API and implementation >-############################################################################### >-# NLS_MESSAGEFORMAT_ALL >- >-Unknown_Log_level=Unknown Log Level >-Info=Log Info >-Warning=Log Warning >-Error=Log Error >-Debug=Log Debug >Index: src/org/eclipse/equinox/event/EventAdminMsg.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/EventAdminMsg.java >diff -N src/org/eclipse/equinox/event/EventAdminMsg.java >--- src/org/eclipse/equinox/event/EventAdminMsg.java 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,29 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 1999, 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event; >- >-import org.eclipse.osgi.util.NLS; >- >-public class EventAdminMsg extends NLS { >- private static final String BUNDLE_NAME = "org.eclipse.equinox.event.ExternalMessages"; //$NON-NLS-1$ >- >- public static String EVENT_ASYNC_THREAD_NAME; >- public static String EVENT_NULL_EVENT; >- public static String EVENT_NO_TOPICPERMISSION_PUBLISH; >- public static String EVENT_DISPATCH_HANDLER_EXCEPTION; >- public static String EVENT_INVALID_HANDLER_FILTER; >- >- static { >- // initialize resource bundles >- NLS.initializeMessages(BUNDLE_NAME, EventAdminMsg.class); >- } >-} >Index: src/org/eclipse/equinox/event/Activator.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/Activator.java >diff -N src/org/eclipse/equinox/event/Activator.java >--- src/org/eclipse/equinox/event/Activator.java 16 May 2007 14:13:11 -0000 1.5 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,36 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.equinox.event; >- >-import org.eclipse.equinox.event.mapper.EventRedeliverer; >-import org.osgi.framework.*; >- >-public class Activator implements BundleActivator { >- private EventRedeliverer eventRedeliverer; >- private ServiceRegistration eventAdminService; >- private EventAdminImpl eventAdmin; >- >- public void start(BundleContext bundleContext) { >- eventAdmin = new EventAdminImpl(bundleContext); >- eventAdmin.start(); >- eventAdminService = bundleContext.registerService("org.osgi.service.event.EventAdmin", //$NON-NLS-1$ >- eventAdmin,null); >- eventRedeliverer = new EventRedeliverer(bundleContext); >- eventRedeliverer.open(); >- } >- >- public void stop(BundleContext bundleContext) { >- eventRedeliverer.close(); >- eventAdminService.unregister(); >- eventAdmin.stop(); >- } >-} >Index: src/org/eclipse/equinox/event/LogTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/LogTracker.java >diff -N src/org/eclipse/equinox/event/LogTracker.java >--- src/org/eclipse/equinox/event/LogTracker.java 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,174 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 1998, 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event; >- >-import java.io.PrintStream; >-import java.util.Calendar; >-import java.util.Date; >- >-import org.osgi.framework.BundleContext; >-import org.osgi.framework.ServiceReference; >-import org.osgi.service.log.LogService; >-import org.osgi.util.tracker.ServiceTracker; >- >-/** >- * LogTracker class. This class encapsulates the LogService >- * and handles all issues such as the service coming and going. >- */ >- >-public class LogTracker extends ServiceTracker implements LogService { >- /** LogService interface class name */ >- protected final static String clazz = "org.osgi.service.log.LogService"; //$NON-NLS-1$ >- >- /** PrintStream to use if LogService is unavailable */ >- private final PrintStream out; >- >- /** >- * Create new LogTracker. >- * >- * @param context BundleContext of parent bundle. >- * @param out Default PrintStream to use if LogService is unavailable. >- */ >- public LogTracker(BundleContext context, PrintStream out) { >- super(context, clazz, null); >- this.out = out; >- } >- >- /* >- * ---------------------------------------------------------------------- >- * LogService Interface implementation >- * ---------------------------------------------------------------------- >- */ >- >- public void log(int level, String message) { >- log(null, level, message, null); >- } >- >- public void log(int level, String message, Throwable exception) { >- log(null, level, message, exception); >- } >- >- public void log(ServiceReference reference, int level, String message) { >- log(reference, level, message, null); >- } >- >- public synchronized void log(ServiceReference reference, int level, String message, Throwable exception) { >- ServiceReference[] references = getServiceReferences(); >- >- if (references != null) { >- int size = references.length; >- >- for (int i = 0; i < size; i++) { >- LogService service = (LogService) getService(references[i]); >- if (service != null) { >- try { >- service.log(reference, level, message, exception); >- } catch (Exception e) { >- // TODO: consider printing to System Error >- } >- } >- } >- >- return; >- } >- >- noLogService(level, message, exception, reference); >- } >- >- /** >- * The LogService is not available so we write the message to a PrintStream. >- * >- * @param level Logging level >- * @param message Log message. >- * @param throwable Log exception or null if none. >- * @param reference ServiceReference associated with message or null if none. >- */ >- protected void noLogService(int level, String message, Throwable throwable, ServiceReference reference) { >- if (out != null) { >- synchronized (out) { >- // Bug #113286. If no log service present and messages are being >- // printed to stdout, prepend message with a timestamp. >- String timestamp = getDate(new Date()); >- out.print(timestamp + " "); //$NON-NLS-1$ >- >- switch (level) { >- case LOG_DEBUG : { >- out.print(LogTrackerMsg.Debug); >- >- break; >- } >- case LOG_INFO : { >- out.print(LogTrackerMsg.Info); >- >- break; >- } >- case LOG_WARNING : { >- out.print(LogTrackerMsg.Warning); >- >- break; >- } >- case LOG_ERROR : { >- out.print(LogTrackerMsg.Error); >- >- break; >- } >- default : { >- out.print("["); //$NON-NLS-1$ >- out.print(LogTrackerMsg.Unknown_Log_level); >- out.print("]: "); //$NON-NLS-1$ >- >- break; >- } >- } >- >- out.println(message); >- >- if (reference != null) { >- out.println(reference); >- } >- >- if (throwable != null) { >- throwable.printStackTrace(out); >- } >- } >- } >- } >- >- // from EclipseLog to avoid using DateFormat -- see bug 149892#c10 >- private String getDate(Date date) { >- Calendar c = Calendar.getInstance(); >- c.setTime(date); >- StringBuffer sb = new StringBuffer(); >- appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-'); >- appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-'); >- appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' '); >- appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':'); >- appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':'); >- appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.'); >- appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb); >- return sb.toString(); >- } >- >- private StringBuffer appendPaddedInt(int value, int pad, StringBuffer buffer) { >- pad = pad - 1; >- if (pad == 0) >- return buffer.append(Integer.toString(value)); >- int padding = (int) Math.pow(10, pad); >- if (value >= padding) >- return buffer.append(Integer.toString(value)); >- while (padding > value && padding > 1) { >- buffer.append('0'); >- padding = padding / 10; >- } >- buffer.append(value); >- return buffer; >- } >-} >Index: src/org/eclipse/equinox/event/LogTrackerMsg.java >=================================================================== >RCS file: src/org/eclipse/equinox/event/LogTrackerMsg.java >diff -N src/org/eclipse/equinox/event/LogTrackerMsg.java >--- src/org/eclipse/equinox/event/LogTrackerMsg.java 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,28 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation 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: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.equinox.event; >- >-import org.eclipse.osgi.util.NLS; >- >-public class LogTrackerMsg extends NLS { >- private static final String BUNDLE_NAME = "org.eclipse.equinox.event.LogMessages"; //$NON-NLS-1$ >- >- public static String Unknown_Log_level; >- public static String Info; >- public static String Warning; >- public static String Error; >- public static String Debug; >- >- static { >- // initialize resource bundles >- NLS.initializeMessages(BUNDLE_NAME, LogTrackerMsg.class); >- } >-} >Index: src/org/eclipse/equinox/event/ExternalMessages.properties >=================================================================== >RCS file: src/org/eclipse/equinox/event/ExternalMessages.properties >diff -N src/org/eclipse/equinox/event/ExternalMessages.properties >--- src/org/eclipse/equinox/event/ExternalMessages.properties 16 May 2007 14:13:11 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,17 +0,0 @@ >-############################################################################### >-# Copyright (c) 2007 IBM Corporation 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: >-# IBM Corporation - initial API and implementation >-############################################################################### >-# NLS_MESSAGEFORMAT_ALL >- >-EVENT_ASYNC_THREAD_NAME=EventAdmin Async Event Dispatcher Thread >-EVENT_NULL_EVENT=Null event is passed to EventAdmin. Ignored. >-EVENT_NO_TOPICPERMISSION_PUBLISH=Caller bundle doesn't have TopicPermission to publish topic {0} >-EVENT_DISPATCH_HANDLER_EXCEPTION=Exception while dispatching event {0} to handler {1} >-EVENT_INVALID_HANDLER_FILTER=Invalid handler filter {0} >\ No newline at end of file >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox.event/META-INF/MANIFEST.MF,v >retrieving revision 1.6 >diff -u -r1.6 MANIFEST.MF >--- META-INF/MANIFEST.MF 13 Jul 2007 14:41:19 -0000 1.6 >+++ META-INF/MANIFEST.MF 9 Nov 2007 03:33:04 -0000 >@@ -1,22 +1,17 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %bundleName >-Bundle-Version: 1.0.200.qualifier >+Bundle-Version: 1.1.0.qualifier > Bundle-SymbolicName: org.eclipse.equinox.event >-Bundle-Activator: org.eclipse.equinox.event.Activator >+Bundle-Activator: org.eclipse.equinox.internal.event.Activator > Bundle-Copyright: %bundleCopyright > Import-Package: org.eclipse.osgi.framework.eventmgr;version="1.1.0", > org.eclipse.osgi.util, > org.osgi.framework, >- org.osgi.service.cm, > org.osgi.service.event, > org.osgi.service.log, >- org.osgi.service.upnp, >- org.osgi.service.useradmin, >- org.osgi.service.wireadmin, > org.osgi.util.tracker >-Export-Package: org.eclipse.equinox.event; x-internal:=true, >- org.eclipse.equinox.event.mapper; x-internal:=true >+Export-Package: org.eclipse.equinox.internal.event;x-internal:=true, >+ org.eclipse.equinox.internal.event.mapper;x-internal:=true > Bundle-Vendor: %bundleVendor >-Export-Service: org.osgi.service.event.EventAdmin > Bundle-Localization: plugin > Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.1 >Index: src/org/eclipse/equinox/internal/event/ExternalMessages.properties >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/ExternalMessages.properties >diff -N src/org/eclipse/equinox/internal/event/ExternalMessages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/ExternalMessages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+############################################################################### >+# Copyright (c) 2007 IBM Corporation 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: >+# IBM Corporation - initial API and implementation >+############################################################################### >+# NLS_MESSAGEFORMAT_ALL >+ >+EVENT_ASYNC_THREAD_NAME=EventAdmin Async Event Dispatcher Thread >+EVENT_NULL_EVENT=Null event is passed to EventAdmin. Ignored. >+EVENT_NO_TOPICPERMISSION_PUBLISH=Caller bundle doesn't have TopicPermission to publish topic {0} >+EVENT_DISPATCH_HANDLER_EXCEPTION=Exception while dispatching event {0} to handler {1} >+EVENT_INVALID_HANDLER_FILTER=Invalid handler filter {0} >Index: src/org/eclipse/equinox/internal/event/mapper/EventCourier.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/EventCourier.java >diff -N src/org/eclipse/equinox/internal/event/mapper/EventCourier.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/EventCourier.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,183 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import org.osgi.framework.*; >+import org.osgi.service.event.EventAdmin; >+import org.osgi.service.log.*; >+import org.osgi.util.tracker.ServiceTracker; >+ >+/** >+ * Main class for redeliver special events like FrameworkEvents via EventAdmin. >+ * >+ * @version $Revision: 1.1 $ >+ */ >+public class EventCourier implements FrameworkListener, BundleListener, ServiceListener, LogListener, LogReaderServiceListener { >+ private ServiceTracker eventAdminTracker; >+ private LogReaderServiceTracker logTracker; >+ private LogReaderService reader; >+ private final static boolean DEBUG = false; >+ private BundleContext bc; >+ private ServiceRegistration configurationListenerReg; >+ private ServiceRegistration wireAdminListenerReg; >+ private ServiceRegistration upnpEventListenerReg; >+ private ServiceRegistration userAdminListenerReg; >+ >+ public EventCourier(BundleContext bc) { >+ this.bc = bc; >+ } >+ >+ public void close() { >+ if (logTracker != null) { >+ logTracker.close(); >+ logTracker = null; >+ } >+ if (eventAdminTracker != null) { >+ eventAdminTracker.close(); >+ eventAdminTracker = null; >+ } >+ if (reader != null) { >+ reader.removeLogListener(this); >+ } >+ reader = null; >+ bc.removeFrameworkListener(this); >+ bc.removeBundleListener(this); >+ bc.removeServiceListener(this); >+ if (configurationListenerReg != null) { >+ configurationListenerReg.unregister(); >+ configurationListenerReg = null; >+ } >+ if (wireAdminListenerReg != null) { >+ wireAdminListenerReg.unregister(); >+ wireAdminListenerReg = null; >+ } >+ if (upnpEventListenerReg != null) { >+ upnpEventListenerReg.unregister(); >+ upnpEventListenerReg = null; >+ } >+ if (userAdminListenerReg != null) { >+ userAdminListenerReg.unregister(); >+ userAdminListenerReg = null; >+ } >+ } >+ >+ /** >+ * prepare any service trackers and register event listeners which are >+ * necessary to obtain events to be mapped >+ */ >+ public void open() { >+ // open ServiceTracker for EventAdmin >+ eventAdminTracker = new ServiceTracker(bc, EventAdmin.class.getName(), null); >+ eventAdminTracker.open(); >+ // open ServiceTracker for LogReaderService >+ logTracker = new LogReaderServiceTracker(bc, this); >+ logTracker.open(); >+ // add legacy event listener for framework level event >+ bc.addFrameworkListener(this); >+ bc.addBundleListener(this); >+ bc.addServiceListener(this); >+ } >+ >+ private EventAdmin getEventAdmin() { >+ if (eventAdminTracker == null) >+ return null; >+ return (EventAdmin) eventAdminTracker.getService(); >+ } >+ >+ /** >+ * @param event >+ * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent) >+ */ >+ public void frameworkEvent(FrameworkEvent event) { >+ EventAdmin eventAdmin = getEventAdmin(); >+ if (eventAdmin != null) { >+ (new FrameworkEventAdapter(event, eventAdmin)).redeliver(); >+ } else { >+ printNoEventAdminError(); >+ } >+ } >+ >+ private void printNoEventAdminError() { >+ if (DEBUG) { >+ System.out.println(this.getClass().getName() + ": Cannot find the EventAdmin."); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * @param event >+ * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent) >+ */ >+ public void bundleChanged(BundleEvent event) { >+ EventAdmin eventAdmin = getEventAdmin(); >+ if (eventAdmin != null) { >+ (new BundleEventAdapter(event, eventAdmin)).redeliver(); >+ } else { >+ printNoEventAdminError(); >+ } >+ } >+ >+ /** >+ * @param event >+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent) >+ */ >+ public void serviceChanged(ServiceEvent event) { >+ EventAdmin eventAdmin = getEventAdmin(); >+ if (eventAdmin != null) { >+ (new ServiceEventAdapter(event, eventAdmin)).redeliver(); >+ } else { >+ printNoEventAdminError(); >+ } >+ } >+ >+ /** >+ * @param entry >+ * @see org.osgi.service.log.LogListener#logged(org.osgi.service.log.LogEntry) >+ */ >+ public void logged(LogEntry entry) { >+ EventAdmin eventAdmin = getEventAdmin(); >+ if (eventAdmin != null) { >+ (new LogEntryAdapter(entry, eventAdmin)).redeliver(); >+ } else { >+ printNoEventAdminError(); >+ } >+ } >+ >+ /** >+ * @param reference >+ * @param service >+ * @see org.eclipse.equinox.internal.event.mapper.LogReaderServiceListener#logReaderServiceAdding(org.osgi.framework.ServiceReference, >+ * org.osgi.service.log.LogReaderService) >+ */ >+ public void logReaderServiceAdding(ServiceReference reference, LogReaderService service) { >+ if (reader != null) { >+ return; >+ } >+ reader = service; >+ reader.addLogListener(this); >+ } >+ >+ /** >+ * @param reference >+ * @param service >+ * @see org.eclipse.equinox.internal.event.mapper.LogReaderServiceListener#logReaderServiceRemoved(org.osgi.framework.ServiceReference, >+ * org.osgi.service.log.LogReaderService) >+ */ >+ public void logReaderServiceRemoved(ServiceReference reference, LogReaderService service) { >+ if ((reader != null) && reader.equals(service)) { >+ reader.removeLogListener(this); >+ reader = null; >+ } >+ // ungetService() will be called after returning to >+ // LogReaderServiceTracker's removedService() method. >+ } >+ >+} >Index: src/org/eclipse/equinox/internal/event/mapper/ServiceEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/ServiceEventAdapter.java >diff -N src/org/eclipse/equinox/internal/event/mapper/ServiceEventAdapter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/ServiceEventAdapter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import java.util.Hashtable; >+import org.osgi.framework.ServiceEvent; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventAdmin; >+ >+/** >+ * @version $Revision: 1.3 $ >+ */ >+public class ServiceEventAdapter extends EventAdapter { >+ // constants for Event topic substring >+ public static final String HEADER = "org/osgi/framework/ServiceEvent"; //$NON-NLS-1$ >+ public static final String UNREGISTERING = "UNREGISTERING"; //$NON-NLS-1$ >+ public static final String MODIFIED = "MODIFIED"; //$NON-NLS-1$ >+ public static final String REGISTERED = "REGISTERED"; //$NON-NLS-1$ >+ private ServiceEvent event; >+ >+ public ServiceEventAdapter(ServiceEvent event, EventAdmin eventAdmin) { >+ super(eventAdmin); >+ this.event = event; >+ } >+ >+ /** >+ * @see org.eclipse.equinox.internal.event.mapper.EventAdapter#convert() >+ */ >+ public Event convert() { >+ String typename = null; >+ switch (event.getType()) { >+ case ServiceEvent.REGISTERED : >+ typename = REGISTERED; >+ break; >+ case ServiceEvent.MODIFIED : >+ typename = MODIFIED; >+ break; >+ case ServiceEvent.UNREGISTERING : >+ typename = UNREGISTERING; >+ break; >+ default : >+ return null; >+ } >+ String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >+ Hashtable properties = new Hashtable(); >+ ServiceReference ref = event.getServiceReference(); >+ if (ref != null) { >+ putServiceReferenceProperties(properties, ref); >+ } >+ properties.put(Constants.EVENT, event); >+ Event converted = new Event(topic, properties); >+ return converted; >+ } >+ >+} >Index: src/org/eclipse/equinox/internal/event/EventAdminImpl.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/EventAdminImpl.java >diff -N src/org/eclipse/equinox/internal/event/EventAdminImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/EventAdminImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,156 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event; >+ >+import java.security.Permission; >+import java.util.Iterator; >+import java.util.Set; >+import org.eclipse.osgi.framework.eventmgr.*; >+import org.eclipse.osgi.util.NLS; >+import org.osgi.framework.BundleContext; >+import org.osgi.service.event.*; >+import org.osgi.service.log.LogService; >+ >+/** >+ * Implementation of org.osgi.service.event.EventAdmin. EventAdminImpl uses >+ * org.eclipse.osgi.framework.eventmgr.EventManager. It is assumeed >+ * org.eclipse.osgi.framework.eventmgr package is exported by some other bundle. >+ */ >+public class EventAdminImpl implements EventAdmin { >+ private final LogTracker log; >+ private final EventHandlerTracker handlers; >+ private volatile EventManager eventManager; >+ >+ /** >+ * Constructor for EventAdminImpl. >+ * >+ * @param context BundleContext >+ */ >+ EventAdminImpl(BundleContext context) { >+ super(); >+ log = new LogTracker(context, System.out); >+ handlers = new EventHandlerTracker(context, log); >+ } >+ >+ /** >+ * This method should be called before registering EventAdmin service >+ */ >+ void start() { >+ log.open(); >+ ThreadGroup eventGroup = new ThreadGroup("Equinox Event Admin"); //$NON-NLS-1$ >+ eventGroup.setDaemon(true); >+ eventManager = new EventManager(EventAdminMsg.EVENT_ASYNC_THREAD_NAME, eventGroup); >+ handlers.open(); >+ } >+ >+ /** >+ * This method should be called after unregistering EventAdmin service >+ */ >+ void stop() { >+ handlers.close(); >+ eventManager.close(); >+ eventManager = null; // signify we have stopped >+ log.close(); >+ } >+ >+ /** >+ * @param event >+ * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event) >+ */ >+ public void postEvent(Event event) { >+ dispatchEvent(event, true); >+ } >+ >+ /** >+ * @param event >+ * @see org.osgi.service.event.EventAdmin#sendEvent(org.osgi.service.event.Event) >+ */ >+ public void sendEvent(Event event) { >+ dispatchEvent(event, false); >+ } >+ >+ /** >+ * Internal main method for sendEvent() and postEvent(). Dispatching an >+ * event to EventHandler. All exceptions are logged except when dealing with >+ * LogEntry. >+ * >+ * @param event to be delivered >+ * @param isAsync must be set to true for syncronous event delivery, false >+ * for asyncronous delivery. >+ */ >+ private void dispatchEvent(Event event, boolean isAsync) { >+ // keep a local copy in case we are stopped in the middle of dispatching >+ EventManager currentManager = eventManager; >+ if (currentManager == null) { >+ // EventAdmin is stopped >+ return; >+ } >+ if (event == null) { >+ log.log(LogService.LOG_ERROR, EventAdminMsg.EVENT_NULL_EVENT); >+ // continue from here will result in an NPE below; the spec for EventAdmin does not allow for null here >+ } >+ >+ String topic = event.getTopic(); >+ >+ try { >+ checkTopicPermissionPublish(topic); >+ } catch (SecurityException e) { >+ String msg = NLS.bind(EventAdminMsg.EVENT_NO_TOPICPERMISSION_PUBLISH, event.getTopic()); >+ log.log(LogService.LOG_ERROR, msg); >+ // must throw a security exception here according to the EventAdmin spec >+ throw e; >+ } >+ >+ Set eventHandlers = handlers.getHandlers(topic); >+ // If there are no handlers, then we are done >+ if (eventHandlers.size() == 0) { >+ return; >+ } >+ >+ SecurityManager sm = System.getSecurityManager(); >+ Permission perm = (sm == null) ? null : new TopicPermission(topic, TopicPermission.SUBSCRIBE); >+ >+ EventListeners listeners = new EventListeners(); >+ Iterator iter = eventHandlers.iterator(); >+ while (iter.hasNext()) { >+ EventHandlerWrapper wrapper = (EventHandlerWrapper) iter.next(); >+ listeners.addListener(wrapper, perm); >+ } >+ >+ // Create the listener queue for this event delivery >+ ListenerQueue listenerQueue = new ListenerQueue(currentManager); >+ // Add the listeners to the queue and associate them with the event >+ // dispatcher >+ listenerQueue.queueListeners(listeners, handlers); >+ // Deliver the event to the listeners. >+ if (isAsync) { >+ listenerQueue.dispatchEventAsynchronous(0, event); >+ } >+ else { >+ listenerQueue.dispatchEventSynchronous(0, event); >+ } >+ } >+ >+ /** >+ * Checks if the caller bundle has right PUBLISH TopicPermision. >+ * >+ * @param topic >+ * @throws SecurityException if the caller does not have the right to PUBLISH TopicPermission >+ */ >+ private void checkTopicPermissionPublish(String topic) throws SecurityException{ >+ SecurityManager sm = System.getSecurityManager(); >+ if (sm == null) >+ return; >+ sm.checkPermission(new TopicPermission(topic, TopicPermission.PUBLISH)); >+ } >+ >+} >Index: src/org/eclipse/equinox/internal/event/EventHandlerWrapper.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/EventHandlerWrapper.java >diff -N src/org/eclipse/equinox/internal/event/EventHandlerWrapper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/EventHandlerWrapper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,184 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event; >+ >+import java.security.Permission; >+import org.eclipse.osgi.util.NLS; >+import org.osgi.framework.*; >+import org.osgi.service.event.*; >+import org.osgi.service.log.LogService; >+ >+/** >+ * A wrapper for EventHandlers. This class caches property values and >+ * performs final checks before calling the wrapped handler. >+ * >+ */ >+public class EventHandlerWrapper { >+ private final ServiceReference reference; >+ private final LogService log; >+ private final BundleContext context; >+ private EventHandler handler; >+ private String[] topics; >+ private Filter filter; >+ >+ /** >+ * Create an EventHandlerWrapper. >+ >+ * @param reference Reference to the EventHandler >+ * @param context Bundle Context of the Event Admin bundle >+ * @param log LogService object for logging >+ */ >+ public EventHandlerWrapper(ServiceReference reference, BundleContext context, LogService log) { >+ this.reference = reference; >+ this.context = context; >+ this.log = log; >+ } >+ >+ /** >+ * Cache values from service properties >+ * >+ * @return true if the handler should be called; false if the handler should not be called >+ */ >+ public synchronized boolean init() { >+ topics = null; >+ filter = null; >+ >+ // Get topic names >+ Object o = reference.getProperty(EventConstants.EVENT_TOPIC); >+ if (o instanceof String) { >+ topics = new String[] {(String)o}; >+ } >+ else if (o instanceof String[]) { >+ topics = (String[]) o; >+ } >+ >+ if (topics == null) { >+ return false; >+ } >+ >+ // get filter >+ o = reference.getProperty(EventConstants.EVENT_FILTER); >+ if (o instanceof String) { >+ try { >+ filter = context.createFilter((String)o); >+ } >+ catch (InvalidSyntaxException e) { >+ log.log(LogService.LOG_ERROR,NLS.bind(EventAdminMsg.EVENT_INVALID_HANDLER_FILTER, o), e); >+ return false; >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Flush the handler service if it has been obtained. >+ */ >+ public void flush() { >+ synchronized (this) { >+ if (handler == null) { >+ return; >+ } >+ handler = null; >+ } >+ context.ungetService(reference); >+ } >+ >+ /** >+ * Get the event topics for the wrapped handler. >+ * >+ * @return The wrapped handler's event topics >+ */ >+ public synchronized String[] getTopics() { >+ return topics; >+ } >+ >+ /** >+ * Return the wrapped handler. >+ * @return The wrapped handler. >+ */ >+ private EventHandler getHandler() { >+ synchronized (this) { >+ // if we already have a handler, return it >+ if (handler != null) { >+ return handler; >+ } >+ } >+ >+ // we don't have the handler, so lets get it outside the sync region >+ EventHandler tempHandler = (EventHandler)context.getService(reference); >+ >+ synchronized (this) { >+ // do we still need the handler we just got? >+ if (handler == null) { >+ handler = tempHandler; >+ return handler; >+ } >+ // get the current handler >+ tempHandler = handler; >+ } >+ >+ // unget the handler we just got since we don't need it >+ context.ungetService(reference); >+ >+ // return the current handler (copied into the local var) >+ return tempHandler; >+ } >+ >+ /** >+ * Get the filter object >+ * >+ * @return The handler's filter >+ */ >+ private synchronized Filter getFilter() { >+ return filter; >+ } >+ >+ /** >+ * Dispatch event to handler. Perform final tests before actually calling the handler. >+ * >+ * @param event The event to dispatch >+ * @param perm The permission to be checked >+ */ >+ public void handleEvent(Event event, Permission perm) { >+ Bundle bundle = reference.getBundle(); >+ // is service unregistered? >+ if (bundle == null) { >+ return; >+ } >+ >+ // filter match >+ Filter eventFilter = getFilter(); >+ if ((eventFilter != null) && !event.matches(eventFilter)) { >+ return; >+ } >+ >+ // permission check >+ if ((perm != null) && (!bundle.hasPermission(perm))) { >+ return; >+ } >+ >+ // get handler service >+ EventHandler handlerService = getHandler(); >+ if (handlerService == null) { >+ return; >+ } >+ >+ try { >+ handlerService.handleEvent(event); >+ } >+ catch (Throwable t) { >+ // log/handle any Throwable thrown by the listener >+ log.log(LogService.LOG_ERROR, NLS.bind(EventAdminMsg.EVENT_DISPATCH_HANDLER_EXCEPTION, event, handlerService), t); >+ } >+ } >+} >Index: src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java >diff -N src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import java.util.Hashtable; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventAdmin; >+ >+/** >+ * @version $Revision: 1.2 $ >+ */ >+public abstract class EventAdapter { >+ final EventAdmin eventAdmin; >+ >+ /** >+ * @param event >+ * @param eventAdmin >+ */ >+ public EventAdapter(EventAdmin eventAdmin) { >+ this.eventAdmin = eventAdmin; >+ } >+ >+ /** >+ * @return event >+ */ >+ public abstract Event convert(); >+ >+ public void redeliver() { >+ Event converted = convert(); >+ if (converted != null) { >+ redeliverInternal(converted); >+ } >+ } >+ >+ /** >+ * subclasses should override this method if it wants to use sendEvent() >+ * instead. >+ */ >+ protected void redeliverInternal(Event converted) { >+ eventAdmin.postEvent(converted); >+ } >+ >+ public void putBundleProperties(Hashtable properties, Bundle bundle) { >+ // assertion bundle != null >+ properties.put(Constants.BUNDLE_ID, new Long(bundle.getBundleId())); >+ String symbolicName = bundle.getSymbolicName(); >+ if (symbolicName != null) { >+ properties.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName); >+ } >+ properties.put(Constants.BUNDLE, bundle); >+ } >+ >+ public void putExceptionProperties(Hashtable properties, Throwable t) { >+ // assertion t != null >+ properties.put(Constants.EXCEPTION, t); >+ properties.put(Constants.EXCEPTION_CLASS, t.getClass().getName()); >+ String message = t.getMessage(); >+ if (message != null) { >+ properties.put(Constants.EXCEPTION_MESSAGE, t.getMessage()); >+ } >+ } >+ >+ public void putServiceReferenceProperties(Hashtable properties, ServiceReference ref) { >+ // assertion ref != null >+ properties.put(Constants.SERVICE, ref); >+ properties.put(Constants.SERVICE_ID, ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)); >+ Object o = ref.getProperty(org.osgi.framework.Constants.SERVICE_PID); >+ if ((o != null) && (o instanceof String)) { >+ properties.put(Constants.SERVICE_PID, o); >+ } >+ Object o2 = ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS); >+ if ((o2 != null) && (o2 instanceof String[])) { >+ properties.put(Constants.SERVICE_OBJECTCLASS, o2); >+ } >+ } >+ >+ /* >+ * Utility function for converting classes into strings >+ */ >+ public String[] classes2strings(Class classes[]) { >+ if ((classes == null) || (classes.length == 0)) >+ return null; >+ String[] strings = new String[classes.length]; >+ for (int i = 0; i < classes.length; i++) { >+ strings[i] = classes[i].getName(); >+ } >+ return strings; >+ } >+} >Index: src/org/eclipse/equinox/internal/event/LogTrackerMsg.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/LogTrackerMsg.java >diff -N src/org/eclipse/equinox/internal/event/LogTrackerMsg.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/LogTrackerMsg.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.event; >+ >+import org.eclipse.osgi.util.NLS; >+ >+public class LogTrackerMsg extends NLS { >+ private static final String BUNDLE_NAME = "org.eclipse.equinox.event.LogMessages"; //$NON-NLS-1$ >+ >+ public static String Unknown_Log_level; >+ public static String Info; >+ public static String Warning; >+ public static String Error; >+ public static String Debug; >+ >+ static { >+ // initialize resource bundles >+ NLS.initializeMessages(BUNDLE_NAME, LogTrackerMsg.class); >+ } >+} >Index: src/org/eclipse/equinox/internal/event/mapper/FrameworkEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/FrameworkEventAdapter.java >diff -N src/org/eclipse/equinox/internal/event/mapper/FrameworkEventAdapter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/FrameworkEventAdapter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,72 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import java.util.Hashtable; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.FrameworkEvent; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventAdmin; >+ >+/** >+ * @version $Revision: 1.2 $ >+ */ >+public class FrameworkEventAdapter extends EventAdapter { >+ // constants for Event topic substring >+ public static final String HEADER = "org/osgi/framework/FrameworkEvent"; //$NON-NLS-1$ >+ public static final String STARTLEVEL_CHANGED = "STARTLEVEL_CHANGED"; //$NON-NLS-1$ >+ public static final String STARTED = "STARTED"; //$NON-NLS-1$ >+ public static final String PACKAGES_REFRESHED = "PACKAGES_REFRESHED"; //$NON-NLS-1$ >+ public static final String ERROR = "ERROR"; //$NON-NLS-1$ >+ protected FrameworkEvent event; >+ >+ public FrameworkEventAdapter(FrameworkEvent event, EventAdmin eventAdmin) { >+ super(eventAdmin); >+ this.event = event; >+ } >+ >+ /** >+ * @see org.eclipse.equinox.internal.event.mapper.EventAdapter#convert() >+ */ >+ public Event convert() { >+ String typename = null; >+ switch (event.getType()) { >+ case FrameworkEvent.ERROR : >+ typename = ERROR; >+ break; >+ case FrameworkEvent.PACKAGES_REFRESHED : >+ typename = PACKAGES_REFRESHED; >+ break; >+ case FrameworkEvent.STARTED : >+ typename = STARTED; >+ break; >+ case FrameworkEvent.STARTLEVEL_CHANGED : >+ typename = STARTLEVEL_CHANGED; >+ break; >+ default : >+ return null; >+ } >+ String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >+ Hashtable properties = new Hashtable(); >+ Bundle bundle = event.getBundle(); >+ if (bundle != null) { >+ putBundleProperties(properties, bundle); >+ } >+ Throwable t = event.getThrowable(); >+ if (t != null) { >+ putExceptionProperties(properties, t); >+ } >+ properties.put(Constants.EVENT, event); >+ Event converted = new Event(topic, properties); >+ return converted; >+ } >+} >Index: src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceTracker.java >diff -N src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceTracker.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceTracker.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,49 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import org.osgi.framework.BundleContext; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.log.LogReaderService; >+import org.osgi.util.tracker.ServiceTracker; >+ >+/** >+ * @version $Revision: 1.1 $ >+ */ >+public class LogReaderServiceTracker extends ServiceTracker { >+ private final LogReaderServiceListener listener; >+ private ServiceReference reference; >+ >+ public LogReaderServiceTracker(BundleContext context, LogReaderServiceListener listener) { >+ super(context, LogReaderService.class.getName(), null); >+ this.listener = listener; >+ } >+ >+ public Object addingService(ServiceReference ref) { >+ Object object = super.addingService(ref); >+ if ((object != null) && (this.reference == null) && (object instanceof LogReaderService)) { >+ this.reference = ref; >+ listener.logReaderServiceAdding(ref, (LogReaderService) object); >+ } >+ return object; >+ } >+ >+ public void removedService(ServiceReference ref, Object service) { >+ if ((service != null) && (this.reference.equals(ref)) && (service instanceof LogReaderService)) { >+ listener.logReaderServiceRemoved(ref, (LogReaderService) service); >+ this.reference = null; >+ } >+ super.removedService(ref, service); >+ //this method calls ungetService() >+ } >+ >+} >Index: src/org/eclipse/equinox/internal/event/LogMessages.properties >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/LogMessages.properties >diff -N src/org/eclipse/equinox/internal/event/LogMessages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/LogMessages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+############################################################################### >+# Copyright (c) 2005, 2006 IBM Corporation 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: >+# IBM Corporation - initial API and implementation >+############################################################################### >+# NLS_MESSAGEFORMAT_ALL >+ >+Unknown_Log_level=Unknown Log Level >+Info=Log Info >+Warning=Log Warning >+Error=Log Error >+Debug=Log Debug >Index: src/org/eclipse/equinox/internal/event/mapper/LogEntryAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/LogEntryAdapter.java >diff -N src/org/eclipse/equinox/internal/event/mapper/LogEntryAdapter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/LogEntryAdapter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import java.util.Hashtable; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventAdmin; >+import org.osgi.service.log.LogEntry; >+import org.osgi.service.log.LogService; >+ >+/** >+ * @version $Revision: 1.2 $ >+ */ >+public class LogEntryAdapter extends EventAdapter { >+ // constants for Event topic substring >+ public static final String TOPIC = "org/osgi/service/log/LogEntry"; //$NON-NLS-1$ >+ // constants for Event properties >+ public static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$ >+ public static final String MESSAGE = "message"; //$NON-NLS-1$ >+ public static final String LOG_LEVEL = "log.level"; //$NON-NLS-1$ >+ public static final String LOG_ENTRY = "log.entry"; //$NON-NLS-1$ >+ private LogEntry entry; >+ >+ public LogEntryAdapter(LogEntry entry, EventAdmin eventAdmin) { >+ super(eventAdmin); >+ this.entry = entry; >+ } >+ >+ /** >+ * @see org.eclipse.equinox.internal.event.mapper.EventAdapter#convert() >+ */ >+ public Event convert() { >+ String topic = TOPIC; >+ int level = entry.getLevel(); >+ switch (level) { >+ case LogService.LOG_ERROR : >+ case LogService.LOG_WARNING : >+ case LogService.LOG_INFO : >+ case LogService.LOG_DEBUG : >+ break; >+ default : >+ // other log levels are represented by their decimal value >+ topic += Constants.TOPIC_SEPARATOR + level; >+ } >+ Hashtable properties = new Hashtable(); >+ Bundle bundle = entry.getBundle(); >+ if (bundle == null) { >+ throw new RuntimeException("LogEntry.getBundle() returns null"); //$NON-NLS-1$ >+ } >+ putBundleProperties(properties, bundle); >+ Throwable t = entry.getException(); >+ if (t != null) { >+ putExceptionProperties(properties, t); >+ } >+ ServiceReference ref = entry.getServiceReference(); >+ if (ref != null) { >+ putServiceReferenceProperties(properties, ref); >+ } >+ properties.put(LOG_ENTRY, entry); >+ properties.put(LOG_LEVEL, new Integer(entry.getLevel())); >+ if (entry.getMessage() != null) >+ properties.put(MESSAGE, entry.getMessage()); >+ properties.put(TIMESTAMP, new Long(entry.getTime())); >+ Event converted = new Event(topic, properties); >+ return converted; >+ } >+ >+} >Index: src/org/eclipse/equinox/internal/event/mapper/BundleEventAdapter.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/BundleEventAdapter.java >diff -N src/org/eclipse/equinox/internal/event/mapper/BundleEventAdapter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/BundleEventAdapter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import java.util.Hashtable; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.BundleEvent; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventAdmin; >+ >+/** >+ * @version $Revision: 1.2 $ >+ */ >+public class BundleEventAdapter extends EventAdapter { >+ // constants for Event topic substring >+ public static final String HEADER = "org/osgi/framework/BundleEvent"; //$NON-NLS-1$ >+ public static final String INSTALLED = "INSTALLED"; //$NON-NLS-1$ >+ public static final String STOPPED = "STOPPED"; //$NON-NLS-1$ >+ public static final String STARTED = "STARTED"; //$NON-NLS-1$ >+ public static final String UPDATED = "UPDATED"; //$NON-NLS-1$ >+ public static final String UNINSTALLED = "UNINSTALLED"; //$NON-NLS-1$ >+ public static final String RESOLVED = "RESOLVED"; //$NON-NLS-1$ >+ public static final String UNRESOLVED = "UNRESOLVED"; //$NON-NLS-1$ >+ private BundleEvent event; >+ >+ public BundleEventAdapter(BundleEvent event, EventAdmin eventAdmin) { >+ super(eventAdmin); >+ this.event = event; >+ } >+ >+ /** >+ * @return event >+ * @see org.eclipse.equinox.internal.event.mapper.EventAdapter#convert() >+ */ >+ public Event convert() { >+ String typename = null; >+ switch (event.getType()) { >+ case BundleEvent.INSTALLED : >+ typename = INSTALLED; >+ break; >+ case BundleEvent.STOPPED : >+ typename = STOPPED; >+ break; >+ case BundleEvent.STARTED : >+ typename = STARTED; >+ break; >+ case BundleEvent.UPDATED : >+ typename = UPDATED; >+ break; >+ case BundleEvent.UNINSTALLED : >+ typename = UNINSTALLED; >+ break; >+ case BundleEvent.RESOLVED : >+ typename = RESOLVED; >+ break; >+ case BundleEvent.UNRESOLVED : >+ typename = UNRESOLVED; >+ break; >+ default : >+ // unknown events must be send as their decimal value >+ typename = Integer.toString(event.getType()); >+ } >+ String topic = HEADER + Constants.TOPIC_SEPARATOR + typename; >+ Hashtable properties = new Hashtable(); >+ Bundle bundle = event.getBundle(); >+ if (bundle == null) { >+ throw new RuntimeException("BundleEvent.getBundle() returns null"); //$NON-NLS-1$ >+ } >+ putBundleProperties(properties, bundle); >+ properties.put(Constants.EVENT, event); >+ Event converted = new Event(topic, properties); >+ return converted; >+ } >+} >Index: src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceListener.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceListener.java >diff -N src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/LogReaderServiceListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,26 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event.mapper; >+ >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.log.LogReaderService; >+ >+/** >+ * @version $Revision: 1.1 $ >+ */ >+public interface LogReaderServiceListener { >+ >+ public void logReaderServiceAdding(ServiceReference reference, LogReaderService service); >+ >+ public void logReaderServiceRemoved(ServiceReference reference, LogReaderService service); >+ >+} >Index: src/org/eclipse/equinox/internal/event/EventAdminMsg.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/EventAdminMsg.java >diff -N src/org/eclipse/equinox/internal/event/EventAdminMsg.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/EventAdminMsg.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 1999, 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event; >+ >+import org.eclipse.osgi.util.NLS; >+ >+public class EventAdminMsg extends NLS { >+ private static final String BUNDLE_NAME = "org.eclipse.equinox.event.ExternalMessages"; //$NON-NLS-1$ >+ >+ public static String EVENT_ASYNC_THREAD_NAME; >+ public static String EVENT_NULL_EVENT; >+ public static String EVENT_NO_TOPICPERMISSION_PUBLISH; >+ public static String EVENT_DISPATCH_HANDLER_EXCEPTION; >+ public static String EVENT_INVALID_HANDLER_FILTER; >+ >+ static { >+ // initialize resource bundles >+ NLS.initializeMessages(BUNDLE_NAME, EventAdminMsg.class); >+ } >+} >Index: src/org/eclipse/equinox/internal/event/LogTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/LogTracker.java >diff -N src/org/eclipse/equinox/internal/event/LogTracker.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/LogTracker.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,174 @@ >+/******************************************************************************* >+ * Copyright (c) 1998, 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.event; >+ >+import java.io.PrintStream; >+import java.util.Calendar; >+import java.util.Date; >+ >+import org.osgi.framework.BundleContext; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.log.LogService; >+import org.osgi.util.tracker.ServiceTracker; >+ >+/** >+ * LogTracker class. This class encapsulates the LogService >+ * and handles all issues such as the service coming and going. >+ */ >+ >+public class LogTracker extends ServiceTracker implements LogService { >+ /** LogService interface class name */ >+ protected final static String clazz = "org.osgi.service.log.LogService"; //$NON-NLS-1$ >+ >+ /** PrintStream to use if LogService is unavailable */ >+ private final PrintStream out; >+ >+ /** >+ * Create new LogTracker. >+ * >+ * @param context BundleContext of parent bundle. >+ * @param out Default PrintStream to use if LogService is unavailable. >+ */ >+ public LogTracker(BundleContext context, PrintStream out) { >+ super(context, clazz, null); >+ this.out = out; >+ } >+ >+ /* >+ * ---------------------------------------------------------------------- >+ * LogService Interface implementation >+ * ---------------------------------------------------------------------- >+ */ >+ >+ public void log(int level, String message) { >+ log(null, level, message, null); >+ } >+ >+ public void log(int level, String message, Throwable exception) { >+ log(null, level, message, exception); >+ } >+ >+ public void log(ServiceReference reference, int level, String message) { >+ log(reference, level, message, null); >+ } >+ >+ public synchronized void log(ServiceReference reference, int level, String message, Throwable exception) { >+ ServiceReference[] references = getServiceReferences(); >+ >+ if (references != null) { >+ int size = references.length; >+ >+ for (int i = 0; i < size; i++) { >+ LogService service = (LogService) getService(references[i]); >+ if (service != null) { >+ try { >+ service.log(reference, level, message, exception); >+ } catch (Exception e) { >+ // TODO: consider printing to System Error >+ } >+ } >+ } >+ >+ return; >+ } >+ >+ noLogService(level, message, exception, reference); >+ } >+ >+ /** >+ * The LogService is not available so we write the message to a PrintStream. >+ * >+ * @param level Logging level >+ * @param message Log message. >+ * @param throwable Log exception or null if none. >+ * @param reference ServiceReference associated with message or null if none. >+ */ >+ protected void noLogService(int level, String message, Throwable throwable, ServiceReference reference) { >+ if (out != null) { >+ synchronized (out) { >+ // Bug #113286. If no log service present and messages are being >+ // printed to stdout, prepend message with a timestamp. >+ String timestamp = getDate(new Date()); >+ out.print(timestamp + " "); //$NON-NLS-1$ >+ >+ switch (level) { >+ case LOG_DEBUG : { >+ out.print(LogTrackerMsg.Debug); >+ >+ break; >+ } >+ case LOG_INFO : { >+ out.print(LogTrackerMsg.Info); >+ >+ break; >+ } >+ case LOG_WARNING : { >+ out.print(LogTrackerMsg.Warning); >+ >+ break; >+ } >+ case LOG_ERROR : { >+ out.print(LogTrackerMsg.Error); >+ >+ break; >+ } >+ default : { >+ out.print("["); //$NON-NLS-1$ >+ out.print(LogTrackerMsg.Unknown_Log_level); >+ out.print("]: "); //$NON-NLS-1$ >+ >+ break; >+ } >+ } >+ >+ out.println(message); >+ >+ if (reference != null) { >+ out.println(reference); >+ } >+ >+ if (throwable != null) { >+ throwable.printStackTrace(out); >+ } >+ } >+ } >+ } >+ >+ // from EclipseLog to avoid using DateFormat -- see bug 149892#c10 >+ private String getDate(Date date) { >+ Calendar c = Calendar.getInstance(); >+ c.setTime(date); >+ StringBuffer sb = new StringBuffer(); >+ appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-'); >+ appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-'); >+ appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' '); >+ appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':'); >+ appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':'); >+ appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.'); >+ appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb); >+ return sb.toString(); >+ } >+ >+ private StringBuffer appendPaddedInt(int value, int pad, StringBuffer buffer) { >+ pad = pad - 1; >+ if (pad == 0) >+ return buffer.append(Integer.toString(value)); >+ int padding = (int) Math.pow(10, pad); >+ if (value >= padding) >+ return buffer.append(Integer.toString(value)); >+ while (padding > value && padding > 1) { >+ buffer.append('0'); >+ padding = padding / 10; >+ } >+ buffer.append(value); >+ return buffer; >+ } >+} >Index: src/org/eclipse/equinox/internal/event/Activator.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/Activator.java >diff -N src/org/eclipse/equinox/internal/event/Activator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/Activator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event; >+ >+import org.eclipse.equinox.internal.event.mapper.EventCourier; >+import org.osgi.framework.*; >+ >+public class Activator implements BundleActivator { >+ private EventCourier eventRedeliverer; >+ private ServiceRegistration eventAdminService; >+ private EventAdminImpl eventAdmin; >+ >+ public void start(BundleContext bundleContext) { >+ eventAdmin = new EventAdminImpl(bundleContext); >+ eventAdmin.start(); >+ eventAdminService = bundleContext.registerService("org.osgi.service.event.EventAdmin", //$NON-NLS-1$ >+ eventAdmin,null); >+ eventRedeliverer = new EventCourier(bundleContext); >+ eventRedeliverer.open(); >+ } >+ >+ public void stop(BundleContext bundleContext) { >+ eventRedeliverer.close(); >+ eventAdminService.unregister(); >+ eventAdmin.stop(); >+ } >+} >Index: src/org/eclipse/equinox/internal/event/mapper/Constants.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/mapper/Constants.java >diff -N src/org/eclipse/equinox/internal/event/mapper/Constants.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/mapper/Constants.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 IBM Corporation. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.event.mapper; >+ >+/** >+ * @version $Revision: 1.1 $ >+ */ >+public interface Constants { >+ // constants for Event common properties; event specific properties are >+ // defined in the corresponding event adapter. >+ public static final String BUNDLE = "bundle"; //$NON-NLS-1$ >+ public static final String BUNDLE_ID = "bundle.id"; //$NON-NLS-1$ >+ public static final String BUNDLE_SYMBOLICNAME = "bundle.symbolicName"; //$NON-NLS-1$ >+ public static final String EVENT = "event"; //$NON-NLS-1$ >+ public static final String EXCEPTION = "exception"; //$NON-NLS-1$ >+ public static final String EXCEPTION_CLASS = "exception.class"; //$NON-NLS-1$ >+ public static final String EXCEPTION_MESSAGE = "exception.message"; //$NON-NLS-1$ >+ public static final String MESSAGE = "message"; //$NON-NLS-1$ >+ public static final String SERVICE = "service"; //$NON-NLS-1$ >+ public static final String SERVICE_ID = "service.id"; //$NON-NLS-1$ >+ public static final String SERVICE_OBJECTCLASS = "service.objectClass"; //$NON-NLS-1$ >+ public static final String SERVICE_PID = "service.pid"; //$NON-NLS-1$ >+ public static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$ >+ public static final char TOPIC_SEPARATOR = '/'; >+} >Index: src/org/eclipse/equinox/internal/event/EventHandlerTracker.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/event/EventHandlerTracker.java >diff -N src/org/eclipse/equinox/internal/event/EventHandlerTracker.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/event/EventHandlerTracker.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,200 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.internal.event; >+ >+import java.security.Permission; >+import java.util.*; >+import org.eclipse.osgi.framework.eventmgr.EventDispatcher; >+import org.osgi.framework.BundleContext; >+import org.osgi.framework.ServiceReference; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventHandler; >+import org.osgi.service.log.LogService; >+import org.osgi.util.tracker.ServiceTracker; >+ >+public class EventHandlerTracker extends ServiceTracker implements EventDispatcher { >+ private final LogService log; >+ //* List<EventHandlerWrapper> of all handlers with topic of "*" >+ private final List globalWildcard; >+ // Map<String,List<EventHandlerWrapper>> key is topic prefix of partial wildcard >+ private final Map partialWildcard; >+ // Map<String,List<EventHandlerWrapper>> key is topic name >+ private final Map topicName; >+ >+ public EventHandlerTracker(BundleContext context, LogService log) { >+ super(context, EventHandler.class.getName(), null); >+ this.log = log; >+ globalWildcard = new ArrayList(); >+ partialWildcard = new HashMap(); >+ topicName = new HashMap(); >+ } >+ >+ public Object addingService(ServiceReference reference) { >+ EventHandlerWrapper wrapper = new EventHandlerWrapper(reference, context, log); >+ synchronized (this) { >+ if (wrapper.init()) { >+ bucket(wrapper); >+ } >+ } >+ return wrapper; >+ } >+ >+ public void modifiedService(ServiceReference reference, Object service) { >+ EventHandlerWrapper wrapper = (EventHandlerWrapper) service; >+ synchronized (this) { >+ unbucket(wrapper); >+ if (wrapper.init()) { >+ bucket(wrapper); >+ return; >+ } >+ } >+ >+ wrapper.flush(); // needs to be called outside sync region >+ } >+ >+ public void removedService(ServiceReference reference, Object service) { >+ EventHandlerWrapper wrapper = (EventHandlerWrapper) service; >+ synchronized (this) { >+ unbucket(wrapper); >+ } >+ wrapper.flush(); // needs to be called outside sync region >+ } >+ >+ /** >+ * Place the wrapper into the appropriate buckets. >+ * This is a performance optimization for event delivery. >+ * >+ * @param wrapper The wrapper to place in buckets. >+ * @GuardedBy this >+ */ >+ private void bucket(EventHandlerWrapper wrapper) { >+ final String[] topics = wrapper.getTopics(); >+ final int length = (topics == null) ? 0 : topics.length; >+ for (int i = 0; i < length; i++) { >+ String topic = topics[i]; >+ // global wildcard >+ if (topic.equals("*")) { //$NON-NLS-1$ >+ globalWildcard.add(wrapper); >+ } >+ // partial wildcard >+ else if (topic.endsWith("/*")) { //$NON-NLS-1$ >+ String key = topic.substring(0, topic.length() - 2); // Strip off "/*" from the end >+ List wrappers = (List) partialWildcard.get(key); >+ if (wrappers == null) { >+ wrappers = new ArrayList(); >+ partialWildcard.put(key, wrappers); >+ } >+ wrappers.add(wrapper); >+ } >+ // simple topic name >+ else { >+ List wrappers = (List) topicName.get(topic); >+ if (wrappers == null) { >+ wrappers = new ArrayList(); >+ topicName.put(topic, wrappers); >+ } >+ wrappers.add(wrapper); >+ } >+ } >+ } >+ >+ /** >+ * Remove the wrapper from the buckets. >+ * >+ * @param wrapper The wrapper to remove from the buckets. >+ * @GuardedBy this >+ */ >+ private void unbucket(EventHandlerWrapper wrapper) { >+ final String[] topics = wrapper.getTopics(); >+ final int length = (topics == null) ? 0 : topics.length; >+ for (int i = 0; i < length; i++) { >+ String topic = topics[i]; >+ // global wilcard >+ if (topic.equals("*")) { //$NON-NLS-1$ >+ globalWildcard.remove(wrapper); >+ } >+ // partial wildcard >+ else if (topic.endsWith("/*")) { //$NON-NLS-1$ >+ String key = topic.substring(0, topic.length() - 2); // Strip off "/*" from the end >+ List wrappers = (List) partialWildcard.get(key); >+ if (wrappers != null) { >+ wrappers.remove(wrapper); >+ if (wrappers.size() == 0) { >+ partialWildcard.remove(key); >+ } >+ } >+ } >+ // simple topic name >+ else { >+ List wrappers = (List) topicName.get(topic); >+ if (wrappers != null) { >+ wrappers.remove(wrapper); >+ if (wrappers.size() == 0) { >+ topicName.remove(topic); >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * Return the set of handlers which subscribe to the event topic. >+ * A set is used to ensure a handler is not called for an event more than once. >+ * >+ * @param topic >+ * @return a set of handlers >+ */ >+ public synchronized Set getHandlers(final String topic) { >+ // Use a set to remove duplicates >+ Set handlers = new HashSet(); >+ >+ // Add the "*" handlers >+ handlers.addAll(globalWildcard); >+ >+ // Add the handlers with partial matches >+ if (partialWildcard.size() > 0) { >+ int index = topic.length(); >+ while (index >= 0) { >+ String subTopic = topic.substring(0, index); // First subtopic is the complete topic. >+ List wrappers = (List) partialWildcard.get(subTopic); >+ if (wrappers != null) { >+ handlers.addAll(wrappers); >+ } >+ // Strip the last level from the topic. For example, org/osgi/framework becomes org/osgi. >+ // Wildcard topics are inserted into the map with the "/*" stripped off. >+ index = subTopic.lastIndexOf('/'); >+ } >+ } >+ >+ // Add the handlers for matching topic names >+ List wrappers = (List) topicName.get(topic); >+ if (wrappers != null) { >+ handlers.addAll(wrappers); >+ } >+ >+ return handlers; >+ } >+ >+ /** >+ * Dispatches Event to EventHandlers >+ * >+ * @param eventListener >+ * @param listenerObject >+ * @param eventAction >+ * @param eventObject >+ * @see org.eclipse.osgi.framework.eventmgr.EventDispatcher#dispatchEvent(java.lang.Object, >+ * java.lang.Object, int, java.lang.Object) >+ */ >+ public void dispatchEvent(Object eventListener, Object listenerObject, int eventAction, Object eventObject) { >+ ((EventHandlerWrapper) eventListener).handleEvent((Event) eventObject, (Permission) listenerObject); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 202278
:
82511
|
82578
|
82702