You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ra...@apache.org on 2012/08/07 22:57:41 UTC

svn commit: r1370517 - in /incubator/directmemory/trunk: ./ conf/ directmemory-cache/ directmemory-common/ directmemory-common/src/ directmemory-common/src/main/ directmemory-common/src/main/java/ directmemory-common/src/main/java/org/ directmemory-com...

Author: raffaeleguidi
Date: Tue Aug  7 20:57:40 2012
New Revision: 1370517

URL: http://svn.apache.org/viewvc?rev=1370517&view=rev
Log:
added configuration modification (but left inactive) with commons module

Added:
    incubator/directmemory/trunk/conf/
    incubator/directmemory/trunk/conf/directmemory.yaml
    incubator/directmemory/trunk/directmemory-common/
    incubator/directmemory/trunk/directmemory-common/pom.xml
      - copied, changed from r1370516, incubator/directmemory/trunk/directmemory-cache/pom.xml
    incubator/directmemory/trunk/directmemory-common/src/
    incubator/directmemory/trunk/directmemory-common/src/main/
    incubator/directmemory/trunk/directmemory-common/src/main/java/
    incubator/directmemory/trunk/directmemory-common/src/main/java/org/
    incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/
    incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/
    incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/
    incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/Configuration.java
    incubator/directmemory/trunk/directmemory-common/src/test/
    incubator/directmemory/trunk/directmemory-common/src/test/java/
    incubator/directmemory/trunk/directmemory-common/src/test/java/org/
    incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/
    incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/
    incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/conf/
    incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
Modified:
    incubator/directmemory/trunk/directmemory-cache/pom.xml
    incubator/directmemory/trunk/pom.xml

Added: incubator/directmemory/trunk/conf/directmemory.yaml
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/conf/directmemory.yaml?rev=1370517&view=auto
==============================================================================
--- incubator/directmemory/trunk/conf/directmemory.yaml (added)
+++ incubator/directmemory/trunk/conf/directmemory.yaml Tue Aug  7 20:57:40 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

Modified: incubator/directmemory/trunk/directmemory-cache/pom.xml
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/pom.xml?rev=1370517&r1=1370516&r2=1370517&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/pom.xml (original)
+++ incubator/directmemory/trunk/directmemory-cache/pom.xml Tue Aug  7 20:57:40 2012
@@ -43,7 +43,7 @@ under the License.
       com.google.common.base;version="[9.0,11)",
       org.aspectj*;version="[1.6,2)",
       org.slf4j*
-    </osgi.import>
+    </osgi.import> <!-- ,org.yaml.snakeyaml* -->
     <osgi.export>org.apache.directmemory*;version="${project.version}</osgi.export>
   </properties>
 

