package org.onap.policy.drools.serverpool;
-import static org.junit.Assert.assertTrue;
import static org.onap.policy.drools.serverpool.ServerPoolProperties.DEFAULT_LOCK_AUDIT_GRACE_PERIOD;
import static org.onap.policy.drools.serverpool.ServerPoolProperties.DEFAULT_LOCK_AUDIT_PERIOD;
import static org.onap.policy.drools.serverpool.ServerPoolProperties.DEFAULT_LOCK_AUDIT_RETRY_DELAY;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
-import lombok.NonNull;
+import lombok.EqualsAndHashCode;
import org.onap.policy.drools.core.DroolsRunnable;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.PolicySession;
* owned by the host containing the entry.
*/
public class TargetLock implements Lock, Serializable {
+ private static final long serialVersionUID = 1L;
+
private static Logger logger = LoggerFactory.getLogger(TargetLock.class);
// Listener class to handle state changes that require restarting the audit
context = new PolicySessionContext(session);
session.setAdjunct(PolicySessionContext.class, context);
} else {
- context = (LockCallback)lcontext;
+ context = (LockCallback) lcontext;
}
} else {
// no context to deliver through -- call back directly to owner
logger.info("Lock response={} (code={})",
response, response.getStatus());
- /**
+ /*
* there are three possible responses:
* 204 No Content - operation was successful
* 202 Accepted - operation is still in progress
});
}
- /********************/
- /* 'Lock' Interface */
- /********************/
+ /* ****************** */
+ /* 'Lock' Interface */
+ /* ****************** */
/**
* This method will free the current lock, or remove it from the waiting
// not implemented yet
}
- /********************/
+ /* ****************** */
/**
* Update the state.
+ ", state=" + state + ")";
}
- /*****************/
- /* Serialization */
- /*****************/
+ /* *************** */
+ /* Serialization */
+ /* *************** */
/**
* This method modifies the behavior of 'TargetLock' deserialization by
/* ============================================================ */
private static class LockFactory implements PolicyResourceLockManager {
- /*****************************************/
- /* 'PolicyResourceLockManager' interface */
- /*****************************************/
+ /* *************************************** */
+ /* 'PolicyResourceLockManager' interface */
+ /* *************************************** */
/**
* {@inheritDoc}
return new TargetLock(resourceId, ownerKey, callback, waitForLock);
}
- /*************************/
- /* 'Startable' interface */
- /*************************/
+ /* *********************** */
+ /* 'Startable' interface */
+ /* *********************** */
/**
* {@inheritDoc}
return true;
}
- /************************/
- /* 'Lockable' interface */
- /************************/
+ /* ********************** */
+ /* 'Lockable' interface */
+ /* ********************** */
/**
* {@inheritDoc}
* This class usually has a one-to-one correspondence with a 'TargetLock'
* instance, unless the 'TargetLock' has been abandoned.
*/
+ @EqualsAndHashCode
private static class Identity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// this is the key associated with the lock
String key;
}
return true;
}
-
- /***************************/
- /* 'Object' class override */
- /***************************/
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object other) {
- if (other instanceof Identity) {
- Identity identity = (Identity)other;
- return uuid.equals(identity.uuid)
- && key.equals(identity.key)
- && ownerKey.equals(identity.ownerKey);
- }
- return false;
- }
}
/* ============================================================ */
* the callback to 'TargetLock.owner' runs within the Drools thread.
*/
private static class PolicySessionContext implements LockCallback, Serializable {
+ private static final long serialVersionUID = 1L;
+
// the 'PolicySession' instance in question
PolicySession policySession;
this.policySession = policySession;
}
- /*********************/
- /* 'Owner' interface */
- /*********************/
+ /* ******************* */
+ /* 'Owner' interface */
+ /* ******************* */
/**
* {@inheritDoc}
// Run 'owner.lockAvailable' within the Drools session
if (policySession != null) {
DroolsRunnable callback = () -> {
- ((TargetLock)lock).owner.lockAvailable(lock);
+ ((TargetLock) lock).owner.lockAvailable(lock);
};
policySession.getKieSession().insert(callback);
}
// Run 'owner.unlockAvailable' within the Drools session
if (policySession != null) {
DroolsRunnable callback = () -> {
- ((TargetLock)lock).owner.lockUnavailable(lock);
+ ((TargetLock) lock).owner.lockUnavailable(lock);
};
policySession.getKieSession().insert(callback);
}
}
- /*****************/
- /* Serialization */
- /*****************/
+ /* *************** */
+ /* Serialization */
+ /* *************** */
/**
* Specializes serialization of 'PolicySessionContext'.
* of the lock implementation.
*/
public static class GlobalLocks implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// this is the lock table, mapping 'key' to 'LockEntry', which indicates
// the current lock holder, and all those waiting
private Map<String, LockEntry> keyToEntry = new HashMap<>();
* any that are waiting.
*/
private static class LockEntry implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// string key identifying the lock
private String key;
* This corresponds to a member of 'LockEntry.waitingList'
*/
private static class Waiting implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// string key identifying the owner
String ownerKey;
* This class is used to restore a 'GlobalLocks' instance from a backup.
*/
static class LockRestore implements Bucket.Restore, Serializable {
+ private static final long serialVersionUID = 1L;
+
GlobalLocks globalLocks;
/**
// here. The alternative is to add some additional information
// to make this mapping quick, at the expense of a slight
// slow down of normal lock operations.
- for (int i = 0 ; i < Bucket.BUCKETCOUNT ; i += 1) {
+ for (int i = 0; i < Bucket.BUCKETCOUNT; i += 1) {
LocalLocks localLocks =
Bucket.getBucket(i).getAdjunctDontCreate(LocalLocks.class);
if (localLocks != null) {
Object decodedData = Util.deserialize(Base64.getDecoder().decode(data));
if (decodedData instanceof HostData) {
// deserialized data
- HostData hostData = (HostData)decodedData;
+ HostData hostData = (HostData) decodedData;
// fetch 'Server' instance associated with the responding server
Server server = Server.getServer(hostData.hostUuid);
* host that is consolidating the information for display.
*/
static class HostData implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// the UUID of the host sending the data
private UUID hostUuid;
serverDataList = new ArrayList<ServerData>();
// go through buckets
- for (int i = 0 ; i < Bucket.BUCKETCOUNT ; i += 1) {
+ for (int i = 0; i < Bucket.BUCKETCOUNT; i += 1) {
Bucket bucket = Bucket.getBucket(i);
// client data
* Information derived from the 'LocalLocks' adjunct to a single bucket.
*/
static class ClientData implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// number of the bucket
private int bucketNumber;
* single 'TargetLock'.
*/
static class ClientDataRecord implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// contains key, ownerKey, uuid
private Identity identity;
* Information derived from the 'GlobalLocks' adjunct to a single bucket.
*/
static class ServerData implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// number of the bucket
private int bucketNumber;
* 'TargetLock' audit.
*/
static class AuditData implements Serializable {
+ private static final long serialVersionUID = 1L;
+
// sending UUID
private UUID hostUuid;
Object decodedData =
Util.deserialize(Base64.getDecoder().decode(encodedData));
if (decodedData instanceof AuditData) {
- return (AuditData)decodedData;
+ return (AuditData) decodedData;
} else {
logger.error(
"TargetLock.AuditData.decode returned instance of class {}",
static TimerTask timerTask = null;
// maps 'Server' to audit data associated with that server
- Map<Server,AuditData> auditMap = new IdentityHashMap<>();
+ Map<Server, AuditData> auditMap = new IdentityHashMap<>();
/**
* Run a single audit cycle.
* remote server.
*/
void build() {
- for (int i = 0 ; i < Bucket.BUCKETCOUNT ; i += 1) {
+ for (int i = 0; i < Bucket.BUCKETCOUNT; i += 1) {
Bucket bucket = Bucket.getBucket(i);
// client data