You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2007/02/12 16:50:05 UTC
svn commit: r506508 - in
/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi:
./ descriptor/
Author: danj
Date: Mon Feb 12 07:50:04 2007
New Revision: 506508
URL: http://svn.apache.org/viewvc?view=rev&rev=506508
Log:
Integrated JDK Logging API with OSGi logging service - code from Barry Atkins as part of our J2ME enablement.
Added:
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogHandler.java
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogListener.java
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiLoggingConfig.java
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiRouterDescriptor.java
Modified:
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/Activator.java
webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiDeploymentDescriptor.java
Modified: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/Activator.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/Activator.java?view=diff&rev=506508&r1=506507&r2=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/Activator.java (original)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/Activator.java Mon Feb 12 07:50:04 2007
@@ -1,20 +1,19 @@
/*=============================================================================*
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
*=============================================================================*/
-
package org.apache.muse.core.platform.osgi;
import org.osgi.framework.BundleActivator;
@@ -22,101 +21,178 @@
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceListener;
+import org.osgi.service.log.LogService;
+import org.osgi.service.log.LogReaderService;
import org.apache.muse.core.platform.osgi.routing.OSGiResourceRouter;
import org.apache.muse.core.platform.osgi.util.OSGiReflectUtilHelper;
/**
-*
-* Activator is the <code>BundleActivator</code> implementation for the Muse Core
-* Bundle. The activator manages the OSGi Service interface to the appropriate IsolationLayer
-* implementation through an instance of the
-* <code>org.apache.muse.core.platform.osgi.ResourceManagementProvider</code> service.
-*
-* @see org.apache.muse.core.platform.osgi.ResourceManagementProvider
-* @author Joel Hawkins (joelh)
-*
-*/
-
-public class Activator implements BundleActivator {
-
- private static final String MANAGEMENT_ENVIRONMENT_FILTER = "(objectclass=org.apache.muse.core.platform.osgi.ResourceManagementProvider)";
-
- private ServiceReference managementServiceRef;
-
- private static Activator activator;
-
- private BundleContext context;
-
- private ResourceManagementProvider provider;
-
- static private class ManagementServiceListener implements ServiceListener {
-
- public void serviceChanged(ServiceEvent event) {
- ServiceReference ref = event.getServiceReference();
- switch (event.getType()) {
- case ServiceEvent.REGISTERED:
- if (activator.managementServiceRef == null) {
- activator.managementServiceRef = event.getServiceReference();
- activator.provider = (ResourceManagementProvider) activator.context
- .getService(activator.managementServiceRef);
- OSGiResourceRouter.getDefault().attachManagementProvider(
- activator.provider);
- }
- break;
- case ServiceEvent.MODIFIED:
- break;
- case ServiceEvent.UNREGISTERING:
- ref = event.getServiceReference();
- if (ref == activator.managementServiceRef) {
- activator.managementServiceRef = null;
- OSGiResourceRouter.getDefault().releaseManagementProvider();
- }
- break;
- }
- }
- }
-
- private ManagementServiceListener managementListener = new ManagementServiceListener();
-
- /**
- * starts the Bundle. The <code>start</code> method attempts to resolve an initial
- * refrence to the <code>ResourceManagementProvider</code> service and attach that
- * service to the <code>OSGiResourceRouter</code> instance. The method also intializes
- * the OSGiReflectUtilHelper instance.
- *
- * @see org.apache.muse.core.platform.osgi.routing.OSGiResourceRouter
- * @see org.apache.muse.core.platform.osgi.util.OSGiReflectUtilHelper
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- activator = this;
- this.context = context;
- try {
- OSGiResourceRouter.getDefault().initialize(context);
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- if ((managementServiceRef = context.getServiceReference("org.apache.muse.core.platform.osgi.ResourceManagementProvider")) != null) {
- activator.provider = (ResourceManagementProvider) activator.context.getService(activator.managementServiceRef);
- OSGiResourceRouter.getDefault().attachManagementProvider(activator.provider);
- }
-
- OSGiReflectUtilHelper.getDefault().initialize(context);
-
- context.addServiceListener(managementListener, MANAGEMENT_ENVIRONMENT_FILTER);
-
- }
-
- /**
- * stops the Bundle and removes any applied listeners
- *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- context.removeBundleListener(OSGiResourceRouter.getDefault());
- context.removeServiceListener(managementListener);
- }
-
+ *
+ * Activator is the <code>BundleActivator</code> implementation for the Muse
+ * Core Bundle. The activator manages the OSGi Service interface to the
+ * appropriate IsolationLayer implementation through an instance of the
+ * <code>org.apache.muse.core.platform.osgi.ResourceManagementProvider</code>
+ * service.
+ *
+ * @see org.apache.muse.core.platform.osgi.ResourceManagementProvider
+ * @author Joel Hawkins (joelh)
+ *
+ */
+
+public class Activator implements BundleActivator
+{
+
+ private static final String MANAGEMENT_ENVIRONMENT_FILTER = "(objectclass=org.apache.muse.core.platform.osgi.ResourceManagementProvider)";
+
+ private static final String LOG_SERVICE_FILTER = "(objectclass=org.osgi.service.log.LogService)";
+
+ private static final String LOG_READER_SERVICE_FILTER = "(objectclass=org.osgi.service.log.LogReaderService)";
+
+ private ServiceReference managementServiceRef;
+
+ private ServiceReference logServiceReference = null;
+
+ private ServiceReference logReaderServiceReference = null;
+
+ private static Activator activator;
+
+ private BundleContext context;
+
+ private ResourceManagementProvider provider;
+
+ static private class ManagementServiceListener implements ServiceListener
+ {
+
+ public void serviceChanged(ServiceEvent event)
+ {
+ ServiceReference ref = event.getServiceReference();
+ switch (event.getType())
+ {
+ case ServiceEvent.REGISTERED:
+ if (activator.managementServiceRef == null)
+ {
+ activator.managementServiceRef = event.getServiceReference();
+ activator.provider = (ResourceManagementProvider) activator.context.getService(activator.managementServiceRef);
+ OSGiResourceRouter.getDefault().attachManagementProvider(activator.provider);
+ }
+ break;
+ case ServiceEvent.MODIFIED:
+ break;
+ case ServiceEvent.UNREGISTERING:
+ ref = event.getServiceReference();
+ if (ref == activator.managementServiceRef)
+ {
+ activator.managementServiceRef = null;
+ OSGiResourceRouter.getDefault().releaseManagementProvider();
+ }
+ break;
+ }
+ }
+ }
+
+ private ManagementServiceListener managementListener = new ManagementServiceListener();
+
+ static private class LogServiceListener implements ServiceListener
+ {
+ private boolean enabled = false;
+
+ public void serviceChanged(ServiceEvent event)
+ {
+ ServiceReference ref = event.getServiceReference();
+ switch (event.getType())
+ {
+ case ServiceEvent.REGISTERED:
+ if (!enabled)
+ {
+ try
+ {
+ activator.logServiceReference = activator.context.getServiceReference("org.osgi.service.log.LogService");
+
+ if (activator.logServiceReference != null)
+ {
+ LogService logService = (LogService) activator.context.getService(activator.logServiceReference);
+ OSGiLogHandler.setLogService(logService);
+ enabled = true;
+ }
+ activator.logReaderServiceReference = activator.context.getServiceReference("org.osgi.service.log.LogReaderService");
+ if (activator.logReaderServiceReference != null)
+ {
+ LogReaderService logReaderService = (LogReaderService) activator.context.getService(activator.logReaderServiceReference);
+ OSGiLogHandler.setLogReaderService(logReaderService);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ break;
+ case ServiceEvent.MODIFIED:
+ break;
+ case ServiceEvent.UNREGISTERING:
+ if (ref == activator.logServiceReference)
+ OSGiLogHandler.setLogService(null);
+
+ if (ref == activator.logReaderServiceReference)
+ OSGiLogHandler.setLogReaderService(null);
+
+ enabled = false;
+ break;
+ }
+
+ }
+
+ }
+
+ private LogServiceListener logListener = new LogServiceListener();
+
+ /**
+ * starts the Bundle. The <code>start</code> method attempts to resolve an
+ * initial refrence to the <code>ResourceManagementProvider</code> service
+ * and attach that service to the <code>OSGiResourceRouter</code>
+ * instance. The method also intializes the OSGiReflectUtilHelper instance.
+ *
+ * @see org.apache.muse.core.platform.osgi.routing.OSGiResourceRouter
+ * @see org.apache.muse.core.platform.osgi.util.OSGiReflectUtilHelper
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception
+ {
+ activator = this;
+ this.context = context;
+ try
+ {
+ OSGiResourceRouter.getDefault().initialize(context);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+
+ if ((managementServiceRef = context.getServiceReference("org.apache.muse.core.platform.osgi.ResourceManagementProvider")) != null)
+ {
+ activator.provider = (ResourceManagementProvider) activator.context.getService(activator.managementServiceRef);
+ OSGiResourceRouter.getDefault().attachManagementProvider(activator.provider);
+ }
+
+ OSGiReflectUtilHelper.getDefault().initialize(context);
+
+ context.addServiceListener(managementListener, MANAGEMENT_ENVIRONMENT_FILTER);
+ context.addServiceListener(logListener, LOG_SERVICE_FILTER);
+ context.addServiceListener(logListener, LOG_READER_SERVICE_FILTER);
+ }
+
+ /**
+ * stops the Bundle and removes any applied listeners
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception
+ {
+ context.removeBundleListener(OSGiResourceRouter.getDefault());
+ context.removeServiceListener(managementListener);
+ context.removeServiceListener(logListener);
+ }
+
}
Added: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogHandler.java?view=auto&rev=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogHandler.java (added)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogHandler.java Mon Feb 12 07:50:04 2007
@@ -0,0 +1,78 @@
+/* =============================================================================*
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ * =============================================================================*/
+
+package org.apache.muse.core.platform.osgi;
+
+import java.io.*;
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+import org.osgi.service.log.*;
+
+/**
+ * @author BarryAtkins
+ */
+
+public class OSGiLogHandler extends Handler
+{
+ private static LogService _logService = null;
+
+ private static LogReaderService _logReaderService = null;
+
+ protected OSGiLogListener _listener = null;
+
+ public OSGiLogHandler(String logfile) throws IOException
+ {
+ _listener = new OSGiLogListener(logfile);
+
+ if (_logReaderService != null)
+ _logReaderService.addLogListener(_listener);
+ }
+
+ public static void setLogService(LogService logService)
+ {
+ _logService = logService;
+ }
+
+ public static void setLogReaderService(LogReaderService logReaderService)
+ {
+ _logReaderService = logReaderService;
+ }
+
+ public void publish(LogRecord record)
+ {
+ if (_logService != null)
+ _logService.log(record.getLevel().intValue(), record.getMessage());
+
+ else
+ _listener.log(record.getLevel(), record.getMessage());
+ }
+
+ public void close()
+ {
+ if (_logReaderService != null)
+ _logReaderService.removeLogListener(_listener);
+
+ _listener.close();
+ }
+
+ public void flush()
+ {
+
+ }
+}
Added: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogListener.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogListener.java?view=auto&rev=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogListener.java (added)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/OSGiLogListener.java Mon Feb 12 07:50:04 2007
@@ -0,0 +1,84 @@
+/* =============================================================================*
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ * =============================================================================*/
+
+package org.apache.muse.core.platform.osgi;
+
+import java.io.*;
+import java.util.Date;
+import java.util.logging.Level;
+
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+
+/**
+ *
+ * @author Barry Atkins
+ *
+ */
+
+public class OSGiLogListener implements LogListener
+{
+ private FileWriter _writer = null;
+
+ public OSGiLogListener(String fileName)
+ throws IOException
+ {
+ _writer = new FileWriter(fileName);
+ }
+
+ public void close()
+ {
+ try
+ {
+ _writer.flush();
+ _writer.close();
+ }
+
+ catch (IOException error)
+ {
+ error.printStackTrace();
+ }
+ }
+
+ public void log(Level level, String message)
+ {
+ log(message);
+ }
+
+ public void log(String message)
+ {
+ try
+ {
+ Date now = new Date();
+
+ _writer.write("[ ");
+ _writer.write(now.toString());
+ _writer.write(" ] ");
+ _writer.write(message);
+ _writer.write('\n');
+ }
+
+ catch (IOException error)
+ {
+ error.printStackTrace();
+ }
+ }
+
+ public void logged(LogEntry entry)
+ {
+ log(entry.getMessage());
+ }
+}
Modified: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiDeploymentDescriptor.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiDeploymentDescriptor.java?view=diff&rev=506508&r1=506507&r2=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiDeploymentDescriptor.java (original)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiDeploymentDescriptor.java Mon Feb 12 07:50:04 2007
@@ -38,7 +38,6 @@
import org.apache.muse.core.descriptor.SerializerDefinition;
import org.apache.muse.core.descriptor.SerializerDescriptor;
import org.apache.muse.core.descriptor.SimpleDeploymentDescriptor;
-import org.apache.muse.core.descriptor.SimpleRouterDescriptor;
import org.apache.muse.core.descriptor.SimpleSerializerDescriptor;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
@@ -229,12 +228,12 @@
/**
* factory method for creating RouterDescriptors
- * @return a <code>SimpleRouterDescriptor</code> instance
+ * @return a <code>OSGiRouterDescriptor</code> instance
*
- * @see SimpleRouterDescriptor
+ * @see OSGiRouterDescriptor
*/
protected RouterDescriptor createRouterDescriptor() {
- return new SimpleRouterDescriptor();
+ return new OSGiRouterDescriptor();
}
/** factory method for creating RouterDefinitions
Added: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiLoggingConfig.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiLoggingConfig.java?view=auto&rev=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiLoggingConfig.java (added)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiLoggingConfig.java Mon Feb 12 07:50:04 2007
@@ -0,0 +1,59 @@
+/*=============================================================================*
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.core.platform.osgi.descriptor;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Handler;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.FileHandler;
+import java.util.logging.SimpleFormatter;
+
+import org.apache.muse.core.descriptor.LoggingConfig;
+import org.apache.muse.core.platform.osgi.OSGiLogHandler;
+
+/**
+ *
+ * @author Barry Atkins
+ *
+ */
+
+public class OSGiLoggingConfig extends LoggingConfig
+{
+ protected Handler createLogHandler(File logFile)
+ {
+ Handler handler = null;
+
+ try
+ {
+ handler = new OSGiLogHandler(logFile.getAbsolutePath());
+ }
+
+ catch (IOException error)
+ {
+ //
+ // what can we do? redirect errors to stderr/console
+ //
+ error.printStackTrace();
+ handler = new ConsoleHandler();
+ }
+
+ handler.setFormatter(new SimpleFormatter());
+ return handler;
+ }
+
+}
Added: webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiRouterDescriptor.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiRouterDescriptor.java?view=auto&rev=506508
==============================================================================
--- webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiRouterDescriptor.java (added)
+++ webservices/muse/trunk/modules/muse-osgi-core/src/org/apache/muse/core/platform/osgi/descriptor/OSGiRouterDescriptor.java Mon Feb 12 07:50:04 2007
@@ -0,0 +1,34 @@
+/*=============================================================================*
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.core.platform.osgi.descriptor;
+
+import org.apache.muse.core.descriptor.SimpleRouterDescriptor;
+import org.apache.muse.core.descriptor.LoggingConfig;
+
+/**
+ *
+ * @author Barry Atkins
+ *
+ */
+
+public class OSGiRouterDescriptor extends SimpleRouterDescriptor
+{
+ protected LoggingConfig createLoggingConfig()
+ {
+ return new OSGiLoggingConfig();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org