Copied: incubator/directmemory/trunk/directmemory-common/pom.xml (from r1370516, incubator/directmemory/trunk/directmemory-cache/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-common/pom.xml?p2=incubator/directmemory/trunk/directmemory-common/pom.xml&p1=incubator/directmemory/trunk/directmemory-cache/pom.xml&r1=1370516&r2=1370517&rev=1370517&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/pom.xml (original)
+++ incubator/directmemory/trunk/directmemory-common/pom.xml Tue Aug  7 20:57:40 2012
@@ -28,41 +28,14 @@ under the License.
     <relativePath>../</relativePath>
   </parent>
 
-  <artifactId>directmemory-cache</artifactId>
-  <name>Apache DirectMemory :: Cache</name>
+  <artifactId>directmemory-common</artifactId>
+  <name>Apache DirectMemory :: Commons</name>
   <packaging>bundle</packaging>
-  <description>DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la
-    BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection
-    performance
+  <description>DirectMemory Commons is a collection of base utilities that are shared amongst the various modules of DirectMemory.
   </description>
 
-  <properties>
-    <osgi.import>
-      !org.apache.directmemory*,
-      com.google.common.collect;version="[9.0,11)",
-      com.google.common.base;version="[9.0,11)",
-      org.aspectj*;version="[1.6,2)",
-      org.slf4j*
-    </osgi.import>
-    <osgi.export>org.apache.directmemory*;version="${project.version}</osgi.export>
-  </properties>
-
-
   <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-clean-plugin</artifactId>
-        <configuration>
-          <filesets>
-            <fileset>
-              <directory>logs</directory>
-              <followSymlinks>false</followSymlinks>
-            </fileset>
-          </filesets>
-        </configuration>
-      </plugin>
-
+    <!--<plugins>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>aspectj-maven-plugin</artifactId>
@@ -76,22 +49,43 @@ under the License.
           <execution>
             <goals>
               <goal>compile</goal>
-              <!-- use this goal to weave all your main classes -->
               <goal>test-compile</goal>
-              <!-- use this goal to weave all your test classes -->
             </goals>
           </execution>
         </executions>
-        <dependencies>
-          <dependency>
-            <groupId>org.aspectj</groupId>
-            <artifactId>aspectjtools</artifactId>
-            <version>${aspectj.version}</version>
-          </dependency>
-        </dependencies>
       </plugin>
+    </plugins>-->
 
-    </plugins>
+    <pluginManagement>
+      <plugins>
+        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+                <pluginExecutions>
+                    <pluginExecution>
+                        <pluginExecutionFilter>
+                            <groupId>org.codehaus.mojo</groupId>
+                                <artifactId> aspectj-maven-plugin</artifactId>
+                                    <versionRange>[1.4,)</versionRange>
+                                    <goals>
+                                        <goal>compile</goal>
+                                        <goal>test-compile</goal>
+                                    </goals>
+                        </pluginExecutionFilter>
+                            <action>
+                                <ignore></ignore>
+                            </action>
+                        </pluginExecution>
+                    </pluginExecutions>
+                </lifecycleMappingMetadata>
+            </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
   </build>
 
   <dependencies>
@@ -100,32 +94,13 @@ under the License.
       <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>aspectjrt</artifactId>
-    </dependency>    
-    <dependency>
-      <groupId>com.carrotsearch</groupId>
-      <artifactId>junit-benchmarks</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-core</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-classic</artifactId>
-      <scope>test</scope>
+      <groupId>org.yaml</groupId>
+      <artifactId>snakeyaml</artifactId>
     </dependency>
   </dependencies>
 

Added: incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/Configuration.java?rev=1370517&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/Configuration.java (added)
+++ incubator/directmemory/trunk/directmemory-common/src/main/java/org/apache/directmemory/conf/Configuration.java Tue Aug  7 20:57:40 2012
@@ -0,0 +1,129 @@
+package org.apache.directmemory.conf;
+
+import java.io.File;
+import java.io.FileInputStream;
+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;
+        String yamlLocation = null;
+        try
+        {
+            yamlLocation =
+                new File( System.getProperty( "user.dir" ) + "/../conf/directmemory.yaml" ).getCanonicalPath();
+            inputStream = new FileInputStream( new File( yamlLocation ) );
+            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 " + yamlLocation );
+            }
+        }
+    }
+
+    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-common/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java?rev=1370517&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java (added)
+++ incubator/directmemory/trunk/directmemory-common/src/test/java/org/apache/directmemory/conf/ConfigurationTest.java Tue Aug  7 20:57:40 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/pom.xml
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/pom.xml?rev=1370517&r1=1370516&r2=1370517&view=diff
==============================================================================
--- incubator/directmemory/trunk/pom.xml (original)
+++ incubator/directmemory/trunk/pom.xml Tue Aug  7 20:57:40 2012
@@ -198,6 +198,7 @@ under the License.
   </mailingLists>
 
   <modules>
+    <!--<module>directmemory-common</module>-->
     <module>directmemory-cache</module>
     <module>directmemory-tests</module>
     <module>server</module>
@@ -264,6 +265,7 @@ under the License.
     <msgpack.version>0.6.5</msgpack.version>
     <protobuf.version>2.4.1</protobuf.version>
     <wagon.version>2.2</wagon.version>
+    <snakeyaml.version>1.10</snakeyaml.version>
 
     <!-- Plugin Versions -->
     <buildnumber-plugin.version>1.1</buildnumber-plugin.version>
@@ -522,6 +524,11 @@ under the License.
       <!-- Internal Project Artifacts -->
       <dependency>
         <groupId>org.apache.directmemory</groupId>
+        <artifactId>directmemory-common</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.directmemory</groupId>
         <artifactId>directmemory-cache</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -680,6 +687,11 @@ under the License.
         <version>${slf4j.version}</version>
         <type>jar</type>
       </dependency>
+      <dependency>
+        <groupId>org.yaml</groupId>
+        <artifactId>snakeyaml</artifactId>
+        <version>${snakeyaml.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>