Author: raffaeleguidi
Date: Mon Aug  6 19:39:02 2012
New Revision: 1369947

URL: http://svn.apache.org/viewvc?rev=1369947&view=rev
Log:
integrated configuration patch

Added:
    
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/
    
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/Configuration.java
    
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/
    
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
    
incubator/directmemory/trunk/directmemory-cache/src/test/resources/directmemory.yaml
Modified:
    incubator/directmemory/trunk/directmemory-cache/pom.xml
    
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java

Modified: incubator/directmemory/trunk/directmemory-cache/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/pom.xml?rev=1369947&r1=1369946&r2=1369947&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/pom.xml (original)
+++ incubator/directmemory/trunk/directmemory-cache/pom.xml Mon Aug  6 19:39:02 
2012
@@ -108,6 +108,11 @@ under the License.
       <artifactId>aspectjrt</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.yaml</groupId>
+      <artifactId>snakeyaml</artifactId>
+      <version>1.10</version>
+    </dependency>      
+    <dependency>
       <groupId>com.carrotsearch</groupId>
       <artifactId>junit-benchmarks</artifactId>
       <scope>test</scope>

Added: 
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/Configuration.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/Configuration.java?rev=1369947&view=auto
==============================================================================
--- 
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/Configuration.java
 (added)
+++ 
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/conf/Configuration.java
 Mon Aug  6 19:39:02 2012
@@ -0,0 +1,125 @@
+package org.apache.directmemory.conf;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+/*
+ * 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.
+ */
+
+/**
+ * Provides a global single point of access to all singleton properties 
comprehensible to DirectMemory.
+ */
+public final class Configuration
+{
+    private static final Logger logger = LoggerFactory.getLogger( 
Configuration.class );
+
+    public static int getNumberOfBuffers()
+    {
+        return yamlShadow.numberOfBuffers;
+    }
+
+    public static int getInitialCapacity()
+    {
+        return yamlShadow.initialCapacity;
+    }
+
+    public static int getRamMegaBytes()
+    {
+        return yamlShadow.ramMegaBytes;
+    }
+
+    public static long getDisposalTime()
+    {
+        return yamlShadow.disposalTime;
+    }
+
+    public static int getConcurrencyLevel()
+    {
+        return yamlShadow.concurrencyLevel;
+    }
+
+    private static void wireConfiguration()
+    {
+        boolean success = false;
+        InputStream inputStream = null;
+        try
+        {
+            inputStream = Configuration.class.getClassLoader()
+                            .getResourceAsStream("directmemory.yaml");
+            Yaml yaml = new Yaml( new Constructor( YamlShadow.class ) );
+            yamlShadow = (YamlShadow) yaml.load( inputStream );
+            success = true;
+        }
+        catch ( Exception exception )
+        {
+            logger.error( "Problem trying to load DirectMemory configuration, 
now exiting.", exception );
+        }
+        finally
+        {
+            if ( inputStream != null )
+            {
+                try
+                {
+                    inputStream.close();
+                }
+                catch ( IOException ioException )
+                { // no-op
+                }
+            }
+            if ( success )
+            {
+                logger.info( "Loading DirectMemory configuration from 
directmemory.yml" );
+            }
+        }
+    }
+
+    public static class YamlShadow
+    {
+        public int numberOfBuffers = 1;
+
+        public int initialCapacity = 100000;
+
+        public int ramMegaBytes = 1;
+
+        public int concurrencyLevel = 4;
+
+        public long disposalTime = 10L;
+
+        public YamlShadow()
+        {
+        }
+    }
+
+    private static YamlShadow yamlShadow;
+    static
+    {
+        wireConfiguration();
+    }
+
+    // Prevent instance escape
+    private Configuration()
+    {
+    }
+
+}

Added: 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java?rev=1369947&view=auto
==============================================================================
--- 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
 (added)
+++ 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
 Mon Aug  6 19:39:02 2012
@@ -0,0 +1,18 @@
+package org.apache.directmemory.conf;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ConfigurationTest
+{
+    @Test
+    public void testBaseConfiguration()
+    {
+        assertTrue( Configuration.getNumberOfBuffers() > 0 );
+        assertTrue( Configuration.getInitialCapacity() > 0 );
+        assertTrue( Configuration.getRamMegaBytes() > 0 );
+        assertTrue( Configuration.getConcurrencyLevel() > 0 );
+        assertTrue( Configuration.getDisposalTime() > 0L );
+    }
+}

Modified: 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java?rev=1369947&r1=1369946&r2=1369947&view=diff
==============================================================================
--- 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java
 (original)
+++ 
incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java
 Mon Aug  6 19:39:02 2012
@@ -51,6 +51,7 @@ public final class DummyPojoSerializer
         data = baos.toByteArray();
     }
 
+    @SuppressWarnings( "unchecked" ) // it is just a dummy class for tests
     @Override
     public <T> T deserialize( byte[] source, Class<T> clazz )
         throws IOException, ClassNotFoundException, InstantiationException, 
IllegalAccessException

Added: 
incubator/directmemory/trunk/directmemory-cache/src/test/resources/directmemory.yaml
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/resources/directmemory.yaml?rev=1369947&view=auto
==============================================================================
--- 
incubator/directmemory/trunk/directmemory-cache/src/test/resources/directmemory.yaml
 (added)
+++ 
incubator/directmemory/trunk/directmemory-cache/src/test/resources/directmemory.yaml
 Mon Aug  6 19:39:02 2012
@@ -0,0 +1,14 @@
+# Number of buffers
+numberOfBuffers: 1
+
+# Initial capacity
+initialCapacity: 100000
+
+# RAM allocation in MB
+ramMegaBytes: 1
+
+# Concurrency level
+concurrencyLevel: 4
+
+# Disposal time in seconds
+disposalTime: 10


Reply via email to