コード例 #1
0
 private Collection<MultiMapRecord> createCollection(Collection<MultiMapRecord> coll) {
   if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.SET)) {
     return new HashSet<MultiMapRecord>(coll);
   } else if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.LIST)) {
     return new ArrayList<MultiMapRecord>(coll);
   }
   return null;
 }
コード例 #2
0
 public <V> Collection<V> createNew() {
   if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.SET)) {
     return new HashSet<V>(10);
   } else if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.LIST)) {
     return new LinkedList<V>();
   }
   throw new IllegalArgumentException("No Matching CollectionProxyType!");
 }
コード例 #3
0
ファイル: Config.java プロジェクト: GokcerBelgusen/hazelcast
 public MultiMapConfig findMultiMapConfig(String name) {
   String baseName = getBaseName(name);
   MultiMapConfig config = lookupByPattern(multiMapConfigs, baseName);
   if (config != null) {
     return config.getAsReadOnly();
   }
   return getMultiMapConfig("default").getAsReadOnly();
 }
コード例 #4
0
ファイル: MultiMapConfig.java プロジェクト: notz/hazelcast
 public MultiMapConfig(MultiMapConfig defConfig) {
   this.name = defConfig.getName();
   this.valueCollectionType = defConfig.valueCollectionType;
   this.binary = defConfig.binary;
   this.syncBackupCount = defConfig.syncBackupCount;
   this.asyncBackupCount = defConfig.asyncBackupCount;
   this.statisticsEnabled = defConfig.statisticsEnabled;
   this.listenerConfigs = new ArrayList<EntryListenerConfig>(defConfig.getEntryListenerConfigs());
 }
コード例 #5
0
 private Collection<Data> createCollection(int size) {
   final MultiMapConfig config = getClientEngine().getConfig().findMultiMapConfig(name);
   if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.SET)) {
     return new HashSet<Data>(size);
   } else if (config.getValueCollectionType().equals(MultiMapConfig.ValueCollectionType.LIST)) {
     return new ArrayList<Data>(size);
   }
   return null;
 }
コード例 #6
0
 protected boolean putInternal(Data key, Data value) {
   throwExceptionIfNull(key);
   throwExceptionIfNull(value);
   Collection<MultiMapRecord> coll = txMap.get(key);
   long recordId = -1;
   long timeout = tx.getTimeoutMillis();
   long ttl = extendTimeout(timeout);
   final MultiMapTransactionLog log;
   if (coll == null) {
     MultiMapResponse response = lockAndGet(key, timeout, ttl);
     if (response == null) {
       throw new ConcurrentModificationException(
           "Transaction couldn't obtain lock " + getThreadId());
     }
     recordId = response.getNextRecordId();
     coll = createCollection(response.getRecordCollection(getNodeEngine()));
     txMap.put(key, coll);
     log = new MultiMapTransactionLog(key, name, ttl, getThreadId());
     tx.addTransactionLog(log);
   } else {
     log = (MultiMapTransactionLog) tx.getTransactionLog(getTxLogKey(key));
   }
   MultiMapRecord record =
       new MultiMapRecord(config.isBinary() ? value : getNodeEngine().toObject(value));
   if (coll.add(record)) {
     if (recordId == -1) {
       recordId = nextId(key);
     }
     record.setRecordId(recordId);
     TxnPutOperation operation = new TxnPutOperation(name, key, value, recordId);
     log.addOperation(operation);
     return true;
   }
   return false;
 }
コード例 #7
0
ファイル: Config.java プロジェクト: GokcerBelgusen/hazelcast
 public MultiMapConfig getMultiMapConfig(String name) {
   String baseName = getBaseName(name);
   MultiMapConfig config = lookupByPattern(multiMapConfigs, baseName);
   if (config != null) {
     return config;
   }
   MultiMapConfig defConfig = multiMapConfigs.get("default");
   if (defConfig == null) {
     defConfig = new MultiMapConfig();
     defConfig.setName("default");
     addMultiMapConfig(defConfig);
   }
   config = new MultiMapConfig(defConfig);
   config.setName(name);
   addMultiMapConfig(config);
   return config;
 }
コード例 #8
0
 @Test
 public void testMultimapConfig() {
   MultiMapConfig testMultiMapConfig = config.getMultiMapConfig("testMultimap");
   assertEquals(
       MultiMapConfig.ValueCollectionType.LIST, testMultiMapConfig.getValueCollectionType());
   assertEquals(2, testMultiMapConfig.getEntryListenerConfigs().size());
   for (EntryListenerConfig listener : testMultiMapConfig.getEntryListenerConfigs()) {
     if (listener.getClassName() != null) {
       assertNull(listener.getImplementation());
       assertTrue(listener.isIncludeValue());
       assertFalse(listener.isLocal());
     } else {
       assertNotNull(listener.getImplementation());
       assertEquals(entryListener, listener.getImplementation());
       assertTrue(listener.isLocal());
       assertTrue(listener.isIncludeValue());
     }
   }
 }
コード例 #9
0
 protected boolean removeInternal(Data key, Data value) {
   throwExceptionIfNull(key);
   throwExceptionIfNull(value);
   Collection<MultiMapRecord> coll = txMap.get(key);
   long timeout = tx.getTimeoutMillis();
   long ttl = extendTimeout(timeout);
   final MultiMapTransactionLog log;
   if (coll == null) {
     MultiMapResponse response = lockAndGet(key, timeout, ttl);
     if (response == null) {
       throw new ConcurrentModificationException(
           "Transaction couldn't obtain lock " + getThreadId());
     }
     coll = createCollection(response.getRecordCollection(getNodeEngine()));
     txMap.put(key, coll);
     log = new MultiMapTransactionLog(key, name, ttl, getThreadId());
     tx.addTransactionLog(log);
   } else {
     log = (MultiMapTransactionLog) tx.getTransactionLog(getTxLogKey(key));
   }
   MultiMapRecord record =
       new MultiMapRecord(config.isBinary() ? value : getNodeEngine().toObject(value));
   Iterator<MultiMapRecord> iterator = coll.iterator();
   long recordId = -1;
   while (iterator.hasNext()) {
     MultiMapRecord r = iterator.next();
     if (r.equals(record)) {
       iterator.remove();
       recordId = r.getRecordId();
       break;
     }
   }
   if (recordId != -1) {
     TxnRemoveOperation operation = new TxnRemoveOperation(name, key, recordId, value);
     log.addOperation(operation);
     return recordId != -1;
   }
   return false;
 }
コード例 #10
0
 private <T> T invoke(Operation operation, Data dataKey) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
     Invocation invocation =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId)
             .build();
     Future f;
     Object o;
     if (config.isStatisticsEnabled()) {
       long time = System.currentTimeMillis();
       f = invocation.invoke();
       o = f.get();
       if (operation instanceof PutOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementPuts(System.currentTimeMillis() - time);
       } else if (operation instanceof RemoveOperation
           || operation instanceof RemoveAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementRemoves(System.currentTimeMillis() - time);
       } else if (operation instanceof GetAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementGets(System.currentTimeMillis() - time);
       }
     } else {
       f = invocation.invoke();
       o = f.get();
     }
     return (T) nodeEngine.toObject(o);
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
コード例 #11
0
ファイル: Config.java プロジェクト: GokcerBelgusen/hazelcast
 public Config addMultiMapConfig(MultiMapConfig multiMapConfig) {
   multiMapConfigs.put(multiMapConfig.getName(), multiMapConfig);
   return this;
 }