You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by si...@apache.org on 2012/02/15 14:53:48 UTC

svn commit: r1244486 - in /incubator/directmemory/trunk/directmemory-cache/src: main/java/org/apache/directmemory/serialization/ test/java/org/apache/directmemory/serialization/ test/resources/META-INF/ test/resources/META-INF/services/

Author: simonetripodi
Date: Wed Feb 15 13:53:47 2012
New Revision: 1244486

URL: http://svn.apache.org/viewvc?rev=1244486&view=rev
Log:
preparation for modularization: first checkin of a serializer factory implementation based on ServiceLoader, it will find for an impl in the provider, will return a default one if not found

Added:
    incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java   (with props)
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java   (with props)
    incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/
    incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/
    incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/org.apache.directmemory.serialization.Serializer

Added: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java?rev=1244486&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java (added)
+++ incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java Wed Feb 15 13:53:47 2012
@@ -0,0 +1,49 @@
+package org.apache.directmemory.serialization;
+
+/*
+ * 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.
+ */
+
+import static java.util.ServiceLoader.load;
+
+import java.util.Iterator;
+
+public final class SerializerFactory
+{
+
+    public static Serializer createNewSerializer()
+    {
+        Iterator<Serializer> serializers = load( Serializer.class ).iterator();
+
+        if ( serializers.hasNext() )
+        {
+            return serializers.next();
+        }
+
+        return new StandardSerializer();
+    }
+
+    /**
+     * Hidden constructor, this class cannot be instantiated
+     */
+    private SerializerFactory()
+    {
+        // do nothing
+    }
+
+}

Propchange: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java?rev=1244486&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java (added)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java Wed Feb 15 13:53:47 2012
@@ -0,0 +1,41 @@
+package org.apache.directmemory.serialization;
+
+/*
+ * 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.
+ */
+
+import static org.apache.directmemory.serialization.SerializerFactory.createNewSerializer;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public final class SerializerFactoryTestCase
+{
+
+    /*
+     * TODO please update the test once DM will be modularized!
+     */
+    @Test
+    public void verifySerializerInstantiation()
+    {
+        Serializer serializer = createNewSerializer();
+
+        assertTrue( serializer instanceof ProtoStuffWithLinkedBufferSerializer );
+    }
+
+}

Propchange: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/org.apache.directmemory.serialization.Serializer?rev=1244486&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/org.apache.directmemory.serialization.Serializer (added)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/resources/META-INF/services/org.apache.directmemory.serialization.Serializer Wed Feb 15 13:53:47 2012
@@ -0,0 +1,18 @@
+ # 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.
+
+org.apache.directmemory.serialization.ProtoStuffWithLinkedBufferSerializer