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);
}
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);
}
}
}
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);
}
}
}
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;
}
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);
}
}
Aggregations