示例#1
0
 public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
   LockRequest request =
       new LockRequest(
           getKeyData(), ThreadUtil.getThreadId(), Long.MAX_VALUE, getTimeInMillis(time, unit));
   Boolean result = invoke(request);
   return result;
 }
示例#2
0
 @Override
 public boolean evict(K key) {
   final Data keyData = toData(key);
   MapEvictRequest request = new MapEvictRequest(name, keyData, ThreadUtil.getThreadId());
   Boolean result = invoke(request);
   return result;
 }
示例#3
0
 private Object invokeOperation(Data key, MapOperation operation) {
   int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     Object result;
     if (statisticsEnabled) {
       long time = System.currentTimeMillis();
       Future future =
           operationService
               .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
               .setResultDeserialized(false)
               .invoke();
       result = future.get();
       mapServiceContext.incrementOperationStats(time, localMapStats, name, operation);
     } else {
       Future future =
           operationService
               .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
               .setResultDeserialized(false)
               .invoke();
       result = future.get();
     }
     return result;
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#4
0
 @Override
 public V replace(K key, V value) {
   final Data keyData = toData(key);
   final Data valueData = toData(value);
   MapReplaceRequest request =
       new MapReplaceRequest(name, keyData, valueData, ThreadUtil.getThreadId());
   return invoke(request, keyData);
 }
  public void unlock(K key) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);

    final Data keyData = toData(key);
    ClientMessage request =
        MultiMapUnlockCodec.encodeRequest(name, keyData, ThreadUtil.getThreadId());
    invoke(request, keyData);
  }
示例#6
0
 @Override
 public void lock(K key, long leaseTime, TimeUnit timeUnit) {
   final Data keyData = toData(key);
   MapLockRequest request =
       new MapLockRequest(
           name, keyData, ThreadUtil.getThreadId(), getTimeInMillis(leaseTime, timeUnit), -1);
   invoke(request, keyData);
 }
示例#7
0
 @Override
 public boolean tryRemove(K key, long timeout, TimeUnit timeunit) {
   final Data keyData = toData(key);
   MapTryRemoveRequest request =
       new MapTryRemoveRequest(
           name, keyData, ThreadUtil.getThreadId(), timeunit.toMillis(timeout));
   Boolean result = invoke(request, keyData);
   return result;
 }
示例#8
0
 @Override
 public void set(K key, V value, long ttl, TimeUnit timeunit) {
   final Data keyData = toData(key);
   final Data valueData = toData(value);
   MapSetRequest request =
       new MapSetRequest(
           name, keyData, valueData, ThreadUtil.getThreadId(), getTimeInMillis(ttl, timeunit));
   invoke(request, keyData);
 }
示例#9
0
 @Override
 public boolean remove(Object key, Object value) {
   final Data keyData = toData(key);
   final Data valueData = toData(value);
   MapRemoveIfSameRequest request =
       new MapRemoveIfSameRequest(name, keyData, valueData, ThreadUtil.getThreadId());
   Boolean result = invoke(request, keyData);
   return result;
 }
  public void lock(K key, long leaseTime, TimeUnit timeUnit) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
    checkPositive(leaseTime, "leaseTime should be positive");

    final Data keyData = toData(key);
    ClientMessage request =
        MultiMapLockCodec.encodeRequest(
            name, keyData, ThreadUtil.getThreadId(), getTimeInMillis(leaseTime, timeUnit));
    invoke(request, keyData);
  }
示例#11
0
 @Override
 public boolean replace(K key, V oldValue, V newValue) {
   final Data keyData = toData(key);
   final Data oldValueData = toData(oldValue);
   final Data newValueData = toData(newValue);
   MapReplaceIfSameRequest request =
       new MapReplaceIfSameRequest(
           name, keyData, oldValueData, newValueData, ThreadUtil.getThreadId());
   Boolean result = invoke(request, keyData);
   return result;
 }
  public int valueCount(K key) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);

    Data keyData = toData(key);
    ClientMessage request =
        MultiMapValueCountCodec.encodeRequest(name, keyData, ThreadUtil.getThreadId());
    ClientMessage response = invoke(request, keyData);
    MultiMapValueCountCodec.ResponseParameters resultParameters =
        MultiMapValueCountCodec.decodeResponse(response);
    return resultParameters.response;
  }
