[logback-dev] svn commit: r2171 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/net logback-classic/src/main/java/ch/qos/logback/classic/net logback-classic/src/main/java/ch/qos/logback/classic/spi logback-classic/src/test/java/ch/qos/logback/classic/net logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders logback-classic/src/test/java/ch/qos/logback/classic/spi logback-core/src/main/java/ch/qos/logback/core/net logback-core/src/main/java/ch/qos/logback/core/spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Feb 26 11:53:18 CET 2009


Author: ceki
Date: Thu Feb 26 11:53:17 2009
New Revision: 2171

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/AccessEventPreSerializationTransformer.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/LoggingEventPreSerializationTransformer.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/PreSerializationTransformer.java
Removed:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/SDOAware.java
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SocketAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventSDO.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/TrivialLoggingEventBuilder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationTest.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java

Log:

 SDOAware interface has been removed.
 ILoggerEvent interface no longer extends SDOAware.
 
 Appenders which rely on serialization invoke the appropriate PreSerializationTransformer
 to obtain a serializable representation of the event they are processing. 


Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/AccessEventPreSerializationTransformer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/AccessEventPreSerializationTransformer.java	Thu Feb 26 11:53:17 2009
@@ -0,0 +1,24 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2009, QOS.ch
+ * 
+ * This library 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.
+ */
+package ch.qos.logback.access.net;
+
+import java.io.Serializable;
+
+import ch.qos.logback.access.spi.AccessEvent;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
+
+public class AccessEventPreSerializationTransformer implements
+    PreSerializationTransformer<AccessEvent> {
+
+  public Serializable transform(AccessEvent event) {
+    return event;
+  }
+
+}

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SocketAppender.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SocketAppender.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SocketAppender.java	Thu Feb 26 11:53:17 2009
@@ -15,6 +15,7 @@
 
 import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.core.net.SocketAppenderBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 /**
  * Sends {@link AccessEvent} objects to a remote a log server, usually a
@@ -30,6 +31,8 @@
 
 public class SocketAppender extends SocketAppenderBase<AccessEvent> {
   
+  PreSerializationTransformer<AccessEvent> pst = new AccessEventPreSerializationTransformer();
+  
   public SocketAppender() {
   }
 
@@ -57,4 +60,7 @@
     ae.prepareForDeferredProcessing();
   }
 
+  public PreSerializationTransformer<AccessEvent> getPST() {
+    return pst;
+  }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java	Thu Feb 26 11:53:17 2009
@@ -10,6 +10,8 @@
 
 package ch.qos.logback.classic.net;
 
+import java.io.Serializable;
+
 import javax.jms.ObjectMessage;
 import javax.jms.Queue;
 import javax.jms.QueueConnection;
@@ -22,6 +24,7 @@
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.AppenderBase;
 import ch.qos.logback.core.net.JMSAppenderBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 /**
  * A simple appender that publishes events to a JMS Queue. The events are
@@ -45,6 +48,8 @@
 
   int successiveFailureCount = 0;
 
+  private PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
+  
   public JMSQueueAppender() {
   }
 
@@ -166,7 +171,8 @@
 
     try {
       ObjectMessage msg = queueSession.createObjectMessage();
-      msg.setObject(event.getSDO());
+      Serializable so = pst.transform(event);
+      msg.setObject(so);
       queueSender.send(msg);
       successiveFailureCount = 0;
     } catch (Exception e) {

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java	Thu Feb 26 11:53:17 2009
@@ -10,6 +10,8 @@
 
 package ch.qos.logback.classic.net;
 
+import java.io.Serializable;
+
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
 import javax.jms.Topic;
@@ -22,6 +24,7 @@
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.AppenderBase;
 import ch.qos.logback.core.net.JMSAppenderBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 /**
  * A simple appender that publishes events to a JMS Topic. The events are
@@ -44,7 +47,9 @@
   TopicPublisher topicPublisher;
 
   int successiveFailureCount = 0;
-
+  
+  private PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
+  
   public JMSTopicAppender() {
   }
 
@@ -167,8 +172,8 @@
 
     try {
       ObjectMessage msg = topicSession.createObjectMessage();
-
-      msg.setObject(event.getSDO());
+      Serializable so = pst.transform(event);
+      msg.setObject(so);
       topicPublisher.publish(msg);
       successiveFailureCount = 0;
     } catch (Exception e) {

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/LoggingEventPreSerializationTransformer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/LoggingEventPreSerializationTransformer.java	Thu Feb 26 11:53:17 2009
@@ -0,0 +1,35 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2009, QOS.ch
+ * 
+ * This library 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.
+ */
+package ch.qos.logback.classic.net;
+
+import java.io.Serializable;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.classic.spi.LoggingEventSDO;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
+
+public class LoggingEventPreSerializationTransformer implements
+    PreSerializationTransformer<ILoggingEvent> {
+
+  public Serializable transform(ILoggingEvent event) {
+    if(event == null) {
+      return null;
+    }
+    if (event instanceof LoggingEvent) {
+      return LoggingEventSDO.build(event);
+    } else if (event instanceof LoggingEventSDO) {
+      return (LoggingEventSDO)  event;
+    } else {
+      throw new IllegalArgumentException("Unsupported type "+event.getClass().getName());
+    }
+  }
+
+}

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java	Thu Feb 26 11:53:17 2009
@@ -15,6 +15,7 @@
 
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.net.SocketAppenderBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 /**
  * Sends {@link ILoggingEvent} objects to a remote a log server, usually a
@@ -31,6 +32,8 @@
 
   boolean includeCallerData = false;
 
+  PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
+  
   public SocketAppender() {
   }
 
@@ -62,5 +65,9 @@
   public void setIncludeCallerData(boolean includeCallerData) {
     this.includeCallerData = includeCallerData;
   }
-
+  
+  public PreSerializationTransformer<ILoggingEvent> getPST() {
+    return pst;
+  }
+  
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java	Thu Feb 26 11:53:17 2009
@@ -5,21 +5,21 @@
 import org.slf4j.Marker;
 
 import ch.qos.logback.classic.Level;
-import ch.qos.logback.core.spi.SDOAware;
 
-public interface ILoggingEvent extends SDOAware {
+/**
+ * The core interface in logback-classic.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public interface ILoggingEvent {
 
   public String getThreadName();
-
   public Level getLevel();
-
   public String getMessage();
-  
-  public LoggerRemoteView getLoggerRemoteView();
-  
+  public Object[] getArgumentArray();
   public String getFormattedMessage();
 
-  public Object[] getArgumentArray();
+  public LoggerRemoteView getLoggerRemoteView();
 
   public ThrowableProxy getThrowableProxy();
 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java	Thu Feb 26 11:53:17 2009
@@ -10,10 +10,6 @@
 
 package ch.qos.logback.classic.spi;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -41,11 +37,6 @@
  */
 public class LoggingEvent implements ILoggingEvent {
 
-  private static final long serialVersionUID = 3075964498087694229L;
-
-  private static final int NULL_ARGUMENT_ARRAY = -1;
-  private static final String NULL_ARGUMENT_ARRAY_ELEMENT = "NULL_ARGUMENT_ARRAY_ELEMENT";
-
   /**
    * Fully qualified name of the calling Logger class. This field does not
    * survive serialization.
@@ -91,8 +82,6 @@
    * created.
    */
   private long timeStamp;
-
-  private LoggingEventSDO loggingEventSDO;
   
   public LoggingEvent() {
   }
@@ -283,43 +272,6 @@
     return mdcPropertyMap;
   }
 
