+ @Override
+ public boolean unregisterCandidate(final Entity entity_) {
+ boolean permit = false;
+ try {
+ permit = roleChangeGuard.tryAcquire(TIMEOUT, TimeUnit.SECONDS);
+ if(permit) {
+ if (entity_.equals(this.entity)) {
+ if (entityOwnershipCandidateRegistration != null) {
+ LOG.debug("Unregister candidate for entity {}", entity_);
+ entityOwnershipCandidateRegistration.close();
+ entityOwnershipCandidateRegistration = null;
+ }
+ } else {
+ if (txEntityOwnershipCandidateRegistration != null) {
+ LOG.debug("Unregister candidate for tx entity {}", entity_);
+ txEntityOwnershipCandidateRegistration.close();
+ txEntityOwnershipCandidateRegistration = null;
+ }
+ }
+ } else {
+ return false;
+ }
+ } catch (final InterruptedException e) {
+ LOG.warn("Cannot acquire semaphore for unregister entity {} candidate.", entity_.getType());
+ return false;
+ } finally {
+ if (permit) {
+ roleChangeGuard.release();
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void close() {
+ unregisterAllCandidates();
+ }
+
+ public boolean isMaster(){
+ return (txEntityOwnershipCandidateRegistration != null && entityOwnershipCandidateRegistration != null);