示例#13
0
 protected Object getInternal(Data key) {
   // todo action for read-backup true is not well tested.
   if (getMapConfig().isReadBackupData()) {
     Object fromBackup = readBackupDataOrNull(key);
     if (fromBackup != null) {
       return fromBackup;
     }
   }
   MapOperation operation = operationProvider.createGetOperation(name, key);
   operation.setThreadId(ThreadUtil.getThreadId());
   return invokeOperation(key, operation);
 }
示例#14
0
 protected EntryView getEntryViewInternal(Data key) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createGetEntryViewOperation(name, key);
   operation.setThreadId(ThreadUtil.getThreadId());
   operation.setServiceName(SERVICE_NAME);
   try {
     Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
     return (EntryView) toObject(future.get());
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#15
0
 protected ICompletableFuture<Data> setAsyncInternal(
     Data key, Data value, long ttl, TimeUnit timeunit) {
   int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
   MapOperation operation =
       operationProvider.createSetOperation(name, key, value, getTimeInMillis(ttl, timeunit));
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     return operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#16
0
 @Override
 public Future<V> removeAsync(final K key) {
   final Data keyData = toData(key);
   MapRemoveRequest request = new MapRemoveRequest(name, keyData, ThreadUtil.getThreadId());
   try {
     final ICompletableFuture future =
         getContext().getInvocationService().invokeOnKeyOwner(request, keyData);
     return new DelegatingFuture<V>(future, getContext().getSerializationService());
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
 }
示例#17
0
 protected boolean containsKeyInternal(Data key) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation containsKeyOperation = operationProvider.createContainsKeyOperation(name, key);
   containsKeyOperation.setThreadId(ThreadUtil.getThreadId());
   containsKeyOperation.setServiceName(SERVICE_NAME);
   try {
     Future future =
         operationService.invokeOnPartition(SERVICE_NAME, containsKeyOperation, partitionId);
     return (Boolean) toObject(future.get());
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#18
0
 @Override
 public boolean tryLock(K key, long time, TimeUnit timeunit) throws InterruptedException {
   final Data keyData = toData(key);
   MapLockRequest request =
       new MapLockRequest(
           name,
           keyData,
           ThreadUtil.getThreadId(),
           Long.MAX_VALUE,
           getTimeInMillis(time, timeunit));
   Boolean result = invoke(request, keyData);
   return result;
 }
  public boolean put(K key, V value) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
    checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED);

    Data keyData = toData(key);
    Data valueData = toData(value);
    ClientMessage request =
        MultiMapPutCodec.encodeRequest(name, keyData, valueData, ThreadUtil.getThreadId());
    ClientMessage response = invoke(request, keyData);
    MultiMapPutCodec.ResponseParameters resultParameters =
        MultiMapPutCodec.decodeResponse(response);
    return resultParameters.response;
  }
示例#20
0
 public Data executeOnKeyInternal(Data key, EntryProcessor entryProcessor) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor);
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     Future future =
         operationService
             .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
             .setResultDeserialized(false)
             .invoke();
     return (Data) future.get();
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#21
0
 @Override
 public Future<V> putAsync(final K key, final V value, final long ttl, final TimeUnit timeunit) {
   final Data keyData = toData(key);
   final Data valueData = toData(value);
   MapPutRequest request =
       new MapPutRequest(
           name, keyData, valueData, ThreadUtil.getThreadId(), getTimeInMillis(ttl, timeunit));
   try {
     final ICompletableFuture future =
         getContext().getInvocationService().invokeOnKeyOwner(request, keyData);
     return new DelegatingFuture<V>(future, getContext().getSerializationService());
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
 }
  public Collection<V> get(K key) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);

    Data keyData = toData(key);
    ClientMessage request = MultiMapGetCodec.encodeRequest(name, keyData, ThreadUtil.getThreadId());
    ClientMessage response = invoke(request, keyData);
    MultiMapGetCodec.ResponseParameters resultParameters =
        MultiMapGetCodec.decodeResponse(response);
    Collection<Data> result = resultParameters.list;
    Collection<V> resultCollection = new ArrayList<V>(result.size());
    for (Data data : result) {
      final V value = toObject(data);
      resultCollection.add(value);
    }
    return resultCollection;
  }
  public boolean tryLock(K key, long time, TimeUnit timeunit, long leaseTime, TimeUnit leaseUnit)
      throws InterruptedException {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);

    final Data keyData = toData(key);
    long timeoutInMillis = getTimeInMillis(time, timeunit);
    long leaseTimeInMillis = getTimeInMillis(leaseTime, leaseUnit);

    long threadId = ThreadUtil.getThreadId();
    ClientMessage request =
        MultiMapTryLockCodec.encodeRequest(
            name, keyData, threadId, leaseTimeInMillis, timeoutInMillis);
    ClientMessage response = invoke(request, keyData);
    MultiMapTryLockCodec.ResponseParameters resultParameters =
        MultiMapTryLockCodec.decodeResponse(response);
    return resultParameters.response;
  }