-  private void writeObject(ObjectOutputStream out) throws IOException {
-    out.defaultWriteObject();
-    out.writeInt(level.levelInt);
-    if (argumentArray != null) {
-      int len = argumentArray.length;
-      out.writeInt(len);
-      for (int i = 0; i < argumentArray.length; i++) {
-        if (argumentArray[i] != null) {
-          out.writeObject(argumentArray[i].toString());
-        } else {
-          out.writeObject(NULL_ARGUMENT_ARRAY_ELEMENT);
-        }
-      }
-    } else {
-      out.writeInt(NULL_ARGUMENT_ARRAY);
-    }
-
-  }
-  
-  private void readObject(ObjectInputStream in) throws IOException,
-      ClassNotFoundException {
-    in.defaultReadObject();
-    int levelInt = in.readInt();
-    level = Level.toLevel(levelInt);
-
-    int argArrayLen = in.readInt();
-    if (argArrayLen != NULL_ARGUMENT_ARRAY) {
-      argumentArray = new String[argArrayLen];
-      for (int i = 0; i < argArrayLen; i++) {
-        Object val = in.readObject();
-        if (!NULL_ARGUMENT_ARRAY_ELEMENT.equals(val)) {
-          argumentArray[i] = val;
-        }
-      }
-    }
-  }
-
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
@@ -329,10 +281,4 @@
     return sb.toString();
   }
 
