gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [05/17] gora git commit: refactored and improved logging
Date Fri, 05 Aug 2016 10:41:28 GMT
refactored and improved logging


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/fd80478e
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/fd80478e
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/fd80478e

Branch: refs/heads/master
Commit: fd80478e376790856b399f472283e58c3969f8fa
Parents: 29a3f61
Author: Kevin Ratnasekera <djkevincr@yahoo.com>
Authored: Sun Jul 31 14:16:00 2016 +0530
Committer: Kevin Ratnasekera <djkevincr@yahoo.com>
Committed: Sun Jul 31 14:16:00 2016 +0530

----------------------------------------------------------------------
 .../gora/persistency/impl/PersistentBase.java   |  1 -
 .../mapreduce/TestPersistentSerialization.java  |  2 --
 .../jcache/store/JCacheCacheEntryListener.java  | 28 ++++++++++++++++++--
 .../store/JCacheCacheEntryListenerFactory.java  |  5 ++--
 .../gora/jcache/store/JCacheCacheLoader.java    |  5 ++--
 .../jcache/store/JCacheCacheLoaderFactory.java  |  4 +--
 .../gora/jcache/store/JCacheCacheWriter.java    |  5 ++--
 .../jcache/store/JCacheCacheWriterFactory.java  |  4 +--
 .../apache/gora/jcache/store/JCacheStore.java   | 24 ++++++++++++++++-
 9 files changed, 60 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
b/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
index 3d316b5..691684e 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
@@ -40,7 +40,6 @@ public abstract class PersistentBase extends SpecificRecordBase implements
 
   public PersistentBase() {
     __g__dirty = new byte[getFieldsCount()];
-    //__g__dirty = java.nio.ByteBuffer.wrap(new byte[getFieldsCount()]);
   }
 
   public abstract int getFieldsCount();

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-core/src/test/java/org/apache/gora/mapreduce/TestPersistentSerialization.java
----------------------------------------------------------------------
diff --git a/gora-core/src/test/java/org/apache/gora/mapreduce/TestPersistentSerialization.java
b/gora-core/src/test/java/org/apache/gora/mapreduce/TestPersistentSerialization.java
index fee4460..141e9cf 100644
--- a/gora-core/src/test/java/org/apache/gora/mapreduce/TestPersistentSerialization.java
+++ b/gora-core/src/test/java/org/apache/gora/mapreduce/TestPersistentSerialization.java
@@ -144,8 +144,6 @@ public class TestPersistentSerialization {
     page2.getParsedContent().add(new StringBuffer("coo2"));
     page3.setParsedContent(new ArrayList<CharSequence>());
     page3.getParsedContent().add(new StringBuffer("coo3"));
-    //page2.setOutlinks(new HashMap<CharSequence, CharSequence>());
-    //page2.getOutlinks().put(new StringBuffer("a"), new StringBuffer("b"));
 
     TestIOUtils.testSerializeDeserialize(page1, page2, page3);
   }

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
index 9284463..f7c9d36 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
@@ -18,17 +18,22 @@
 package org.apache.gora.jcache.store;
 
 import org.apache.gora.persistency.impl.PersistentBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import javax.cache.event.CacheEntryExpiredListener;
+import javax.cache.event.CacheEntryUpdatedListener;
 import javax.cache.event.CacheEntryCreatedListener;
+import javax.cache.event.CacheEntryRemovedListener;
 import javax.cache.event.CacheEntryEvent;
 import javax.cache.event.CacheEntryListenerException;
-import javax.cache.event.CacheEntryRemovedListener;
 import java.util.concurrent.ConcurrentSkipListSet;
 
 public class JCacheCacheEntryListener<K, T extends PersistentBase>
         implements CacheEntryCreatedListener<K, T>,
-        CacheEntryRemovedListener<K, T> {
+        CacheEntryRemovedListener<K, T>, CacheEntryUpdatedListener<K, T>, CacheEntryExpiredListener<K,
T> {
 
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheEntryListener.class);
   private ConcurrentSkipListSet<K> cacheEntryList;
 
   public JCacheCacheEntryListener(ConcurrentSkipListSet cacheEntryList) {
@@ -40,6 +45,7 @@ public class JCacheCacheEntryListener<K, T extends PersistentBase>
           throws CacheEntryListenerException {
     for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
       cacheEntryList.add(event.getKey());
+      LOG.info("Cache entry added on key " + event.getKey().toString());
     }
   }
 
@@ -48,6 +54,24 @@ public class JCacheCacheEntryListener<K, T extends PersistentBase>
           throws CacheEntryListenerException {
     for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
       cacheEntryList.remove(event.getKey());
+      LOG.info("Cache entry removed on key " + event.getKey().toString());
+    }
+  }
+
+  @Override
+  public void onUpdated(Iterable<CacheEntryEvent<? extends K, ? extends T>> cacheEntryEvents)
+          throws CacheEntryListenerException {
+    for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
+      LOG.info("Cache entry updated set on key " + event.getKey().toString());
     }
   }
