aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
diff options
context:
space:
mode:
authorMohammad Salehe <salehe@cs.toronto.edu>2019-02-08 11:58:35 -0500
committerMohammad Salehe <salehe@cs.toronto.edu>2019-02-24 22:23:39 -0500
commitee0e4cef1eaba1691f2a69c94f9707a9dbcfcd63 (patch)
tree0ea14a449dd3e1c7cb9269dfba65bd650c8af23c /src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
parentf6b5b60d066fa47ef520c58305aa6f28827f106b (diff)
Make MusicCore non-staticdev-cassandra-only
Make MusicCore and other dependencies (MusicDataStoreHandle) non-static For compatibility, MusicCore still has a singleton instance that is statically instantiated and can be used as needed by legacy users. These changes should be made in calling sites (legacy users using singleton): MusicDataStoreHandle.getDSHandle() -> MusicCore.getInstanceDSHandle() Change-Id: I02b67f316dc21a1498157bc68cc32bf76d3ec01e Issue-ID: MUSIC-148 Signed-off-by: Mohammad Salehe <salehe@cs.toronto.edu>
Diffstat (limited to 'src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java')
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
index ebd6213f..0b44df3c 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
@@ -24,10 +24,11 @@ package org.onap.music.datastore;
import java.util.HashMap;
import java.util.Map;
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicUtil;
-import org.onap.music.service.impl.MusicCassaCore;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.TableMetadata;
@@ -38,32 +39,11 @@ public class MusicDataStoreHandle {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
/**
- *
- * @param remoteAddress
- * @return
- */
- public static MusicDataStore getDSHandle(String remoteAddress) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
- long start = System.currentTimeMillis();
- if (mDstoreHandle == null) {
- try {
- MusicUtil.loadProperties();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
- }
- mDstoreHandle = new MusicDataStore(remoteAddress);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
- return mDstoreHandle;
- }
-
- /**
*
* @return
* @throws MusicServiceException
*/
- public static MusicDataStore getDSHandle() throws MusicServiceException {
+ private static MusicDataStore getDSHandle() throws MusicServiceException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
long start = System.currentTimeMillis();
@@ -73,12 +53,11 @@ public class MusicDataStoreHandle {
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
}
- // Quick Fix - Best to put this into every call to getDSHandle?
- if (MusicUtil.getMyCassaHost().equals("localhost")) {
- mDstoreHandle = new MusicDataStore();
- } else {
- mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- }
+ // Quick Fix - Best to put this into every call to getInstanceDSHandle?
+ Cluster cluster = CassandraClusterBuilder.connectSmart(MusicUtil.getMyCassaHost());
+ Session session = cluster.connect();
+ mDstoreHandle = new MusicDataStore(cluster, session);
+
}
if(mDstoreHandle.getSession() == null) {
String message = "Connection to Cassandra has not been enstablished."