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;
 }
 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
 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
 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());
 }
 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;
 }
 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
 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;
 }
 @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());
     }
   }
 }
 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;
 }
 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
 public Config addMultiMapConfig(MultiMapConfig multiMapConfig) {
   multiMapConfigs.put(multiMapConfig.getName(), multiMapConfig);
   return this;
 }