aboutsummaryrefslogtreecommitdiffstats
path: root/context/context-management/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'context/context-management/src/main')
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java2
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java24
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java28
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java24
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/AbstractLockManager.java48
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java2
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java27
7 files changed, 88 insertions, 67 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
index 30af48195..44ec06c6d 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
@@ -38,7 +38,7 @@ public interface SchemaHelper {
* @param schema the schema
* @throws ContextRuntimeException the context runtime exception
*/
- void init(AxKey userKey, AxContextSchema schema) throws ContextRuntimeException;
+ void init(AxKey userKey, AxContextSchema schema);
/**
* Get the user key of the schema helper.
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
index 0f991ba36..6382992d9 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
@@ -51,6 +51,10 @@ public final class ContextAlbumImpl implements ContextAlbum {
// Logger for this class
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextAlbumImpl.class);
+ // Recurring string constants
+ private static final String NULL_VALUES_ILLEGAL = "null values are illegal on method parameter \"key\"";
+ private static final String ALBUM = "album \"";
+
// The definition of this context album
private final AxContextAlbum albumDefinition;
@@ -259,8 +263,8 @@ public final class ContextAlbumImpl implements ContextAlbum {
@Override
public boolean containsKey(final Object key) {
if (key == null) {
- LOGGER.warn("null values are illegal on method parameter \"key\"");
- throw new ContextRuntimeException("null values are illegal on method parameter \"key\"");
+ LOGGER.warn(NULL_VALUES_ILLEGAL);
+ throw new ContextRuntimeException(NULL_VALUES_ILLEGAL);
}
return albumMap.containsKey(key);
@@ -290,7 +294,7 @@ public final class ContextAlbumImpl implements ContextAlbum {
public Object get(final Object key) {
if (key == null) {
final String returnString =
- "album \"" + albumDefinition.getId() + "\" null keys are illegal on keys for get()";
+ ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for get()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
@@ -365,20 +369,20 @@ public final class ContextAlbumImpl implements ContextAlbum {
public Object put(final String key, final Object incomingValue) {
if (key == null) {
final String returnString =
- "album \"" + albumDefinition.getId() + "\" null keys are illegal on keys for put()";
+ ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for put()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (incomingValue == null) {
- final String returnString = "album \"" + albumDefinition.getId() + "\" null values are illegal on key \""
+ final String returnString = ALBUM + albumDefinition.getId() + "\" null values are illegal on key \""
+ key + "\" for put()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (!albumDefinition.isWritable()) {
- final String returnString = "album \"" + albumDefinition.getId()
+ final String returnString = ALBUM + albumDefinition.getId()
+ "\" put() not allowed on read only albums for key=\"" + key + "\", value=\"" + incomingValue;
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -418,7 +422,7 @@ public final class ContextAlbumImpl implements ContextAlbum {
public void putAll(final Map<? extends String, ? extends Object> incomingContextAlbum) {
if (!albumDefinition.isWritable()) {
final String returnString =
- "album \"" + albumDefinition.getId() + "\" putAll() not allowed on read only albums";
+ ALBUM + albumDefinition.getId() + "\" putAll() not allowed on read only albums";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
@@ -454,14 +458,14 @@ public final class ContextAlbumImpl implements ContextAlbum {
@Override
public Object remove(final Object key) {
if (!albumDefinition.isWritable()) {
- final String returnString = "album \"" + albumDefinition.getId()
+ final String returnString = ALBUM + albumDefinition.getId()
+ "\" remove() not allowed on read only albums for key=\"" + key + "\"";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (key == null) {
- LOGGER.warn("null values are illegal on method parameter \"key\"");
+ LOGGER.warn(NULL_VALUES_ILLEGAL);
throw new ContextRuntimeException("null values are illegal on method parameter \"keyID\"");
}
@@ -483,7 +487,7 @@ public final class ContextAlbumImpl implements ContextAlbum {
public void clear() {
if (!albumDefinition.isWritable()) {
final String returnString =
- "album \"" + albumDefinition.getId() + "\" clear() not allowed on read only albums";
+ ALBUM + albumDefinition.getId() + "\" clear() not allowed on read only albums";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
index e40646d56..042b2c22a 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
@@ -94,12 +94,12 @@ public abstract class AbstractDistributor implements Distributor {
// Create the lock manager if it doesn't already exist
if (lockManager == null) {
- lockManager = new LockManagerFactory().createLockManager(key);
+ setLockManager(new LockManagerFactory().createLockManager(key));
}
// Set up flushing on the context distributor if its not set up already
if (flushTimer == null) {
- flushTimer = new DistributorFlushTimerTask(this);
+ setFlushTimer(new DistributorFlushTimerTask(this));
}
// Create a new persistor for this key
@@ -107,6 +107,22 @@ public abstract class AbstractDistributor implements Distributor {
LOGGER.exit("init(" + key + ")");
}
+ /**
+ * Set the static lock manager
+ * @param incomingLockManager the lock manager value
+ */
+ private static void setLockManager(final LockManager incomingLockManager) {
+ lockManager = incomingLockManager;
+ }
+
+ /**
+ * Set the static flush timer
+ * @param incomingFlushTimer the flush timer value
+ */
+ private static void setFlushTimer(final DistributorFlushTimerTask incomingFlushTimer) {
+ flushTimer = incomingFlushTimer;
+ }
+
/*
* (non-Javadoc)
*
@@ -191,8 +207,7 @@ public abstract class AbstractDistributor implements Distributor {
// another process,
// if not, we have to try to read the content from persistence
if (newContextAlbumMap.isEmpty()) {
- // Read entries from persistence
- // TODO: READ ITEMS FROM PRESISTENCE!!!!
+ // Read entries from persistence, (Not implemented yet)
}
// Create the context album and put the context album object onto the distributor
@@ -232,8 +247,7 @@ public abstract class AbstractDistributor implements Distributor {
for (final Entry<AxArtifactKey, ContextAlbum> distributorMapEntry : albumMaps.entrySet()) {
// Let the persistor write each of the entries
for (final Object contextItem : distributorMapEntry.getValue().values()) {
- LOGGER.debug(contextItem.toString());
- // persistor.writeContextItem((AxContextSchema) contextItem);
+ persistor.writeContextItem((AxContextSchema) contextItem);
}
}
}
@@ -312,7 +326,7 @@ public abstract class AbstractDistributor implements Distributor {
// Shut down the lock manager
if (lockManager != null) {
lockManager.shutdown();
- lockManager = null;
+ setLockManager(null);
}
albumMaps.clear();
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java
index 2c3661822..0dd1d9966 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java
@@ -46,7 +46,7 @@ public class DistributorFlushTimerTask extends TimerTask {
private final Distributor contextDistributor;
// Timing information
- private long period = 0;
+ private long flushPeriod = 0;
private long flushCount = 0;
/**
@@ -62,14 +62,14 @@ public class DistributorFlushTimerTask extends TimerTask {
// Set the period for persistence flushing
final PersistorParameters persistorParameters = ParameterService
.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
- period = persistorParameters.getFlushPeriod();
+ flushPeriod = persistorParameters.getFlushPeriod();
// Set up the timer
timer = new Timer(DistributorFlushTimerTask.class.getSimpleName(), true);
- timer.schedule(this, period, period);
+ timer.schedule(this, flushPeriod, flushPeriod);
- LOGGER.debug("context distributor " + contextDistributor.getKey().getId() + " flushing set up with interval: "
- + period + "ms");
+ LOGGER.debug("context distributor {} flushing set up with interval: {} ms", contextDistributor.getKey().getId(),
+ flushPeriod);
}
/**
@@ -80,15 +80,15 @@ public class DistributorFlushTimerTask extends TimerTask {
// Increment the flush counter
flushCount++;
- LOGGER.debug("context distributor " + contextDistributor.getKey().getId() + " flushing: period=" + period
- + ": count=" + flushCount);
+ LOGGER.debug("context distributor {} flushing: period={}: count={}", contextDistributor.getKey().getId(),
+ flushPeriod, flushCount);
try {
contextDistributor.flush();
- LOGGER.debug("context distributor " + contextDistributor.getKey().getId() + " flushed: period=" + period
- + ": count=" + flushCount);
+ LOGGER.debug("context distributor {} flushed: period={}: count={}", contextDistributor.getKey().getId(),
+ flushPeriod, flushCount);
} catch (final ContextException e) {
- LOGGER.error("flush error on context distributor " + contextDistributor.getKey().getId() + ": period="
- + period + ": count=" + flushCount, e);
+ LOGGER.error("flush error on context distributor {}: period={}: count={}",
+ contextDistributor.getKey().getId(), flushPeriod, flushCount, e);
}
}
@@ -113,6 +113,6 @@ public class DistributorFlushTimerTask extends TimerTask {
*/
@Override
public String toString() {
- return "ContextDistributorFlushTimerTask [period=" + period + ", flushCount=" + flushCount + "]";
+ return "ContextDistributorFlushTimerTask [period=" + flushPeriod + ", flushCount=" + flushCount + "]";
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/AbstractLockManager.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/AbstractLockManager.java
index 4f197e2d3..88908b965 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/AbstractLockManager.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/AbstractLockManager.java
@@ -41,12 +41,15 @@ public abstract class AbstractLockManager implements LockManager {
// Logger for this class
private static final XLogger LOGGER = XLoggerFactory.getXLogger(AbstractLockManager.class);
+ // Recurring string constants
+ private static final String CONTEXT_ITEM = " context item ";
+
// The key of this lock manager
private AxArtifactKey key = null;
// Map of locks in use on this distributor for each context map
- private final Map<String, Map<String, ReadWriteLock>> lockMaps =
- Collections.synchronizedMap(new HashMap<String, Map<String, ReadWriteLock>>());
+ private final Map<String, Map<String, ReadWriteLock>> lockMaps = Collections
+ .synchronizedMap(new HashMap<String, Map<String, ReadWriteLock>>());
/*
* (non-Javadoc)
@@ -85,9 +88,9 @@ public abstract class AbstractLockManager implements LockManager {
lock.readLock().lock();
LOGGER.exit("lockForReading(" + lockTypeKey + "_" + lockKey + ")");
} catch (final Exception e) {
- LOGGER.warn("error acquiring read lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ LOGGER.warn("error acquiring read lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
throw new ContextException(
- "error acquiring read lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ "error acquiring read lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
}
}
@@ -107,9 +110,9 @@ public abstract class AbstractLockManager implements LockManager {
lock.writeLock().lock();
LOGGER.exit("lockForWriting(" + lockTypeKey + "_" + lockKey + ")");
} catch (final Exception e) {
- LOGGER.warn("error acquiring write lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ LOGGER.warn("error acquiring write lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
throw new ContextException(
- "error acquiring write lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ "error acquiring write lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
}
}
@@ -129,9 +132,9 @@ public abstract class AbstractLockManager implements LockManager {
lock.readLock().unlock();
LOGGER.exit("unlockForReading(" + lockTypeKey + "_" + lockKey + ")");
} catch (final Exception e) {
- LOGGER.warn("error releasing read lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ LOGGER.warn("error releasing read lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
throw new ContextException(
- "error releasing read lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ "error releasing read lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
}
}
@@ -151,20 +154,12 @@ public abstract class AbstractLockManager implements LockManager {
lock.writeLock().unlock();
LOGGER.exit("unlockForWriting(" + lockTypeKey + "_" + lockKey + ")");
} catch (final Exception e) {
- LOGGER.warn("error releasing write lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ LOGGER.warn("error releasing write lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
throw new ContextException(
- "error releasing write lock on context map " + lockTypeKey + " context item " + lockKey, e);
+ "error releasing write lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey, e);
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.onap.policy.apex.core.context.LockManager#shutdown()
- */
- @Override
- public abstract void shutdown();
-
/**
* Get a reentrant read write lock from whatever locking mechanism is in use.
*
@@ -184,7 +179,7 @@ public abstract class AbstractLockManager implements LockManager {
* @throws ContextException On errors getting the lock
*/
private ReadWriteLock getLock(final String lockTypeKey, final String lockKey, final boolean createMode)
- throws ContextException {
+ throws ContextException {
// Check if we have a lock type map for this lock type yet
if (!lockMaps.containsKey(lockTypeKey)) {
// Create a lock type map for the lock type
@@ -198,11 +193,11 @@ public abstract class AbstractLockManager implements LockManager {
}
// Should we create a lock?
+ String errorMessage = "error getting lock on context map " + lockTypeKey + CONTEXT_ITEM + lockKey;
if (!createMode) {
- LOGGER.warn("error getting lock on context map " + lockTypeKey + " context item " + lockKey
- + ", lock does not exist");
- throw new ContextException("error getting lock on context map " + lockTypeKey + " context item " + lockKey
- + ", lock does not exist");
+ String message = errorMessage + ", lock does not exist";
+ LOGGER.warn(message);
+ throw new ContextException(message);
}
try {
@@ -213,13 +208,12 @@ public abstract class AbstractLockManager implements LockManager {
lockMaps.get(lockTypeKey).put(lockKey, lock);
if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("created lock " + lockTypeKey + "_" + lockKey);
+ LOGGER.trace("created lock {}_{}", lockTypeKey, lockKey);
}
return lock;
} catch (final Exception e) {
- LOGGER.warn("error getting lock on context map " + lockTypeKey + " context item " + lockKey, e);
- throw new ContextException("error getting lock on context map " + lockTypeKey + " context item " + lockKey,
- e);
+ LOGGER.warn(errorMessage, e);
+ throw new ContextException(errorMessage, e);
}
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
index bb22827cd..f50eb5914 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
@@ -66,7 +66,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
* org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema)
*/
@Override
- public void init(final AxKey incomingUserKey, final AxContextSchema incomingSchema) throws ContextRuntimeException {
+ public void init(final AxKey incomingUserKey, final AxContextSchema incomingSchema) {
Assertions.argumentOfClassNotNull(incomingUserKey, ContextRuntimeException.class,
"incomingUserKey may not be null");
Assertions.argumentOfClassNotNull(incomingSchema, ContextRuntimeException.class,
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java b/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
index e3b335697..c37323759 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
@@ -46,7 +46,8 @@ public class ContextMonitor {
*/
public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value) {
- LOGGER.trace(monitor("INIT", null, albumKey, schemaKey, name, value));
+ String monitorInitString = monitor("INIT", null, albumKey, schemaKey, name, value);
+ LOGGER.trace(monitorInitString);
}
/**
@@ -60,7 +61,8 @@ public class ContextMonitor {
*/
public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("INIT", userArtifactStack, albumKey, schemaKey, name, value));
+ String monitorInitString = monitor("INIT", userArtifactStack, albumKey, schemaKey, name, value);
+ LOGGER.trace(monitorInitString);
}
/**
@@ -74,7 +76,8 @@ public class ContextMonitor {
*/
public void monitorDelete(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("DEL", userArtifactStack, albumKey, schemaKey, name, value));
+ String monitorDeleteString = monitor("DEL", userArtifactStack, albumKey, schemaKey, name, value);
+ LOGGER.trace(monitorDeleteString);
}
/**
@@ -88,7 +91,8 @@ public class ContextMonitor {
*/
public void monitorGet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("GET", userArtifactStack, albumKey, schemaKey, name, value));
+ String monitorGetString = monitor("GET", userArtifactStack, albumKey, schemaKey, name, value);
+ LOGGER.trace(monitorGetString);
}
/**
@@ -102,7 +106,8 @@ public class ContextMonitor {
*/
public void monitorSet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("SET", userArtifactStack, albumKey, schemaKey, name, value));
+ String monitorSetString = monitor("SET", userArtifactStack, albumKey, schemaKey, name, value);
+ LOGGER.trace(monitorSetString);
}
/**
@@ -115,7 +120,8 @@ public class ContextMonitor {
*/
public void monitorReadLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("READLOCK", userArtifactStack, albumKey, schemaKey, name, null));
+ String monitorReadLockString = monitor("READLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ LOGGER.trace(monitorReadLockString);
}
/**
@@ -128,7 +134,8 @@ public class ContextMonitor {
*/
public void monitorWriteLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("WRITELOCK", userArtifactStack, albumKey, schemaKey, name, null));
+ String writeLockMonitorString = monitor("WRITELOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ LOGGER.trace(writeLockMonitorString);
}
/**
@@ -141,7 +148,8 @@ public class ContextMonitor {
*/
public void monitorReadUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("READUNLOCK", userArtifactStack, albumKey, schemaKey, name, null));
+ String monitorReadUnlockString = monitor("READUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ LOGGER.trace(monitorReadUnlockString);
}
/**
@@ -154,7 +162,8 @@ public class ContextMonitor {
*/
public void monitorWriteUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- LOGGER.trace(monitor("WRITEUNLOCK", userArtifactStack, albumKey, schemaKey, name, null));
+ String monitorWriteUnlockString = monitor("WRITEUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ LOGGER.trace(monitorWriteUnlockString);
}
/**