Author: olamy
Date: Wed Jul 10 11:20:59 2013
New Revision: 1501725

URL: http://svn.apache.org/r1501725
Log:
format code

Modified:
    directmemory/trunk/integrations/guava/pom.xml
    
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/ForwardingListener.java
    
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/OffHeapCache.java
    
directmemory/trunk/integrations/guava/src/test/java/org/apache/directmemory/guava/GuavaCacheTest.java

Modified: directmemory/trunk/integrations/guava/pom.xml
URL: 
http://svn.apache.org/viewvc/directmemory/trunk/integrations/guava/pom.xml?rev=1501725&r1=1501724&r2=1501725&view=diff
==============================================================================
--- directmemory/trunk/integrations/guava/pom.xml (original)
+++ directmemory/trunk/integrations/guava/pom.xml Wed Jul 10 11:20:59 2013
@@ -17,65 +17,66 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
 
-    <modelVersion>4.0.0</modelVersion>
+  <modelVersion>4.0.0</modelVersion>
 
-    <parent>
-        <groupId>org.apache.directmemory</groupId>
-        <artifactId>directmemory-integrations</artifactId>
-        <version>0.2-SNAPSHOT</version>
-    </parent>
-
-    <artifactId>directmemory-guava</artifactId>
-    <name>Apache DirectMemory :: Integrations :: Guava</name>
-    <packaging>bundle</packaging>
-    <description>Provides second level cache implementation for Guava 
Cache</description>
-
-    <properties>
-        <osgi.import>
-            org.apache.directmemory*;version="${project.version}",
-            *
-        </osgi.import>
-        <osgi.export>
-            
org.apache.directmemory.guava;version="${project.version}";-noimport:=true,
-        </osgi.export>
-    </properties>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <argLine>-Xmx512m -Xms512m 
-XX:MaxDirectMemorySize=512m</argLine>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
-    <dependencies>
-        <!-- DirectMemory Dependency -->
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>directmemory-cache</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>14.0.1</version>
-        </dependency>
-
-        <!-- Testing Dependencies -->
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-        </dependency>
-    </dependencies>
+  <parent>
+    <groupId>org.apache.directmemory</groupId>
+    <artifactId>directmemory-integrations</artifactId>
+    <version>0.2-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>directmemory-guava</artifactId>
+  <name>Apache DirectMemory :: Integrations :: Guava</name>
+  <packaging>bundle</packaging>
+  <description>Provides second level cache implementation for Guava 
Cache</description>
+
+  <properties>
+    <osgi.import>
+      org.apache.directmemory*;version="${project.version}",
+      *
+    </osgi.import>
+    <osgi.export>
+      
org.apache.directmemory.guava;version="${project.version}";-noimport:=true,
+    </osgi.export>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <argLine>-Xmx512m -Xms512m -XX:MaxDirectMemorySize=512m</argLine>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <!-- DirectMemory Dependency -->
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>directmemory-cache</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>14.0.1</version>
+    </dependency>
+
+    <!-- Testing Dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+    </dependency>
+  </dependencies>
 
 </project>

Modified: 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/ForwardingListener.java
URL: 
http://svn.apache.org/viewvc/directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/ForwardingListener.java?rev=1501725&r1=1501724&r2=1501725&view=diff
==============================================================================
--- 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/ForwardingListener.java
 (original)
+++ 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/ForwardingListener.java
 Wed Jul 10 11:20:59 2013
@@ -1,3 +1,5 @@
+package org.apache.directmemory.guava;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,8 +19,6 @@
  * under the License.
  */
 
-package org.apache.directmemory.guava;
-
 import com.google.common.cache.RemovalListener;
 import com.google.common.cache.RemovalNotification;
 
@@ -26,7 +26,8 @@ import com.google.common.cache.RemovalNo
  * Listener which forwards the notifications to a delegate. It is used to 
bridge the
  * Guava Cache with DirectMemory CacheService
  */
