You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rm...@apache.org on 2014/05/07 23:23:18 UTC

svn commit: r1593138 [2/2] - in /commons/proper/jcs/trunk: ./ commons-jcs-jcache-extras/ commons-jcs-jcache-extras/src/ commons-jcs-jcache-extras/src/main/ commons-jcs-jcache-extras/src/main/java/ commons-jcs-jcache-extras/src/main/java/org/ commons-jc...

Added: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/serialization/Serializations.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/serialization/Serializations.java?rev=1593138&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/serialization/Serializations.java (added)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/serialization/Serializations.java Wed May  7 21:23:17 2014
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.commons.jcs.jcache.serialization;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.Serializable;
+import java.lang.reflect.Proxy;
+
+public class Serializations
+{
+    public static <K extends Serializable> K copy(final ClassLoader loader, final K key)
+    {
+        try
+        {
+            return deSerialize(serialize(key), loader);
+        }
+        catch ( final Exception e)
+        {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static  <T extends Serializable> byte[] serialize( T obj ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream( baos );
+        try
+        {
+            oos.writeObject( obj );
+        }
+        finally
+        {
+            oos.close();
+        }
+        return baos.toByteArray();
+    }
+
+    private static  <T extends Serializable> T deSerialize( final byte[] data, final ClassLoader loader ) throws IOException, ClassNotFoundException
+    {
+        ByteArrayInputStream bais = new ByteArrayInputStream( data );
+        BufferedInputStream bis = new BufferedInputStream( bais );
+        ObjectInputStream ois = new ObjectInputStreamClassLoaderAware( bis, loader );
+        try
+        {
+            return (T) ois.readObject();
+        }
+        finally
+        {
+            ois.close();
+        }
+    }
+
+    private static class ObjectInputStreamClassLoaderAware extends ObjectInputStream
+    {
+        private final ClassLoader classLoader;
+
+        public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
+        {
+            super(in);
+            this.classLoader = classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader();
+        }
+
+        @Override
+        protected Class<?> resolveClass(final ObjectStreamClass desc) throws ClassNotFoundException
+        {
+            return Class.forName(desc.getName(), false, classLoader);
+        }
+
+        @Override
+        protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException
+        {
+            final Class[] cinterfaces = new Class[interfaces.length];
+            for (int i = 0; i < interfaces.length; i++)
+            {
+                cinterfaces[i] = Class.forName(interfaces[i], false, classLoader);
+            }
+
+            try
+            {
+                return Proxy.getProxyClass(classLoader, cinterfaces);
+            }
+            catch (IllegalArgumentException e)
+            {
+                throw new ClassNotFoundException(null, e);
+            }
+        }
+
+    }
+}

Added: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/thread/DaemonThreadFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/thread/DaemonThreadFactory.java?rev=1593138&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/thread/DaemonThreadFactory.java (added)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/thread/DaemonThreadFactory.java Wed May  7 21:23:17 2014
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.commons.jcs.jcache.thread;
+
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DaemonThreadFactory implements ThreadFactory
+{
+    private final AtomicInteger index = new AtomicInteger(1);
+    private final String prefix;
+
+    public DaemonThreadFactory(final String prefix)
+    {
+        this.prefix = prefix;
+    }
+
+    @Override
+    public Thread newThread( final Runnable runner )
+    {
+        final Thread t = new Thread( runner );
+        t.setName(prefix + index.getAndIncrement());
+        t.setDaemon(true);
+        return t;
+    }
+}
\ No newline at end of file

Modified: commons/proper/jcs/trunk/commons-jcs-tck-tests/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-tck-tests/pom.xml?rev=1593138&r1=1593137&r2=1593138&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-tck-tests/pom.xml (original)
+++ commons/proper/jcs/trunk/commons-jcs-tck-tests/pom.xml Wed May  7 21:23:17 2014
@@ -115,24 +115,18 @@
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jcdi_1.0_spec</artifactId>
-      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-atinject_1.0_spec</artifactId>
-      <version>1.0</version>
-      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-interceptor_1.1_spec</artifactId>
-      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.openwebbeans</groupId>
       <artifactId>openwebbeans-impl</artifactId>
-      <version>1.2.2</version>
-      <scope>test</scope>
     </dependency>
   </dependencies>
 

Modified: commons/proper/jcs/trunk/commons-jcs-tck-tests/run-tck.sh
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-tck-tests/run-tck.sh?rev=1593138&r1=1593137&r2=1593138&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-tck-tests/run-tck.sh (original)
+++ commons/proper/jcs/trunk/commons-jcs-tck-tests/run-tck.sh Wed May  7 21:23:17 2014
@@ -1,3 +1,3 @@
 #! /bin/bash
-mvn clean install -PjcacheTck
+mvn clean install -Djcache.tck
 

Modified: commons/proper/jcs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/pom.xml?rev=1593138&r1=1593137&r2=1593138&view=diff
==============================================================================
--- commons/proper/jcs/trunk/pom.xml (original)
+++ commons/proper/jcs/trunk/pom.xml Wed May  7 21:23:17 2014
@@ -140,6 +140,7 @@
     <module>commons-jcs-core</module>
     <module>commons-jcs-jcache</module>
     <module>commons-jcs-tck-tests</module>
+    <module>commons-jcs-jcache-extras</module>
   </modules>
 
   <developers>
@@ -328,6 +329,19 @@
         <version>1.0</version>
         <scope>provided</scope>
       </dependency>
+      <dependency>
+        <groupId>org.apache.geronimo.specs</groupId>
+        <artifactId>geronimo-atinject_1.0_spec</artifactId>
+        <version>1.0</version>
+        <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+        <groupId>org.apache.openwebbeans</groupId>
+        <artifactId>openwebbeans-impl</artifactId>
+        <version>1.2.2</version>
+        <scope>test</scope>
+      </dependency>
 
       <dependency>
         <groupId>javax.cache</groupId>