+
+  @Override
+  public void onExpired(Iterable<CacheEntryEvent<? extends K, ? extends T>> cacheEntryEvents)
+          throws CacheEntryListenerException {
+    for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
+      LOG.warn("Cache entry expired on key " + event.getKey().toString());
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
index 8525d2a..42b3c93 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
@@ -26,11 +26,12 @@ import javax.cache.configuration.Factory;
 public class JCacheCacheEntryListenerFactory <K,T extends PersistentBase>
         implements Factory<JCacheCacheEntryListener<K, T>> {
 
-  public static final long serialVersionUID = 201305101634L;
   private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheEntryListenerFactory.class);
-  private JCacheCacheEntryListener<K, T> instance;
+  public static final long serialVersionUID = 201305101634L;
+  private transient JCacheCacheEntryListener<K, T> instance;
 
   public JCacheCacheEntryListenerFactory(JCacheCacheEntryListener<K, T> instance) {
+    LOG.info("JCache cache entry listener factory initialized successfully.");
     this.instance = instance;
   }
 

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
index 3371a3e..74e910a 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
@@ -19,9 +19,6 @@ package org.apache.gora.jcache.store;
 
 import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.store.DataStore;
-import org.apache.gora.store.DataStoreFactory;
-import org.apache.gora.util.GoraException;
-import org.apache.hadoop.conf.Configuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,6 +42,7 @@ public class JCacheCacheLoader<K, T extends PersistentBase> implements
CacheLoad
     T persistent = null;
     try {
       persistent = dataStore.get(key);
+      LOG.info("Loaded data bean from persistent datastore on key " + key.toString());
     } catch (CacheLoaderException ex) {
       throw ex;
     }
@@ -56,6 +54,7 @@ public class JCacheCacheLoader<K, T extends PersistentBase> implements
CacheLoad
     Map<K, T> loaded = new HashMap<K, T>();
     for (K key : keys) {
       T persistent = dataStore.get(key);
+      LOG.info("Loaded data bean from persistent datastore on key " + key.toString());
       if (persistent != null) {
         loaded.put(key, persistent);
       }

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
index cdbc2f1..b1f59d2 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
@@ -22,16 +22,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.cache.configuration.Factory;
-import java.lang.reflect.Constructor;
 
 public class JCacheCacheLoaderFactory<K, T extends PersistentBase>
         implements Factory<JCacheCacheLoader<K,T>> {
 
-  public static final long serialVersionUID = 201305101626L;
   private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheLoaderFactory.class);
+  public static final long serialVersionUID = 201305101626L;
   private transient JCacheCacheLoader<K, T> instance;
 
   public JCacheCacheLoaderFactory(JCacheCacheLoader<K, T> instance) {
+    LOG.info("JCache cache entry loader factory initialized successfully.");
     this.instance = instance;
   }
 

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
index 7329421..e9c4373 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
@@ -19,9 +19,6 @@ package org.apache.gora.jcache.store;
 
 import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.store.DataStore;
-import org.apache.gora.store.DataStoreFactory;
-import org.apache.gora.util.GoraException;
-import org.apache.hadoop.conf.Configuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,6 +41,7 @@ public class JCacheCacheWriter<K, T extends PersistentBase> implements
CacheWrit
   public void write(Cache.Entry<? extends K,
           ? extends T> entry) throws CacheWriterException {
     dataStore.put(entry.getKey(), entry.getValue());
+    LOG.info("Written data bean to persistent datastore on key " + entry.getKey().toString());
   }
 
   @Override
@@ -59,6 +57,7 @@ public class JCacheCacheWriter<K, T extends PersistentBase> implements
CacheWrit
   @Override
   public void delete(Object key) throws CacheWriterException {
     dataStore.delete((K) key);
+    LOG.info("Deleted data bean from persistent datastore on key " + key.toString());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
index 29fa3fc..5743b5a 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
@@ -22,15 +22,15 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.cache.configuration.Factory;
-import java.lang.reflect.Constructor;
 
 public class JCacheCacheWriterFactory<K, T extends PersistentBase> implements Factory<JCacheCacheWriter<K,T>>
{
 
-  public static final long serialVersionUID = 201205101621L;
   private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheWriterFactory.class);
+  public static final long serialVersionUID = 201205101621L;
   private transient JCacheCacheWriter<K,T> instance;
 
   public JCacheCacheWriterFactory(JCacheCacheWriter<K,T> instance) {
+    LOG.info("JCache entry writer factory initialized successfully.");
     this.instance = instance;
   }
 

http://git-wip-us.apache.org/repos/asf/gora/blob/fd80478e/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
index 1440644..4838cfe 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
@@ -32,6 +32,7 @@ import com.hazelcast.cache.ICache;
 import com.hazelcast.config.CacheConfig;
 import com.hazelcast.config.EvictionConfig;
 import com.hazelcast.config.EvictionPolicy;
+import com.hazelcast.config.InMemoryFormat;
 import com.hazelcast.core.Hazelcast;
 import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.Member;
@@ -86,6 +87,10 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
   private static final String JCACHE_CREATED_EXPIRY_IDENTIFIER = "CREATED";
   private static final String JCACHE_MODIFIED_EXPIRY_IDENTIFIER = "MODIFIED";
   private static final String JCACHE_TOUCHED_EXPIRY_IDENTIFIER = "TOUCHED";
+  private static final String HAZELCAST_CACHE_IN_MEMORY_FORMAT_PROPERTY_KEY = "jcache.cache.inmemory.format";
+  private static final String HAZELCAST_CACHE_BINARY_IN_MEMORY_FORMAT_IDENTIFIER = "BINARY";
+  private static final String HAZELCAST_CACHE_OBJECT_IN_MEMORY_FORMAT_IDENTIFIER = "OBJECT";
+  private static final String HAZELCAST_CACHE_NATIVE_IN_MEMORY_FORMAT_IDENTIFIER = "NATIVE";
   private String goraCacheNamespace = GORA_DEFAULT_JCACHE_NAMESPACE;
   private static final Logger LOG = LoggerFactory.getLogger(JCacheStore.class);
   private DataStore<K, T> persistentDataStore;
@@ -172,6 +177,14 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
         ));
       }
     }