-public class ForwardingListener<K, V> implements RemovalListener<K, V>
+public class ForwardingListener<K, V>
+    implements RemovalListener<K, V>
 {
     private RemovalListener<K, V> delegate;
 
@@ -34,21 +35,21 @@ public class ForwardingListener<K, V> im
     {
     }
 
-    public ForwardingListener(RemovalListener<K, V> delegate)
+    public ForwardingListener( RemovalListener<K, V> delegate )
     {
         this.delegate = delegate;
     }
 
     @Override
-    public void onRemoval(RemovalNotification<K, V> notification)
+    public void onRemoval( RemovalNotification<K, V> notification )
     {
-        if (delegate != null)
+        if ( delegate != null )
         {
-            delegate.onRemoval(notification);
+            delegate.onRemoval( notification );
         }
     }
 
-    public void setDelegate(RemovalListener<K, V> delegate)
+    public void setDelegate( RemovalListener<K, V> delegate )
     {
         this.delegate = delegate;
     }
@@ -58,8 +59,8 @@ public class ForwardingListener<K, V> im
         return new ForwardingListener<K, V>();
     }
 
-    public static <K, V> ForwardingListener<K, V> 
newInstance(RemovalListener<K, V> delegate)
+    public static <K, V> ForwardingListener<K, V> newInstance( 
RemovalListener<K, V> delegate )
     {
-        return new ForwardingListener<K, V>(delegate);
+        return new ForwardingListener<K, V>( delegate );
     }
 }

Modified: 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/OffHeapCache.java
URL: 
http://svn.apache.org/viewvc/directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/OffHeapCache.java?rev=1501725&r1=1501724&r2=1501725&view=diff
==============================================================================
--- 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/OffHeapCache.java
 (original)
+++ 
directmemory/trunk/integrations/guava/src/main/java/org/apache/directmemory/guava/OffHeapCache.java
 Wed Jul 10 11:20:59 2013
@@ -1,3 +1,5 @@
+package org.apache.directmemory.guava;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,8 +19,6 @@
  * under the License.
  */
 
-package org.apache.directmemory.guava;
-
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
@@ -41,100 +41,103 @@ import com.google.common.collect.Maps;
 import static com.google.common.cache.AbstractCache.SimpleStatsCounter;
 import static com.google.common.cache.AbstractCache.StatsCounter;
 
-public class OffHeapCache<K, V> extends 
ForwardingCache.SimpleForwardingCache<K, V>
-        implements RemovalListener<K, V>
+public class OffHeapCache<K, V>
+    extends ForwardingCache.SimpleForwardingCache<K, V>
+    implements RemovalListener<K, V>
 {
     private final CacheService<K, V> cacheService;
+
     private final StatsCounter statsCounter = new SimpleStatsCounter();
 
 
-    public OffHeapCache(CacheService<K, V> cacheService, Cache<K, V> 
primaryCache,
-                        ForwardingListener<K,V> listener)
+    public OffHeapCache( CacheService<K, V> cacheService, Cache<K, V> 
primaryCache, ForwardingListener<K, V> listener )
     {
-        super(primaryCache);
+        super( primaryCache );
         this.cacheService = cacheService;
-        listener.setDelegate(this);
+        listener.setDelegate( this );
     }
 
     @Override
-    public V getIfPresent(Object key)
+    public V getIfPresent( Object key )
     {
-        V result = super.getIfPresent(key);
-        if (result == null)
+        V result = super.getIfPresent( key );
+        if ( result == null )
         {
-            result = retrieve(key);
+            result = retrieve( key );
         }
         return result;
     }
 
 
     @Override
-    public V get(final K key, final Callable<? extends V> valueLoader) throws 
ExecutionException
+    public V get( final K key, final Callable<? extends V> valueLoader )
+        throws ExecutionException
     {
-        return super.get(key, new Callable<V>()
+        return super.get( key, new Callable<V>()
         {
             @Override
-            public V call() throws Exception
+            public V call()
+                throws Exception
             {
                 //Check in offHeap first
-                V result = retrieve(key);
+                V result = retrieve( key );
 
                 //Not found in L2 then load
-                if (result == null)
+                if ( result == null )
                 {
                     result = valueLoader.call();
                 }
                 return result;
             }
-        });
+        } );
     }
 
     @Override
