aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/main/MusicCore.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/main/MusicCore.java')
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java81
1 files changed, 62 insertions, 19 deletions
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index f085be05..b16d6d68 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -24,6 +24,7 @@ package org.onap.music.main;
import java.io.StringWriter;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -169,12 +170,14 @@ public class MusicCore {
}
- public static ReturnType acquireLockWithLease(String fullyQualifiedKey, String lockReference, long leasePeriod) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ public static ReturnType acquireLockWithLease(String fullyQualifiedKey, String lockReference, long leasePeriod)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
evictExpiredLockHolder(fullyQualifiedKey,leasePeriod);
return acquireLock(fullyQualifiedKey, lockReference);
}
- private static void evictExpiredLockHolder(String fullyQualifiedKey, long leasePeriod) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ private static void evictExpiredLockHolder(String fullyQualifiedKey, long leasePeriod)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
String[] splitString = fullyQualifiedKey.split("\\.");
String keyspace = splitString[0];
@@ -193,7 +196,9 @@ public class MusicCore {
}
}
- private static ReturnType isTopOfLockStore(String keyspace, String table, String primaryKeyValue, String lockReference) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ private static ReturnType isTopOfLockStore(String keyspace, String table,
+ String primaryKeyValue, String lockReference)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
//return failure to lock holders too early or already evicted from the lock store
String topOfLockStoreS = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue).lockRef;
@@ -214,7 +219,8 @@ public class MusicCore {
return new ReturnType(ResultType.SUCCESS, lockReference+" is top of lock store");
}
- public static ReturnType acquireLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ public static ReturnType acquireLock(String fullyQualifiedKey, String lockReference)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
String[] splitString = fullyQualifiedKey.split("\\.");
String keyspace = splitString[0];
String table = splitString[1];
@@ -252,7 +258,43 @@ public class MusicCore {
return new ReturnType(ResultType.SUCCESS, lockReference+" is the lock holder for the key");
}
+ /**
+ * Get the list of locks waiting in queue
+ * @param fullyQualifiedKey
+ * @return list of strings that are in the lock queue
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ * @throws MusicLockingException
+ */
+ public static List<String> getLockQueue(String fullyQualifiedKey)
+ throws MusicServiceException, MusicQueryException, MusicLockingException {
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
+
+ return getLockingServiceHandle().getLockQueue(keyspace, table, primaryKeyValue);
+ }
+
+ /**
+ * Get the list of locks waiting in queue
+ * @param fullyQualifiedKey
+ * @return list of strings that are in the lock queue
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ * @throws MusicLockingException
+ */
+ public static long getLockQueueSize(String fullyQualifiedKey)
+ throws MusicServiceException, MusicQueryException, MusicLockingException {
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
+ return getLockingServiceHandle().getLockQueueSize(keyspace, table, primaryKeyValue);
+ }
+
+
/**
*
@@ -263,7 +305,8 @@ public class MusicCore {
*
*
*/
- public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject, String consistency) throws MusicServiceException {
+ public static ResultType createTable(String keyspace, String table,
+ PreparedQueryObject tableQueryObject, String consistency) throws MusicServiceException {
boolean result = false;
try {
@@ -371,7 +414,8 @@ public class MusicCore {
* @return
* @throws MusicServiceException
*/
- public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
+ public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results)
+ throws MusicServiceException {
return getDSHandle().marshalData(results);
}
@@ -419,11 +463,13 @@ public class MusicCore {
return getMusicLockState(fullyQualifiedKey);
}
- public static MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException{
+ public static MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference)
+ throws MusicLockingException{
return destroyLockRef(fullyQualifiedKey, lockReference);
}
- public static MusicLockState forciblyReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicServiceException, MusicQueryException{
+ public static MusicLockState forciblyReleaseLock(String fullyQualifiedKey, String lockReference)
+ throws MusicLockingException, MusicServiceException, MusicQueryException{
String[] splitString = fullyQualifiedKey.split("\\.");
String keyspace = splitString[0];
String table = splitString[1];
@@ -459,7 +505,8 @@ public class MusicCore {
* @return
* @throws MusicServiceException
*/
- public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
+ public static TableMetadata returnColumnMetadata(String keyspace, String tablename)
+ throws MusicServiceException {
return getDSHandle().returnColumnMetadata(keyspace, tablename);
}
@@ -542,7 +589,8 @@ public class MusicCore {
*
*
*/
- public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
+ public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
+ throws MusicServiceException {
// this is mainly for some functions like keyspace creation etc which does not
// really need the bells and whistles of Music locking.
boolean result = false;
@@ -613,7 +661,8 @@ public class MusicCore {
* @throws MusicQueryException
*/
public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ PreparedQueryObject queryObject, Condition conditionInfo)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
long start = System.currentTimeMillis();
String fullyQualifiedKey = keyspaceName + "." + tableName + "." + primaryKey;
@@ -659,7 +708,8 @@ public class MusicCore {
* @throws MusicQueryException
*/
public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
+ PreparedQueryObject queryObject)
+ throws MusicServiceException, MusicLockingException, MusicQueryException {
String fullyQualifiedKey = keyspaceName + "." + tableName + "." + primaryKey;
String lockReference = createLockReference(fullyQualifiedKey);
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
@@ -790,11 +840,4 @@ public class MusicCore {
resultMap.put("keyspace",keyspace);
return resultMap;
}
-
-
-// public static void main(String[] args) {
-// String x = "axe top";
-// x = x.replaceFirst("top", "sword");
-// System.out.print(x); //returns sword pickaxe
-// }
}