diff options
author | Simon Kaegi | 2009-05-19 22:16:59 +0000 |
---|---|---|
committer | Simon Kaegi | 2009-05-19 22:16:59 +0000 |
commit | 6102c093a01c624f3eb18faee53f44a4d85161be (patch) | |
tree | 21cf54aa5918b925a700e71ffffa367331278115 /bundles/org.eclipse.equinox.log | |
parent | b4f2228b0e8a39865a24e27ff4427f94477fb988 (diff) | |
download | rt.equinox.bundles-6102c093a01c624f3eb18faee53f44a4d85161be.tar.gz rt.equinox.bundles-6102c093a01c624f3eb18faee53f44a4d85161be.tar.xz rt.equinox.bundles-6102c093a01c624f3eb18faee53f44a4d85161be.zip |
Bug 276927 [log] does not implement mapping of events
Diffstat (limited to 'bundles/org.eclipse.equinox.log')
-rw-r--r-- | bundles/org.eclipse.equinox.log/src/org/eclipse/equinox/log/internal/Activator.java | 137 |
1 files changed, 133 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.log/src/org/eclipse/equinox/log/internal/Activator.java b/bundles/org.eclipse.equinox.log/src/org/eclipse/equinox/log/internal/Activator.java index 1f3a55c34..ad604b3df 100644 --- a/bundles/org.eclipse.equinox.log/src/org/eclipse/equinox/log/internal/Activator.java +++ b/bundles/org.eclipse.equinox.log/src/org/eclipse/equinox/log/internal/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Cognos Incorporated, IBM Corporation and others + * Copyright (c) 2006, 2009 Cognos Incorporated, 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 @@ -13,7 +13,7 @@ import org.osgi.framework.*; import org.osgi.service.log.LogReaderService; import org.osgi.service.log.LogService; -public class Activator implements BundleActivator { +public class Activator implements BundleActivator, BundleListener, FrameworkListener, ServiceListener { private static final String EVENT_ADMIN_CLASS = "org.osgi.service.event.EventAdmin"; //$NON-NLS-1$ private static final String[] LOGSERVICE_CLASSES = {LogService.class.getName(), ExtendedLogService.class.getName()}; @@ -22,10 +22,14 @@ public class Activator implements BundleActivator { private ServiceRegistration logReaderServiceRegistration; private ServiceRegistration logServiceRegistration; private EventAdminAdapter eventAdminAdapter; + private final ExtendedLogReaderServiceFactory logReaderServiceFactory = new ExtendedLogReaderServiceFactory(); private ExtendedLogServiceFactory logServiceFactory; public void start(BundleContext context) throws Exception { - ExtendedLogReaderServiceFactory logReaderServiceFactory = new ExtendedLogReaderServiceFactory(); + context.addBundleListener(this); + context.addServiceListener(this); + context.addFrameworkListener(this); + if (checkEventAdmin()) { eventAdminAdapter = new EventAdminAdapter(context, logReaderServiceFactory); eventAdminAdapter.start(); @@ -40,13 +44,16 @@ public class Activator implements BundleActivator { logServiceRegistration.unregister(); logServiceRegistration = null; logReaderServiceRegistration.unregister(); + logReaderServiceRegistration = null; logServiceFactory.shutdown(); logServiceFactory = null; if (eventAdminAdapter != null) { eventAdminAdapter.stop(); eventAdminAdapter = null; } - logReaderServiceRegistration = null; + context.removeFrameworkListener(this); + context.removeServiceListener(this); + context.removeBundleListener(this); } private static boolean checkEventAdmin() { @@ -59,4 +66,126 @@ public class Activator implements BundleActivator { } } + /** + * BundleListener.bundleChanged method. + * + */ + public void bundleChanged(BundleEvent event) { + Bundle bundle = event.getBundle(); + if (logReaderServiceFactory.isLoggable(bundle, null, LogService.LOG_INFO)) + logReaderServiceFactory.log(bundle, null, null, LogService.LOG_INFO, getBundleEventTypeName(event.getType()), null); + } + + /** + * ServiceListener.serviceChanged method. + * + */ + public void serviceChanged(ServiceEvent event) { + ServiceReference reference = event.getServiceReference(); + Bundle bundle = reference.getBundle(); + int eventType = event.getType(); + int logType = (eventType == ServiceEvent.MODIFIED) ? LogService.LOG_DEBUG : LogService.LOG_INFO; + if (logReaderServiceFactory.isLoggable(bundle, null, logType)) + logReaderServiceFactory.log(bundle, null, reference, logType, getServiceEventTypeName(eventType), null); + } + + /** + * FrameworkListener.frameworkEvent method. + * + */ + public void frameworkEvent(FrameworkEvent event) { + Bundle bundle = event.getBundle(); + int eventType = event.getType(); + int logType = (eventType == FrameworkEvent.ERROR) ? LogService.LOG_ERROR : LogService.LOG_INFO; + Throwable throwable = (eventType == FrameworkEvent.ERROR) ? event.getThrowable() : null; + if (logReaderServiceFactory.isLoggable(bundle, null, logType)) + logReaderServiceFactory.log(bundle, null, null, logType, getFrameworkEventTypeName(eventType), throwable); + } + + /** + * Convert BundleEvent type to a string. + * + */ + protected static String getBundleEventTypeName(int type) { + switch (type) { + case BundleEvent.INSTALLED : + return ("BundleEvent INSTALLED"); //$NON-NLS-1$ + + case BundleEvent.RESOLVED : + return ("BundleEvent RESOLVED"); //$NON-NLS-1$ + + case BundleEvent.STARTED : + return ("BundleEvent STARTED"); //$NON-NLS-1$ + + case BundleEvent.STARTING : + return ("BundleEvent STARTING"); //$NON-NLS-1$ + + case BundleEvent.STOPPED : + return ("BundleEvent STOPPED"); //$NON-NLS-1$ + + case BundleEvent.STOPPING : + return ("BundleEvent STOPPING"); //$NON-NLS-1$ + + case BundleEvent.UNINSTALLED : + return ("BundleEvent UNINSTALLED"); //$NON-NLS-1$ + + case BundleEvent.UNRESOLVED : + return ("BundleEvent UNRESOLVED"); //$NON-NLS-1$ + + case BundleEvent.UPDATED : + return ("BundleEvent UPDATED"); //$NON-NLS-1$ + + default : + return ("BundleEvent " + Integer.toHexString(type)); //$NON-NLS-1$ + } + } + + /** + * Convert ServiceEvent type to a string. + * + */ + protected static String getServiceEventTypeName(int type) { + switch (type) { + case ServiceEvent.REGISTERED : + return ("ServiceEvent REGISTERED"); //$NON-NLS-1$ + + case ServiceEvent.MODIFIED : + return ("ServiceEvent MODIFIED"); //$NON-NLS-1$ + + case ServiceEvent.UNREGISTERING : + return ("ServiceEvent UNREGISTERING"); //$NON-NLS-1$ + + default : + return ("ServiceEvent " + Integer.toHexString(type)); //$NON-NLS-1$ + } + } + + /** + * Convert FrameworkEvent type to a string. + * + */ + protected static String getFrameworkEventTypeName(int type) { + switch (type) { + case FrameworkEvent.ERROR : + return ("FrameworkEvent ERROR"); //$NON-NLS-1$ + + case FrameworkEvent.INFO : + return ("FrameworkEvent INFO"); //$NON-NLS-1$ + + case FrameworkEvent.PACKAGES_REFRESHED : + return ("FrameworkEvent PACKAGES REFRESHED"); //$NON-NLS-1$ + + case FrameworkEvent.STARTED : + return ("FrameworkEvent STARTED"); //$NON-NLS-1$ + + case FrameworkEvent.STARTLEVEL_CHANGED : + return ("FrameworkEvent STARTLEVEL CHANGED"); //$NON-NLS-1$ + + case FrameworkEvent.WARNING : + return ("FrameworkEvent WARNING"); //$NON-NLS-1$ + + default : + return ("FrameworkEvent " + Integer.toHexString(type)); //$NON-NLS-1$ + } + } } |