[jboss-svn-commits] JBoss Common SVN: r3146 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 11 14:52:43 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-05-11 14:52:42 -0400 (Mon, 11 May 2009)
New Revision: 3146

Added:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerMarker.java
Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
Log:
Make Loggers serializable

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java	2009-05-11 16:49:15 UTC (rev 3145)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java	2009-05-11 18:52:42 UTC (rev 3146)
@@ -25,6 +25,8 @@
 import java.util.ResourceBundle;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import java.util.concurrent.locks.Lock;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
 import org.slf4j.Marker;
 import org.slf4j.spi.LocationAwareLogger;
 
@@ -36,8 +38,10 @@
 /**
  * An actual logger instance.  This is the end-user interface into the logging system.
  */
-public class Logger extends java.util.logging.Logger implements LocationAwareLogger {
+public class Logger extends java.util.logging.Logger implements LocationAwareLogger, Serializable {
 
+    private static final long serialVersionUID = 5093333069125075416L;
+
     /**
      * The named logger tree node.
      */
@@ -92,6 +96,12 @@
         handlersUpdater.clear(this);
     }
 
+    // Serialization
+
+    private Object writeReplace() throws ObjectStreamException {
+        return new LoggerMarker(getName());
+    }
+
     // Filter mgmt
 
     /** {@inheritDoc} */

Added: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerMarker.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerMarker.java	                        (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerMarker.java	2009-05-11 18:52:42 UTC (rev 3146)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.logmanager;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+
+/**
+ * A marker class for loggers.  After read, the {@link #readResolve()} method will return a logger with the given name.
+ */
+public final class LoggerMarker implements Serializable {
+
+    private static final long serialVersionUID = 8266206989821750874L;
+
+    private final String name;
+
+    /**
+     * Construct an instance.
+     *
+     * @param name the logger name
+     */
+    public LoggerMarker(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * Get the actual logger for this marker.
+     *
+     * @return the logger
+     * @throws ObjectStreamException (never)
+     * @see <a href="http://java.sun.com/javase/6/docs/platform/serialization/spec/input.html#5903">Serialization spec, 3.7</a>
+     */
+    public Object readResolve() throws ObjectStreamException {
+        return Logger.getLogger(name);
+    }
+}




More information about the jboss-svn-commits mailing list