示例#24
0
 public ICompletableFuture executeOnKeyInternal(
     Data key, EntryProcessor entryProcessor, ExecutionCallback<Object> callback) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor);
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     if (callback == null) {
       return operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
     } else {
       return operationService
           .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
           .setExecutionCallback(new MapExecutionCallbackAdapter(callback))
           .invoke();
     }
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
示例#25
0
  protected ICompletableFuture<Data> removeAsyncInternal(Data key) {
    int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
    MapOperation operation = operationProvider.createRemoveOperation(name, key, false);
    operation.setThreadId(ThreadUtil.getThreadId());
    try {
      long startTime = System.currentTimeMillis();
      InternalCompletableFuture<Data> future =
          operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);

      if (statisticsEnabled) {
        future.andThen(new IncrementStatsExecutionCallback<Data>(operation, startTime));
      }

      return future;
    } catch (Throwable t) {
      throw rethrow(t);
    }
  }
 protected int valueCountInternal(Data key) {
   throwExceptionIfNull(key);
   Collection<MultiMapRecord> coll = txMap.get(key);
   if (coll == null) {
     CountOperation operation = new CountOperation(name, key);
     operation.setThreadId(ThreadUtil.getThreadId());
     try {
       int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
       final OperationService operationService = getNodeEngine().getOperationService();
       Future<Integer> f =
           operationService.invokeOnPartition(
               MultiMapService.SERVICE_NAME, operation, partitionId);
       return f.get();
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   }
   return coll.size();
 }
 protected Collection<MultiMapRecord> getInternal(Data key) {
   throwExceptionIfNull(key);
   Collection<MultiMapRecord> coll = txMap.get(key);
   if (coll == null) {
     GetAllOperation operation = new GetAllOperation(name, key);
     operation.setThreadId(ThreadUtil.getThreadId());
     try {
       int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
       final OperationService operationService = getNodeEngine().getOperationService();
       Future<MultiMapResponse> f =
           operationService.invokeOnPartition(
               MultiMapService.SERVICE_NAME, operation, partitionId);
       MultiMapResponse response = f.get();
       coll = response.getRecordCollection(getNodeEngine());
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   }
   return coll;
 }
示例#28
0
 public void lock(long leaseTime, TimeUnit timeUnit) {
   LockRequest request =
       new LockRequest(
           getKeyData(), ThreadUtil.getThreadId(), getTimeInMillis(leaseTime, timeUnit), -1);
   invoke(request);
 }
 private int getThreadId() {
   return ThreadUtil.getThreadId();
 }
示例#30
0
 public void forceUnlock() {
   UnlockRequest request = new UnlockRequest(getKeyData(), ThreadUtil.getThreadId(), true);
   invoke(request);
 }