-  public Serializable getSDO() {
-    if(loggingEventSDO == null) {
-      loggingEventSDO = LoggingEventSDO.build(this);
-    }
-    return loggingEventSDO;
-  }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventSDO.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventSDO.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventSDO.java	Thu Feb 26 11:53:17 2009
@@ -36,8 +36,7 @@
   private LoggerRemoteView lrv;
   private long timeStamp;
 
-  static LoggingEventSDO build(ILoggingEvent le) {
-
+  public static LoggingEventSDO build(ILoggingEvent le) {
     LoggingEventSDO ledo = new LoggingEventSDO();
     ledo.lrv = le.getLoggerRemoteView();
     ledo.threadName = le.getThreadName();
@@ -153,11 +152,53 @@
   public void prepareForDeferredProcessing() {
   }
 
-  /**
-   * LoggerEventSDO is its own SDO
-   */
-  public Serializable getSDO() {
-    return this;
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((message == null) ? 0 : message.hashCode());
+    result = prime * result
+        + ((threadName == null) ? 0 : threadName.hashCode());
+    result = prime * result + (int) (timeStamp ^ (timeStamp >>> 32));
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    final LoggingEventSDO other = (LoggingEventSDO) obj;
+    if (message == null) {
+      if (other.message != null)
+        return false;
+    } else if (!message.equals(other.message))
+      return false;
+
+    if (threadName == null) {
+      if (other.threadName != null)
+        return false;
+    } else if (!threadName.equals(other.threadName))
+      return false;
+    if (timeStamp != other.timeStamp)
+      return false;
+    
+    if (marker == null) {
+      if (other.marker != null)
+        return false;
+    } else if (!marker.equals(other.marker))
+      return false;
+    
+    if (mdcPropertyMap == null) {
+      if (other.mdcPropertyMap != null)
+        return false;
+    } else if (!mdcPropertyMap.equals(other.mdcPropertyMap))
+      return false;
+    return true;
   }
 
+  
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java	Thu Feb 26 11:53:17 2009
@@ -1,5 +1,7 @@
 package ch.qos.logback.classic.net;
 
+import java.io.Serializable;
+
 import javax.jms.ObjectMessage;
 
 import junit.framework.TestCase;
@@ -12,12 +14,14 @@
 import ch.qos.logback.classic.util.MockInitialContext;
 import ch.qos.logback.classic.util.MockInitialContextFactory;
 import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 public class JMSQueueAppenderTest extends TestCase {
 
   ch.qos.logback.core.Context context;
   JMSQueueAppender appender;
-
+  PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
+  
   @Override
   protected void setUp() throws Exception {
     context = new ContextBase();
@@ -53,7 +57,8 @@
     assertEquals(1, qs.getMessageList().size());
     ObjectMessage message = (ObjectMessage) qs.getMessageList().get(0);
     try {
-      assertEquals(le.getSDO(), message.getObject());
+      Serializable witness = pst.transform(le);
+      assertEquals(witness, message.getObject());
     } catch (Exception e) {
       fail();
     }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java	Thu Feb 26 11:53:17 2009
@@ -5,6 +5,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.Serializable;
 import java.util.Properties;
 
 import javax.jms.ObjectMessage;
@@ -23,12 +24,14 @@
 import ch.qos.logback.classic.util.MockInitialContext;
 import ch.qos.logback.classic.util.MockInitialContextFactory;
 import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 public class JMSTopicAppenderTest  {
 
   ch.qos.logback.core.Context context;
   JMSTopicAppender appender;
-
+  PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
+  
 
   @Before
   public void setUp() throws Exception {
@@ -65,7 +68,8 @@
     assertEquals(1, tp.getMessageList().size());
     ObjectMessage message = (ObjectMessage) tp.getMessageList().get(0);
     try {
-      assertEquals(le.getSDO(), message.getObject());
+      Serializable witness = pst.transform(le);
+      assertEquals(witness, message.getObject());
     } catch (Exception e) {
       fail();
     }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/TrivialLoggingEventBuilder.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/TrivialLoggingEventBuilder.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/TrivialLoggingEventBuilder.java	Thu Feb 26 11:53:17 2009
@@ -27,5 +27,5 @@
     le.setMessage(MSG_PREFIX);
     le.setThreadName("threadName");
     return le;
-  }
+  } 
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java	Thu Feb 26 11:53:17 2009
@@ -14,7 +14,7 @@
 import ch.qos.logback.classic.net.NOPOutputStream;
 import ch.qos.logback.classic.net.testObjectBuilders.Builder;
 import ch.qos.logback.classic.net.testObjectBuilders.LoggingEventWithParametersBuilder;
-import ch.qos.logback.classic.net.testObjectBuilders.TrivialLoggingEventBuilder;
+import ch.qos.logback.classic.net.testObjectBuilders.TrivialLoggingEventBuilder; 
 import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.testUtil.Env;
 

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationTest.java	Thu Feb 26 11:53:17 2009
@@ -9,6 +9,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.util.Map;
 
 import org.junit.After;
@@ -19,6 +20,8 @@
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.net.LoggingEventPreSerializationTransformer;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 public class LoggingEventSerializationTest {
 
@@ -28,6 +31,7 @@
   ByteArrayOutputStream bos;
   ObjectOutputStream oos;
   ObjectInputStream inputStream;
+  PreSerializationTransformer<ILoggingEvent> pst = new LoggingEventPreSerializationTransformer();
 
   @Before
   public void setUp() throws Exception {
@@ -87,11 +91,13 @@
   public void updatedMDC() throws Exception {
     MDC.put("key", "testValue");
     ILoggingEvent event1 = createLoggingEvent();
-    oos.writeObject(event1.getSDO());
+    Serializable s1 = pst.transform(event1);
+    oos.writeObject(s1);
 
     MDC.put("key", "updatedTestValue");
     ILoggingEvent event2 = createLoggingEvent();
-    oos.writeObject(event2.getSDO());
+    Serializable s2 = pst.transform(event2);
+    oos.writeObject(s2);
 
     // create the input stream based on the ouput stream
     ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
@@ -190,7 +196,8 @@
 
   private ILoggingEvent writeAndRead(ILoggingEvent event) throws IOException,
       ClassNotFoundException {
-    oos.writeObject(event.getSDO());
+    Serializable ser = pst.transform(event);
+    oos.writeObject(ser);
     ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
     inputStream = new ObjectInputStream(bis);
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java	Thu Feb 26 11:53:17 2009
@@ -160,7 +160,5 @@
     this.password = password;
   }
 
-
-
   
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SocketAppenderBase.java	Thu Feb 26 11:53:17 2009
@@ -13,12 +13,13 @@
 
 import java.io.IOException;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.net.InetAddress;
 import java.net.Socket;
 
 import ch.qos.logback.core.AppenderBase;
 import ch.qos.logback.core.CoreConstants;
-import ch.qos.logback.core.spi.SDOAware;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
 
 /**
  * 
@@ -152,12 +153,8 @@
     if (oos != null) {
       try {
         postProcessEvent(event);
-        // if an object is SDOAware, then its SDO has preference
-        if(event instanceof SDOAware) {
-          oos.writeObject(((SDOAware)event).getSDO());
-        } else {
-          oos.writeObject(event);
-        }
+        Serializable serEvent = getPST().transform(event);
+        oos.writeObject(serEvent);
         // addInfo("=========Flushing.");
         oos.flush();
         if (++counter >= CoreConstants.OOS_RESET_FREQUENCY) {
@@ -185,6 +182,7 @@
   }
 
   protected abstract void postProcessEvent(E event);
+  protected abstract PreSerializationTransformer<E> getPST();
 
   void fireConnector() {
     if (connector == null) {
@@ -256,6 +254,7 @@
     return reconnectionDelay;
   }
 
+  
   /**
    * The Connector will reconnect when the server becomes available again. It
    * does this by attempting to open a new connection every

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/PreSerializationTransformer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/PreSerializationTransformer.java	Thu Feb 26 11:53:17 2009
@@ -0,0 +1,15 @@
+package ch.qos.logback.core.spi;
+
+import java.io.Serializable;
+
+/**
+ * PreSerializationTransformer instances have the responsibility to transform
+ * object into a presumably equivalent serializable representation.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ * 
+ * @param <E>
+ */
+public interface PreSerializationTransformer<E> {
+  Serializable transform(E event);
+}


More information about the logback-dev mailing list