summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor')
-rw-r--r--tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/LogLevel.java38
-rw-r--r--tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/MonitorFactory.java35
-rw-r--r--tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/InvalidLevelException.java60
-rw-r--r--tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/JavaLoggingMonitorFactory.java186
-rw-r--r--tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/NullMonitorFactory.java48
5 files changed, 0 insertions, 367 deletions
diff --git a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/LogLevel.java b/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/LogLevel.java
deleted file mode 100644
index 45134c7556..0000000000
--- a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/LogLevel.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.tuscany.common.monitor;
-
-import static java.lang.annotation.ElementType.METHOD;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Target;
-
-/**
- * Annotation that can be applied to methods in a monitoring interface
- * to indicate to logging frameworks the severity of the event.
- *
- * @version $Rev$ $Date$
- */
-@Target({METHOD})
-@Retention(RUNTIME)
-public @interface LogLevel {
-
- /**
- * The log level as specified by {@link java.util.logging.Level}.
- */
- @SuppressWarnings({"JavaDoc"}) String value();
-}
diff --git a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/MonitorFactory.java b/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/MonitorFactory.java
deleted file mode 100644
index aa92092005..0000000000
--- a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/MonitorFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.tuscany.common.monitor;
-
-/**
- * A MonitorFactory creates implementations of components' monitor interfaces
- * that interface with a its monitoring scheme. For example, a implementation
- * may create versions that emit appropriate logging events or which send
- * notifications to a management API.
- *
- * @version $Rev$ $Date$
- */
-public interface MonitorFactory {
- /**
- * Return a monitor for a component's monitor interface.
- *
- * @param monitorInterface the component's monitoring interface
- * @return an implementation of the monitoring interface; will not be null
- */
- <T> T getMonitor(Class<T> monitorInterface);
-}
diff --git a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/InvalidLevelException.java b/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/InvalidLevelException.java
deleted file mode 100644
index baf4e8b7cc..0000000000
--- a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/InvalidLevelException.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.tuscany.common.monitor.impl;
-
-/**
- * Exception indicating an invalid log level has been passed.
- *
- * @version $Rev$ $Date$
- */
-public class InvalidLevelException extends IllegalArgumentException {
- private static final long serialVersionUID = 7767234706427841915L;
- private final String method;
- private final String level;
-
- /**
- * Constructor specifying the method name and the level affected.
- *
- * @param method the name of the method being monitored
- * @param level the invalid log level value
- */
- public InvalidLevelException(String method, String level) {
- super();
- this.method = method;
- this.level = level;
- }
-
- /**
- * Returns the name of the method being monitored.
- * @return the name of the method being monitored
- */
- public String getMethod() {
- return method;
- }
-
- /**
- * Returns the invalid log level specified.
- * @return the invalid log level that was specified
- */
- public String getLevel() {
- return level;
- }
-
- public String getMessage() {
- return "Invalid level for method " + method + " : " + level;
- }
-}
diff --git a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/JavaLoggingMonitorFactory.java b/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/JavaLoggingMonitorFactory.java
deleted file mode 100644
index daef77d4ae..0000000000
--- a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/JavaLoggingMonitorFactory.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.tuscany.common.monitor.impl;
-
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.WeakHashMap;
-import java.util.ResourceBundle;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.logging.LogRecord;
-
-import org.apache.tuscany.common.monitor.LogLevel;
-import org.apache.tuscany.common.monitor.MonitorFactory;
-
-/**
- * A factory for monitors that forwards events to a {@link java.util.logging.Logger Java Logging (JSR47) Logger}.
- *
- * @version $Rev$ $Date$
- * @see java.util.logging
- */
-public class JavaLoggingMonitorFactory implements MonitorFactory {
- private final String bundleName;
- private final Level defaultLevel;
- private final Map<String, Level> levels;
-
- private final Map<Class<?>, WeakReference<?>> proxies = new WeakHashMap<Class<?>, WeakReference<?>>();
-
- /**
- * Construct a MonitorFactory that will monitor the specified methods at the specified levels
- * and generate messages using java.util.logging.
- * <p/>
- * The supplied Properties can be used to specify custom log levels for specific monitor
- * methods. The key should be the method name in form returned by
- * <code>Class.getName() + '#' + Method.getName()</code> and the value the log level to use
- * as defined by {@link java.util.logging.Level}.
- *
- * @param levels definition of custom levels for specific monitored methods
- * @param defaultLevel the default log level to use
- * @param bundleName the name of a resource bundle that will be passed to the logger
- * @see java.util.logging.Logger
- */
- public JavaLoggingMonitorFactory(Properties levels, Level defaultLevel, String bundleName) {
- this.defaultLevel = defaultLevel;
- this.bundleName = bundleName;
- this.levels = new HashMap<String, Level>(levels.size());
- for (Map.Entry<Object, Object> entry : levels.entrySet()) {
- String method = (String) entry.getKey();
- String level = (String) entry.getValue();
- try {
- this.levels.put(method, Level.parse(level));
- } catch (IllegalArgumentException e) {
- throw new InvalidLevelException(method, level);
- }
- }
- }
-
- public synchronized <T> T getMonitor(Class<T> monitorInterface) {
- T proxy = getCachedMonitor(monitorInterface);
- if (proxy == null) {
- proxy = createMonitor(monitorInterface, bundleName);
- proxies.put(monitorInterface, new WeakReference<T>(proxy));
- }
- return proxy;
- }
-
- private <T>T getCachedMonitor(Class<T> monitorInterface) {
- WeakReference<?> ref = proxies.get(monitorInterface);
- return (ref != null) ? monitorInterface.cast(ref.get()) : null;
- }
-
- private <T>T createMonitor(Class<T> monitorInterface, String bundleName) {
- String className = monitorInterface.getName();
- Logger logger = Logger.getLogger(className);
- Method[] methods = monitorInterface.getMethods();
- Map<String, Level> levels = new HashMap<String, Level>(methods.length);
- for (Method method : methods) {
- String key = className + '#' + method.getName();
- Level level = this.levels.get(key);
-
- // if not specified the in config properties, look for an annotation on the method
- if (level == null) {
- LogLevel annotation = method.getAnnotation(LogLevel.class);
- if (annotation != null && annotation.value() != null) {
- try {
- level = Level.parse(annotation.value());
- } catch (IllegalArgumentException e) {
- // bad value, just use the default
- level = defaultLevel;
- }
- }
- }
- if (level == null) {
- level = defaultLevel;
- }
- levels.put(method.getName(), level);
- }
-
- ResourceBundle bundle = locateBundle(monitorInterface, bundleName);
-
- InvocationHandler handler = new LoggingHandler(logger, levels, bundle);
- return monitorInterface.cast(Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class<?>[]{monitorInterface}, handler));
- }
-
- private static <T>ResourceBundle locateBundle(Class<T> monitorInterface, String bundleName) {
- Locale locale = Locale.getDefault();
- ClassLoader cl = monitorInterface.getClassLoader();
- String packageName = monitorInterface.getPackage().getName();
- while (true) {
- try {
- return ResourceBundle.getBundle(packageName + '.' + bundleName, locale, cl);
- } catch (MissingResourceException e) {
- }
- int index = packageName.lastIndexOf('.');
- if (index == -1) {
- break;
- }
- packageName = packageName.substring(0, index);
- }
- try {
- return ResourceBundle.getBundle(bundleName, locale, cl);
- } catch (Exception e) {
- return null;
- }
- }
-
- private static final class LoggingHandler implements InvocationHandler {
- private final Logger logger;
- private final Map<String, Level> methodLevels;
- private final ResourceBundle bundle;
-
- public LoggingHandler(Logger logger, Map<String, Level> methodLevels, ResourceBundle bundle) {
- this.logger = logger;
- this.methodLevels = methodLevels;
- this.bundle = bundle;
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- String sourceMethod = method.getName();
- Level level = methodLevels.get(sourceMethod);
- if (level != null && logger.isLoggable(level)) {
- // construct the key for the resource bundle
- String className = logger.getName();
- String key = className + '#' + sourceMethod;
-
- LogRecord logRecord = new LogRecord(level, key);
- logRecord.setLoggerName(className);
- logRecord.setSourceClassName(className);
- logRecord.setSourceMethodName(sourceMethod);
- logRecord.setParameters(args);
- if (args != null) {
- for (Object o : args) {
- if (o instanceof Throwable) {
- logRecord.setThrown((Throwable) o);
- break;
- }
- }
- }
- logRecord.setResourceBundle(bundle);
- logger.log(logRecord);
- }
- return null;
- }
- }
-}
diff --git a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/NullMonitorFactory.java b/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/NullMonitorFactory.java
deleted file mode 100644
index 827aeec84c..0000000000
--- a/tags/java-M1-20060522/java/sca/common/src/main/java/org/apache/tuscany/common/monitor/impl/NullMonitorFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.tuscany.common.monitor.impl;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import org.apache.tuscany.common.monitor.MonitorFactory;
-
-/**
- * Implementation of a {@link MonitorFactory} that produces implementations that simply return.
- *
- * @version $Rev$ $Date$
- */
-public class NullMonitorFactory implements MonitorFactory {
- public <T> T getMonitor(Class<T> monitorInterface) {
- /*
- * This uses a reflection proxy to implement the monitor interface which
- * is a simple but perhaps not very performant solution. Performance
- * might be improved by code generating an implementation with empty methods.
- */
- return monitorInterface.cast(Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class<?>[]{monitorInterface}, NULL_MONITOR));
- }
-
- /**
- * Singleton wire hander that does nothing.
- */
- private static final InvocationHandler NULL_MONITOR = new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args) {
- return null;
- }
- };
-}