use of dvoraka.avservice.common.data.ReplicationMessage in project av-service by dvoraka.
the class DefaultReplicationService method discoverNeighbours.
private void discoverNeighbours() {
log.debug("Discovering neighbours ({})...", nodeId);
ReplicationMessage message = createDiscoverRequest(nodeId);
serviceClient.sendMessage(message);
Optional<ReplicationMessageList> responses = responseClient.getResponseWait(message.getId(), MAX_RESPONSE_TIME, MAX_RESPONSE_TIME);
if (!responses.isPresent()) {
log.debug("Discovered ({}): none", nodeId);
return;
}
ReplicationMessageList messages = responses.orElseGet(ReplicationMessageList::new);
Set<String> newNeighbours = messages.stream().filter(msg -> msg.getReplicationStatus() == ReplicationStatus.READY).map(ReplicationMessage::getFromId).collect(Collectors.toSet());
neighbours.clear();
neighbours.addAll(newNeighbours);
log.debug("Discovered ({}): {}", nodeId, neighbourCount());
}
use of dvoraka.avservice.common.data.ReplicationMessage in project av-service by dvoraka.
the class DefaultRemoteLock method unlockForFile.
@Override
public boolean unlockForFile(String filename, String owner, int lockCount) {
// send the unlock request
ReplicationMessage unlockRequest = createUnlockRequest(filename, owner, nodeId, getSequence());
serviceClient.sendMessage(unlockRequest);
// get replies
Optional<ReplicationMessageList> unlockReplies = responseClient.getResponseWaitSize(unlockRequest.getId(), MAX_RESPONSE_TIME, lockCount);
// count success unlocks
if (unlockReplies.isPresent()) {
long successUnlocks = unlockReplies.get().stream().filter(message -> message.getReplicationStatus() == ReplicationStatus.OK).count();
if (lockCount == successUnlocks) {
try {
unlockFile(filename, owner);
} catch (FileNotLockedException e) {
log.warn(UNLOCKING_FAILED, e);
}
return true;
} else {
log.warn(UNLOCKING_FAILED);
}
}
return false;
}
use of dvoraka.avservice.common.data.ReplicationMessage in project av-service by dvoraka.
the class AmqpReplicationComponent method onMessage.
@Override
public void onMessage(Message message) {
log.debug("Receive: " + message);
ReplicationMessage replicationMessage;
try {
replicationMessage = (ReplicationMessage) messageConverter.fromMessage(message);
log.debug("Converted ({}): {}", nodeId, replicationMessage);
} catch (MessageConversionException e) {
log.warn("Conversion error!", e);
return;
}
listeners.forEach(listener -> listener.onMessage(replicationMessage));
}
use of dvoraka.avservice.common.data.ReplicationMessage in project av-service by dvoraka.
the class DefaultRemoteLock method initializeSequence.
private void initializeSequence() {
log.debug("Initializing sequence...");
ReplicationMessage request = createSequenceRequest(nodeId);
serviceClient.sendMessage(request);
ReplicationMessageList responses = responseClient.getResponseWait(request.getId(), MAX_RESPONSE_TIME).orElseGet(ReplicationMessageList::new);
long actualSequence = responses.stream().peek(message -> log.debug("Sequence: {}", message)).findFirst().map(ReplicationMessage::getSequence).orElse(1L);
setSequence(actualSequence);
}
use of dvoraka.avservice.common.data.ReplicationMessage in project av-service by dvoraka.
the class DefaultRemoteLock method lockForFile.
@Override
public boolean lockForFile(String filename, String owner, int lockCount) throws InterruptedException {
// lock local file if possible
if (!lockFile(filename, owner)) {
return false;
}
log.debug("Locking {} nodes ({})...", lockCount, nodeId);
lockingLock.lock();
log.debug("Locked.");
ReplicationMessage lockRequest = createLockRequest(filename, owner, nodeId, getSequence());
serviceClient.sendMessage(lockRequest);
Optional<ReplicationMessageList> lockReplies = responseClient.getResponseWaitSize(lockRequest.getId(), MAX_RESPONSE_TIME, lockCount);
// count success locks
if (lockReplies.isPresent()) {
long successLocks = lockReplies.get().stream().filter(message -> message.getReplicationStatus() == ReplicationStatus.READY).count();
if (lockCount == successLocks) {
incSequence();
log.info("Remote locking success.");
lockingLock.unlock();
log.debug("Unlocked.");
return true;
} else {
lockingLock.unlock();
log.debug("Unlocked.");
try {
unlockFile(filename, owner);
} catch (FileNotLockedException e) {
log.warn(UNLOCKING_FAILED, e);
}
return false;
}
}
lockingLock.unlock();
log.debug("Unlocked.");
try {
unlockFile(filename, owner);
} catch (FileNotLockedException e) {
log.warn(UNLOCKING_FAILED, e);
}
return false;
}
Aggregations