+ roleChangeGuard.acquire();
+ } catch (final InterruptedException e) {
+ LOG.warn("Unexpected exception in check TxEntityOwnershipCandidateRegistration process for txEntity {}", txEntity);
+ } finally {
+ result = txEntityOwnershipCandidateRegistration != null;
+ roleChangeGuard.release();
+ }
+ return result;
+ }
+
+ @VisibleForTesting
+ ListenableFuture<Void> onRoleChanged(final OfpRole oldRole, final OfpRole newRole) {
+ LOG.trace("onRoleChanged method call for Entity {}", entity);
+
+ if (!isDeviceConnected()) {
+ // this can happen as after the disconnect, we still get a last message from EntityOwnershipService.
+ LOG.debug("Device {} is disconnected from this node. Hence not attempting a role change.", deviceContext
+ .getPrimaryConnectionContext().getNodeId());
+ // we don't need to do anything
+ return Futures.immediateFuture(null);
+ }
+
+ final AsyncFunction<RpcResult<SetRoleOutput>, Void> roleChangeFunction = new AsyncFunction<RpcResult<SetRoleOutput>, Void>() {
+ @Override
+ public ListenableFuture<Void> apply(final RpcResult<SetRoleOutput> setRoleOutputRpcResult) throws Exception {
+ LOG.debug("Role change {} successful made on switch :{}", newRole, deviceContext.getDeviceState().getNodeId());
+ getDeviceState().setRole(newRole);
+ return deviceContext.onClusterRoleChange(oldRole, newRole);
+ }
+ };
+ return sendRoleChangeToDevice(newRole, roleChangeFunction);
+ }
+
+ @GuardedBy("roleChangeGuard")
+ private void setupTxCandidate() throws Exception {
+ LOG.debug("setupTxCandidate for entity {} and Transaction entity {}", entity, txEntity);
+ Verify.verify(txEntity != null);
+ Verify.verify(entityOwnershipCandidateRegistration != null);
+ Verify.verify(txEntityOwnershipCandidateRegistration == null);
+ txEntityOwnershipCandidateRegistration = entityOwnershipService.registerCandidate(txEntity);
+ }
+
+ @GuardedBy("roleChangeGuard")
+ private void suspendTxCandidate() {
+ LOG.trace("Suspend TxCandidate for Node {}", deviceContext.getDeviceState().getNodeId());
+ if (null != txEntityOwnershipCandidateRegistration) {
+ LOG.debug("Closing TxEntityOwnershipCandidateRegistration for {}", txEntity);
+ txEntityOwnershipCandidateRegistration.close();
+ txEntityOwnershipCandidateRegistration = null;
+ }
+ }
+
+ @Override
+ public void close() {
+ LOG.trace("Close RoleCtx for Node {}", deviceContext.getDeviceState().getNodeId());
+ if (null != entityOwnershipCandidateRegistration) {
+ LOG.info("Close Node Entity {} registration", entity);
+ entityOwnershipCandidateRegistration.close();
+ entityOwnershipCandidateRegistration = null;
+ }
+ if (null != txEntityOwnershipCandidateRegistration) {
+ LOG.info("Close Tx Entity {} registration", txEntity);
+ txEntityOwnershipCandidateRegistration.close();
+ txEntityOwnershipCandidateRegistration = null;