servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ioca...@apache.org
Subject svn commit: r1076225 - in /servicemix/utils/trunk/src: main/java/org/apache/servicemix/store/hazelcast/ test/java/org/apache/servicemix/store/hazelcast/
Date Wed, 02 Mar 2011 14:04:04 GMT
Author: iocanel
Date: Wed Mar  2 14:04:03 2011
New Revision: 1076225

URL: http://svn.apache.org/viewvc?rev=1076225&view=rev
Log:
[SM-2061] Hazelcast store now supports injection of the hazelcast instance.

Modified:
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
    servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStoreFactory.java
    servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java?rev=1076225&r1=1076224&r2=1076225&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
(original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStore.java
Wed Mar  2 14:04:03 2011
@@ -18,6 +18,7 @@
 package org.apache.servicemix.store.hazelcast;
 
 import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.IdGenerator;
 import java.io.IOException;
 import java.io.Serializable;
@@ -37,29 +38,42 @@ public class HazelcastStore implements S
 
     private Map<String, Entry> datas;
 
+    private HazelcastInstance hazelcastInstance;
     private IdGenerator idGenerator;
     private final long timeout;
 
     /**
      * Constructor
-     * @param idGenerator
      * @param name
      */
-    public HazelcastStore(IdGenerator idGenerator,String name) {
-        this.idGenerator = idGenerator;
-        this.datas = Hazelcast.getMap(name);
+    public HazelcastStore(String name) {
+        this.hazelcastInstance = Hazelcast.newHazelcastInstance(null);
+        this.idGenerator = hazelcastInstance.getIdGenerator(name);
+        this.datas = hazelcastInstance.getMap(name);
+        this.timeout=-1;
+    }
+    /**
+     * Constructor
+     * @param hazelcastInstance
+     * @param name
+     */
+    public HazelcastStore(HazelcastInstance hazelcastInstance,String name) {
+        this.hazelcastInstance = hazelcastInstance;
+        this.idGenerator = hazelcastInstance.getIdGenerator(name);
+        this.datas = hazelcastInstance.getMap(name);
         this.timeout=-1;        
     }
-    
+
     /**
      * Constructor
-     * @param idGenerator
+     * @param hazelcastInstance
      * @param name
      * @param timemout
      */
-    public HazelcastStore(IdGenerator idGenerator,String name, long timemout) {
-        this.idGenerator = idGenerator;
-        this.datas = Hazelcast.getMap(name);
+    public HazelcastStore(HazelcastInstance hazelcastInstance,String name, long timemout)
{
+        this.hazelcastInstance = hazelcastInstance;
+        this.idGenerator = hazelcastInstance.getIdGenerator(name);
+        this.datas = hazelcastInstance.getMap(name);
         this.timeout=timemout;
     }
 

Modified: servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStoreFactory.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStoreFactory.java?rev=1076225&r1=1076224&r2=1076225&view=diff
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStoreFactory.java
(original)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/hazelcast/HazelcastStoreFactory.java
Wed Mar  2 14:04:03 2011
@@ -18,47 +18,66 @@
 package org.apache.servicemix.store.hazelcast;
 
 import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.IdGenerator;
+
 import java.io.IOException;
 import java.util.Map;
+
 import org.apache.servicemix.store.Store;
 
 
 /**
- *
  * @author iocanel
  */
 public class HazelcastStoreFactory {
-        
-    private Map<String, HazelcastStore> stores = Hazelcast.getMap(STORE_PREFIX);
+
+    private Map<String, HazelcastStore> stores;
+
+    private HazelcastInstance hazelcastInstance;
     private long timeout = -1;
-    
-    public static final String STORE_PREFIX="org.apache.servicemix.stores";
-    
+
+    public static final String STORE_PREFIX = "org.apache.servicemix.stores";
+
     public synchronized Store open(String name) throws IOException {
+        if (hazelcastInstance == null) {
+            hazelcastInstance = Hazelcast.newHazelcastInstance(null);
+        }
+        stores = hazelcastInstance.getMap(STORE_PREFIX);
         HazelcastStore store = stores.get(name);
-        String storeName = STORE_PREFIX+"."+name;
+        String storeName = STORE_PREFIX + "." + name;
         if (store == null) {
+            IdGenerator idGenerator = hazelcastInstance.getIdGenerator(storeName);
             if (timeout <= 0) {
-                store = new HazelcastStore(Hazelcast.getIdGenerator(storeName),storeName);
+                store = new HazelcastStore(hazelcastInstance, storeName);
             } else {
-                store = new HazelcastStore(Hazelcast.getIdGenerator(storeName), storeName,
timeout);
+                store = new HazelcastStore(hazelcastInstance, storeName, timeout);
             }
             stores.put(name, store);
         }
         return store;
     }
-    
+
     /* (non-Javadoc)
-     * @see org.apache.servicemix.store.ExchangeStoreFactory#release(org.apache.servicemix.store.ExchangeStore)
-     */
+    * @see org.apache.servicemix.store.ExchangeStoreFactory#release(org.apache.servicemix.store.ExchangeStore)
+    */
     public synchronized void close(Store store) throws IOException {
         stores.remove(store);
     }
-    
+
+    public long getTimeout() {
+        return timeout;
+    }
+
     public void setTimeout(long timeout) {
         this.timeout = timeout;
     }
-    
 
+    public HazelcastInstance getHazelcastInstance() {
+        return hazelcastInstance;
+    }
+
+    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        this.hazelcastInstance = hazelcastInstance;
+    }
 }

Modified: servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java?rev=1076225&r1=1076224&r2=1076225&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java
(original)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/store/hazelcast/HazelcastStoreTest.java
Wed Mar  2 14:04:03 2011
@@ -35,10 +35,12 @@ public class HazelcastStoreTest extends 
 
     private Store store;
     private final HazelcastStoreFactory factory = new HazelcastStoreFactory();
+    private HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(null);
     
     public HazelcastStoreTest() {
         super();
         factory.setTimeout(TIMEOUT);
+        factory.setHazelcastInstance(hazelcastInstance);
     }
     
     @Override



Mime
View raw message