+    if (properties.getProperty(HAZELCAST_CACHE_IN_MEMORY_FORMAT_PROPERTY_KEY) != null) {
+      String inMemoryFormat = properties.getProperty(HAZELCAST_CACHE_IN_MEMORY_FORMAT_PROPERTY_KEY);
+      if (inMemoryFormat.equals(HAZELCAST_CACHE_BINARY_IN_MEMORY_FORMAT_IDENTIFIER) ||
+              inMemoryFormat.equals(HAZELCAST_CACHE_OBJECT_IN_MEMORY_FORMAT_IDENTIFIER) ||
+              inMemoryFormat.equals(HAZELCAST_CACHE_NATIVE_IN_MEMORY_FORMAT_IDENTIFIER))
{
+        cacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(inMemoryFormat));
+      }
+    }
     cacheConfig.setCacheLoaderFactory(JCacheCacheFactoryBuilder
             .factoryOfCacheLoader(this.persistentDataStore));
     cacheConfig.setCacheWriterFactory(JCacheCacheFactoryBuilder
@@ -185,6 +198,7 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
     );
     cache = manager.createCache(persistentClass.getSimpleName(),
             cacheConfig).unwrap(ICache.class);
+    LOG.info("JCache Gora datastore initialized successfully.");
   }
 
   @Override
@@ -199,12 +213,16 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
               cacheConfig).unwrap(ICache.class);
     }
     persistentDataStore.createSchema();
+    LOG.info("Created schema on persistent store and initialized cache for persistent bean
"
+            + super.getPersistentClass().getSimpleName());
   }
 
   @Override
   public void deleteSchema() {
     manager.destroyCache(super.getPersistentClass().getSimpleName());
     persistentDataStore.deleteSchema();
+    LOG.info("Deleted schema on persistent store and destroyed cache for persistent bean
"
+            + super.getPersistentClass().getSimpleName());
   }
 
   @Override
@@ -283,8 +301,10 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
           }
         }
       }
+      LOG.info("JCache Gora datastore deleled " + deletedRows + " rows from Persistent datastore");
       return deletedRows;
     } catch (Exception e) {
+      LOG.error("Exception occured while deleting entries from JCache Gora datastore. Hence
returning 0");
       return 0;
     }
   }
@@ -308,7 +328,7 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
     try {
       cacheEntrySubList = (ConcurrentSkipListSet<K>) cacheEntryList.subSet(startKey,
true, endKey, true);
     } catch (NullPointerException npe) {
-      LOG.error("NPE occurred while executing the query for JCacheStore");
+      LOG.error("NPE occurred while executing the query for JCacheStore. Hence returning
empty entry set.");
       return new JCacheResult<>(this, query, new ConcurrentSkipListSet<K>());
     }
     return new JCacheResult<>(this, query, cacheEntrySubList);
@@ -350,6 +370,7 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
   @Override
   public void flush() {
     persistentDataStore.flush();
+    LOG.info("JCache Gora datastore flushed successfully.");
   }
 
   @Override
@@ -362,6 +383,7 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
       manager.close();
     }
     persistentDataStore.close();
+    LOG.info("JCache Gora datastore destroyed successfully.");
   }
 
 }


Mime
View raw message