-    public ImmutableMap<K, V> getAllPresent(Iterable<?> keys)
+    public ImmutableMap<K, V> getAllPresent( Iterable<?> keys )
     {
-        List<?> list = Lists.newArrayList(keys);
-        ImmutableMap<K, V> result = super.getAllPresent(list);
+        List<?> list = Lists.newArrayList( keys );
+        ImmutableMap<K, V> result = super.getAllPresent( list );
 
         //All the requested keys found then no
         //need to check L2
-        if (result.size() == list.size())
+        if ( result.size() == list.size() )
         {
             return result;
         }
 
         //Look up value from L2
-        Map<K, V> r2 = Maps.newHashMap(result);
-        for (Object key : list)
+        Map<K, V> r2 = Maps.newHashMap( result );
+        for ( Object key : list )
         {
-            if (!result.containsKey(key))
+            if ( !result.containsKey( key ) )
             {
-                V val = retrieve(key);
-                if (val != null)
+                V val = retrieve( key );
+                if ( val != null )
                 {
                     //Ideally the signature of method should have been
                     //getAllPresent(Iterable<? extends K> keys) in that
                     //case this cast would not have been required
-                    r2.put((K) key, val);
+                    r2.put( (K) key, val );
                 }
             }
         }
-        return ImmutableMap.copyOf(r2);
+        return ImmutableMap.copyOf( r2 );
     }
 
     @Override
-    public void invalidate(Object key)
+    public void invalidate( Object key )
     {
-        super.invalidate(key);
-        cacheService.free((K) key);
+        super.invalidate( key );
+        cacheService.free( (K) key );
     }
 
     @Override
-    public void invalidateAll(Iterable<?> keys)
+    public void invalidateAll( Iterable<?> keys )
     {
-        super.invalidateAll(keys);
-        for (Object key : keys)
+        super.invalidateAll( keys );
+        for ( Object key : keys )
         {
-            cacheService.free((K) key);
+            cacheService.free( (K) key );
         }
     }
 
@@ -151,11 +154,11 @@ public class OffHeapCache<K, V> extends 
     }
 
     @Override
-    public void onRemoval(RemovalNotification<K, V> notification)
+    public void onRemoval( RemovalNotification<K, V> notification )
     {
-        if (notification.getCause() == RemovalCause.SIZE)
+        if ( notification.getCause() == RemovalCause.SIZE )
         {
-            cacheService.put(notification.getKey(), notification.getValue());
+            cacheService.put( notification.getKey(), notification.getValue() );
         }
     }
 
@@ -164,18 +167,19 @@ public class OffHeapCache<K, V> extends 
         return statsCounter.snapshot();
     }
 
-    protected V retrieve(Object key)
+    protected V retrieve( Object key )
     {
         Stopwatch watch = new Stopwatch().start();
 
-        V value = cacheService.retrieve((K) key);
+        V value = cacheService.retrieve( (K) key );
 
-        if (value != null)
+        if ( value != null )
         {
-            
statsCounter.recordLoadSuccess(watch.elapsed(TimeUnit.NANOSECONDS));
-        } else
+            statsCounter.recordLoadSuccess( watch.elapsed( 
TimeUnit.NANOSECONDS ) );
+        }
+        else
         {
-            statsCounter.recordMisses(1);
+            statsCounter.recordMisses( 1 );
         }
 
         return value;

