Search in sources :

Example 1 with AwaitOperation

use of com.hazelcast.concurrent.lock.operations.AwaitOperation in project hazelcast by hazelcast.

the class ConditionAwaitMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    final Data key = serializationService.toData(parameters.lockName);
    final InternalLockNamespace namespace = new InternalLockNamespace(parameters.lockName);
    return new AwaitOperation(namespace, key, parameters.threadId, parameters.timeout, parameters.name, parameters.referenceId);
}
Also used : InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation) Data(com.hazelcast.nio.serialization.Data)

Example 2 with AwaitOperation

use of com.hazelcast.concurrent.lock.operations.AwaitOperation in project hazelcast by hazelcast.

the class LockResourceImpl method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    key = in.readData();
    owner = in.readUTF();
    threadId = in.readLong();
    referenceId = in.readLong();
    lockCount = in.readInt();
    expirationTime = in.readLong();
    acquireTime = in.readLong();
    transactional = in.readBoolean();
    blockReads = in.readBoolean();
    int len = in.readInt();
    if (len > 0) {
        waiters = new HashMap<String, WaitersInfo>(len);
        for (int i = 0; i < len; i++) {
            WaitersInfo condition = new WaitersInfo();
            condition.readData(in);
            waiters.put(condition.getConditionId(), condition);
        }
    }
    len = in.readInt();
    if (len > 0) {
        conditionKeys = new HashSet<ConditionKey>(len);
        for (int i = 0; i < len; i++) {
            conditionKeys.add(new ConditionKey(in.readUTF(), key, in.readUTF(), in.readUTF(), in.readLong()));
        }
    }
    len = in.readInt();
    if (len > 0) {
        expiredAwaitOps = new ArrayList<AwaitOperation>(len);
        for (int i = 0; i < len; i++) {
            AwaitOperation op = new AwaitOperation();
            op.readData(in);
            expiredAwaitOps.add(op);
        }
    }
}
Also used : AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation)

Example 3 with AwaitOperation

use of com.hazelcast.concurrent.lock.operations.AwaitOperation in project hazelcast by hazelcast.

the class LockResourceImpl method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeData(key);
    out.writeUTF(owner);
    out.writeLong(threadId);
    out.writeLong(referenceId);
    out.writeInt(lockCount);
    out.writeLong(expirationTime);
    out.writeLong(acquireTime);
    out.writeBoolean(transactional);
    out.writeBoolean(blockReads);
    int conditionCount = getConditionCount();
    out.writeInt(conditionCount);
    if (conditionCount > 0) {
        for (WaitersInfo condition : waiters.values()) {
            condition.writeData(out);
        }
    }
    int signalCount = getSignalCount();
    out.writeInt(signalCount);
    if (signalCount > 0) {
        for (ConditionKey signalKey : conditionKeys) {
            out.writeUTF(signalKey.getObjectName());
            out.writeUTF(signalKey.getConditionId());
            out.writeUTF(signalKey.getUuid());
            out.writeLong(signalKey.getThreadId());
        }
    }
    int expiredAwaitOpsCount = getExpiredAwaitsOpsCount();
    out.writeInt(expiredAwaitOpsCount);
    if (expiredAwaitOpsCount > 0) {
        for (AwaitOperation op : expiredAwaitOps) {
            op.writeData(out);
        }
    }
}
Also used : AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation)

Example 4 with AwaitOperation

use of com.hazelcast.concurrent.lock.operations.AwaitOperation in project hazelcast by hazelcast.

the class LockResourceImpl method pollExpiredAwaitOp.

AwaitOperation pollExpiredAwaitOp() {
    List<AwaitOperation> ops = expiredAwaitOps;
    if (isNullOrEmpty(ops)) {
        return null;
    }
    Iterator<AwaitOperation> iterator = ops.iterator();
    AwaitOperation awaitResponse = iterator.next();
    iterator.remove();
    return awaitResponse;
}
Also used : AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation)

Example 5 with AwaitOperation

use of com.hazelcast.concurrent.lock.operations.AwaitOperation in project hazelcast by hazelcast.

the class ConditionImpl method doAwait.

private boolean doAwait(long time, TimeUnit unit, long threadId) throws InterruptedException {
    try {
        long timeout = unit.toMillis(time);
        Data key = lockProxy.getKeyData();
        AwaitOperation op = new AwaitOperation(namespace, key, threadId, timeout, conditionId);
        Future f = invoke(op);
        return Boolean.TRUE.equals(f.get());
    } catch (Throwable t) {
        throw rethrowAllowInterrupted(t);
    }
}
Also used : AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation) BeforeAwaitOperation(com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data)

Aggregations

AwaitOperation (com.hazelcast.concurrent.lock.operations.AwaitOperation)5 Data (com.hazelcast.nio.serialization.Data)2 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)1 BeforeAwaitOperation (com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 Future (java.util.concurrent.Future)1