geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r706654 - in /geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore: XStoreHolder.java XStoreImpl.java XStorePointerImpl.java XStoreRecordImpl.java
Date Tue, 21 Oct 2008 15:10:19 GMT
Author: jdillon
Date: Tue Oct 21 08:10:19 2008
New Revision: 706654

URL: http://svn.apache.org/viewvc?rev=706654&view=rev
Log:
Avoid direct creating of record and pointer impls, or use of the holder
added Marshaller cache

Modified:
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreHolder.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStorePointerImpl.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreHolder.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreHolder.java?rev=706654&r1=706653&r2=706654&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreHolder.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreHolder.java
Tue Oct 21 08:10:19 2008
@@ -24,21 +24,21 @@
  *
  * @version $Rev$ $Date$
  */
-public class XStoreHolder
+class XStoreHolder
 {
-    private static final InheritableThreadLocal<XStore> holder = new InheritableThreadLocal<XStore>();
+    private static final InheritableThreadLocal<XStoreImpl> holder = new InheritableThreadLocal<XStoreImpl>();
 
     public static void clear() {
         holder.remove();
     }
 
-    public static void set(final XStore xstore) {
+    public static void set(final XStoreImpl xstore) {
         assert xstore != null;
 
         holder.set(xstore);
     }
 
-    public static XStore get() {
+    public static XStoreImpl get() {
         return holder.get();
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java?rev=706654&r1=706653&r2=706654&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
Tue Oct 21 08:10:19 2008
@@ -20,12 +20,17 @@
 package org.apache.geronimo.gshell.xstore;
 
 import org.apache.geronimo.gshell.vfs.FileSystemAccess;
+import org.apache.geronimo.gshell.marshal.Marshaller;
+import org.apache.geronimo.gshell.marshal.MarshallerSupport;
 import org.apache.commons.vfs.FileSystem;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Map;
+import java.util.HashMap;
+
 /**
  * {@link XStore} component.
  *
@@ -82,7 +87,7 @@
     public XStoreRecord resolveRecord(final String path) {
         assert path != null;
 
-        final XStore prev = XStoreHolder.get();
+        final XStoreImpl prev = XStoreHolder.get();
         XStoreHolder.set(this);
 
         try {
@@ -104,4 +109,19 @@
 
         return new XStorePointerImpl(this, path);
     }
+
+    private final Map<Class,Marshaller> marshallers = new HashMap<Class,Marshaller>();
+
+    @SuppressWarnings({"unchecked"})
+    <T> Marshaller<T> getMarshaller(final Class<T> type) {
+        assert type != null;
+
+        Marshaller<T> marshaller = marshallers.get(type);
+        if (marshaller == null) {
+            marshaller = new MarshallerSupport<T>(type);
+            marshallers.put(type, marshaller);
+        }
+
+        return marshaller;
+    }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStorePointerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStorePointerImpl.java?rev=706654&r1=706653&r2=706654&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStorePointerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStorePointerImpl.java
Tue Oct 21 08:10:19 2008
@@ -27,11 +27,11 @@
 public class XStorePointerImpl
     implements XStorePointer
 {
-    private transient XStore xstore;
+    private transient XStoreImpl xstore;
 
     private String path;
 
-    public XStorePointerImpl(final XStore xstore, final String path) {
+    XStorePointerImpl(final XStoreImpl xstore, final String path) {
         assert xstore != null;
         this.xstore = xstore;
         assert path != null;

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java?rev=706654&r1=706653&r2=706654&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
Tue Oct 21 08:10:19 2008
@@ -23,7 +23,6 @@
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.geronimo.gshell.io.Closer;
 import org.apache.geronimo.gshell.marshal.Marshaller;
-import org.apache.geronimo.gshell.marshal.MarshallerSupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,11 +42,11 @@
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final XStore xstore;
+    private final XStoreImpl xstore;
 
     private final FileObject file;
 
-    public XStoreRecordImpl(final XStore xstore, final FileObject file) {
+    XStoreRecordImpl(final XStoreImpl xstore, final FileObject file) {
         assert xstore != null;
         this.xstore = xstore;
         assert file != null;
@@ -71,6 +70,8 @@
         }
     }
 
+    // TODO: Add marshaller cache
+    
     public void set(final Object value) {
         assert value != null;
 
@@ -78,7 +79,7 @@
 
         BufferedOutputStream output = null;
         try {
-            Marshaller marshaller = new MarshallerSupport(value.getClass());
+            Marshaller marshaller = xstore.getMarshaller(value.getClass());
             output = new BufferedOutputStream(file.getContent().getOutputStream());
             // noinspection unchecked
             marshaller.marshal(value, output);
@@ -99,8 +100,8 @@
         BufferedInputStream input = null;
 
         try {
-            Marshaller<T> marshaller = new MarshallerSupport<T>(type);
-            
+            Marshaller<T> marshaller = xstore.getMarshaller(type);
+
             FileObject parent = file.getParent();
             if (parent != null && !parent.exists()) {
                 parent.createFolder();



Mime
View raw message