Modified: 
directmemory/trunk/integrations/guava/src/test/java/org/apache/directmemory/guava/GuavaCacheTest.java
URL: 
http://svn.apache.org/viewvc/directmemory/trunk/integrations/guava/src/test/java/org/apache/directmemory/guava/GuavaCacheTest.java?rev=1501725&r1=1501724&r2=1501725&view=diff
==============================================================================
--- 
directmemory/trunk/integrations/guava/src/test/java/org/apache/directmemory/guava/GuavaCacheTest.java
 (original)
+++ 
directmemory/trunk/integrations/guava/src/test/java/org/apache/directmemory/guava/GuavaCacheTest.java
 Wed Jul 10 11:20:59 2013
@@ -1,3 +1,5 @@
+package org.apache.directmemory.guava;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,8 +19,6 @@
  * under the License.
  */
 
-package org.apache.directmemory.guava;
-
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.collect.Iterables;
@@ -38,10 +38,14 @@ public class GuavaCacheTest
 {
 
     private int maxSize = 100;
+
     private int offHeapSize = 20;
-    private Cache<Integer,Integer> primaryCache;
+
+    private Cache<Integer, Integer> primaryCache;
+
     private CacheService<Integer, Integer> cacheService;
-    private OffHeapCache<Integer,Integer> cache;
+
+    private OffHeapCache<Integer, Integer> cache;
 
     @Test
     public void testEviction()
@@ -50,58 +54,61 @@ public class GuavaCacheTest
 
         //No of entries in off heap cache should be equal to the extra entries
         //over and above the maxSize specified for Cache as those would be 
evicted
-        assertEquals(offHeapSize, cacheService.entries());
+        assertEquals( offHeapSize, cacheService.entries() );
 
-        for(int i = 0; i < maxSize + offHeapSize; i++)
+        for ( int i = 0; i < maxSize + offHeapSize; i++ )
         {
-            Integer ignored = cache.getIfPresent(i);
+            Integer ignored = cache.getIfPresent( i );
         }
 
-        assertEquals(offHeapSize, cache.offHeapStats().loadCount());
+        assertEquals( offHeapSize, cache.offHeapStats().loadCount() );
     }
 
     @Test
-    public void testWithLoader() throws ExecutionException
+    public void testWithLoader()
+        throws ExecutionException
     {
         createScenario();
 
         Callable<Integer> testCallable = new Callable<Integer>()
         {
             @Override
-            public Integer call() throws Exception
+            public Integer call()
+                throws Exception
             {
                 return -1;
             }
         };
 
-        Integer result = cache.get(1000,testCallable);
-        assertEquals(new Integer(-1),result);
+        Integer result = cache.get( 1000, testCallable );
+        assertEquals( new Integer( -1 ), result );
     }
 
     @Test
-    public void testInvalidate(){
+    public void testInvalidate()
+    {
         createScenario();
 
         //Find a key which is actually part of L2
-        Integer key = Iterables.get(cacheService.getMap().keySet(),0);
+        Integer key = Iterables.get( cacheService.getMap().keySet(), 0 );
 
-        cache.invalidate(key);
+        cache.invalidate( key );
 
-        assertNull(cacheService.retrieve(key));
+        assertNull( cacheService.retrieve( key ) );
     }
 
     @Test
     public void testInvalidateAllWithKeys()
     {
         createScenario();
-        Integer keyInL1 = Iterables.get(cache.asMap().keySet(), 0);
-        Integer keyInL2 = Iterables.get(cacheService.getMap().keySet(),0);
+        Integer keyInL1 = Iterables.get( cache.asMap().keySet(), 0 );
+        Integer keyInL2 = Iterables.get( cacheService.getMap().keySet(), 0 );
 
-        Iterable<Integer> keys = Lists.newArrayList(keyInL1,keyInL2);
-        cache.invalidateAll(keys);
+        Iterable<Integer> keys = Lists.newArrayList( keyInL1, keyInL2 );
+        cache.invalidateAll( keys );
 
-        assertNull(cacheService.retrieve(keyInL2));
-        assertNull(cache.getIfPresent(keyInL1));
+        assertNull( cacheService.retrieve( keyInL2 ) );
+        assertNull( cache.getIfPresent( keyInL1 ) );
     }
 
     @Test
@@ -109,57 +116,49 @@ public class GuavaCacheTest
     {
         createScenario();
         cache.invalidateAll();
-        assertEquals(0,cacheService.entries());
+        assertEquals( 0, cacheService.entries() );
     }
 
     @Test
     public void getAllPresent()
     {
         createScenario();
-        Integer keyInL1 = Iterables.get(cache.asMap().keySet(), 0);
-        Integer keyInL2 = Iterables.get(cacheService.getMap().keySet(),0);
+        Integer keyInL1 = Iterables.get( cache.asMap().keySet(), 0 );
+        Integer keyInL2 = Iterables.get( cacheService.getMap().keySet(), 0 );
 
-        Iterable<Integer> keys = Lists.newArrayList(keyInL1,keyInL2,1000);
-        Map<Integer,Integer> result = cache.getAllPresent(keys);
+        Iterable<Integer> keys = Lists.newArrayList( keyInL1, keyInL2, 1000 );
+        Map<Integer, Integer> result = cache.getAllPresent( keys );
 
-        assertEquals(2,result.size());
-        assertEquals(result.get(keyInL1),keyInL1);
-        assertEquals(result.get(keyInL2),keyInL2);
+        assertEquals( 2, result.size() );
+        assertEquals( result.get( keyInL1 ), keyInL1 );
+        assertEquals( result.get( keyInL2 ), keyInL2 );
 
-        Iterable<Integer> keys2 = Lists.newArrayList(keyInL1);
-        Map<Integer,Integer> result2 = cache.getAllPresent(keys2);
+        Iterable<Integer> keys2 = Lists.newArrayList( keyInL1 );
+        Map<Integer, Integer> result2 = cache.getAllPresent( keys2 );
 
-        assertEquals(1,result2.size());
-        assertEquals(result2.get(keyInL1),keyInL1);
+        assertEquals( 1, result2.size() );
+        assertEquals( result2.get( keyInL1 ), keyInL1 );
     }
 
     private void createScenario()
     {
         //1. First create a bridge listener
-        ForwardingListener<Integer,Integer> listener = 
ForwardingListener.newInstance();
+        ForwardingListener<Integer, Integer> listener = 
ForwardingListener.newInstance();
 
         //2. Second create the Guava cache with the bridge listener
-        primaryCache =
-                CacheBuilder.newBuilder()
-                        .maximumSize(maxSize)
-                        .removalListener(listener)
-                        .build();
+        primaryCache = CacheBuilder.newBuilder().maximumSize( maxSize 
).removalListener( listener ).build();
 
         //3. Create the CacheService
-        cacheService =
-                new DirectMemory<Integer, Integer>().setNumberOfBuffers( 10 )
-                        .setSize(1000)
-                        .setInitialCapacity(10000)
-                        .setConcurrencyLevel(4)
-                        .newCacheService();
+        cacheService = new DirectMemory<Integer, 
Integer>().setNumberOfBuffers( 10 ).setSize( 1000 ).setInitialCapacity(
+            10000 ).setConcurrencyLevel( 4 ).newCacheService();
 
         //4. Create the L2 cache with bridge listener and Guava cache
-        cache = new OffHeapCache<Integer, 
Integer>(cacheService,primaryCache,listener);
+        cache = new OffHeapCache<Integer, Integer>( cacheService, 
primaryCache, listener );
 
         //Add number of entries so as to cause overflow and thus trigger 
eviction
-        for(int i = 0; i < maxSize + offHeapSize; i++)
+        for ( int i = 0; i < maxSize + offHeapSize; i++ )
         {
-            cache.put(i,i);
+            cache.put( i, i );
         }
     }
 


Reply via email to