Skip to content

Commit

Permalink
Move RuntimeException into getSession
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed Jul 31, 2015
1 parent 3a1fd53 commit dea23ea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public CassAlertsServiceImpl() {
@PostConstruct
public void initServices() {
try {
if (session == null) {
session = CassCluster.getSession();
}
session = CassCluster.getSession();
} catch (Throwable t) {
if (log.isDebugEnabled()) {
t.printStackTrace();
Expand All @@ -112,9 +110,6 @@ public void addAlerts(Collection<Alert> alerts) throws Exception {
throw new IllegalArgumentException("Alerts must be not null");
}
session = CassCluster.getSession();
if (session == null) {
throw new RuntimeException("Cassandra session is null");
}
PreparedStatement insertAlert = CassStatement.get(session, CassStatement.INSERT_ALERT);
PreparedStatement insertAlertTrigger = CassStatement.get(session, CassStatement.INSERT_ALERT_TRIGGER);
PreparedStatement insertAlertCtime = CassStatement.get(session, CassStatement.INSERT_ALERT_CTIME);
Expand Down Expand Up @@ -157,9 +152,6 @@ public Alert getAlert(String tenantId, String alertId, boolean thin) throws Exce
throw new IllegalArgumentException("AlertId must be not null");
}
session = CassCluster.getSession();
if (session == null) {
throw new RuntimeException("Cassandra session is null");
}
PreparedStatement selectAlert = CassStatement.get(session, CassStatement.SELECT_ALERT);
if (selectAlert == null) {
throw new RuntimeException("selectAlert PreparedStatement is null");
Expand Down Expand Up @@ -195,9 +187,6 @@ public Page<Alert> getAlerts(String tenantId, AlertsCriteria criteria, Pager pag
throw new IllegalArgumentException("TenantId must be not null");
}
session = CassCluster.getSession();
if (session == null) {
throw new RuntimeException("Cassandra session is null");
}
boolean filter = (null != criteria && criteria.hasCriteria());
boolean thin = (null != criteria && criteria.isThin());

Expand Down Expand Up @@ -731,9 +720,6 @@ private Alert updateAlertStatus(Alert alert) throws Exception {
throw new IllegalArgumentException("AlertId must be not null");
}
session = CassCluster.getSession();
if (session == null) {
throw new RuntimeException("Cassandra session is null");
}
try {
/*
Not sure if these queries can be wrapped in an async way as they have dependencies with results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class CassCluster {

private static Session session = null;

private static boolean initialized = false;

private static CassCluster instance = new CassCluster();

private CassCluster() { }
Expand Down Expand Up @@ -82,6 +84,7 @@ private void initScheme(Session session, String keyspace) throws IOException {
}
}
}
initialized = true;
}

private String substituteVars(String cql, Map<String, String> vars) {
Expand Down Expand Up @@ -133,11 +136,14 @@ public static Session getSession() throws Exception {
}
}
}
if (session != null) {
if (session != null && !initialized) {
String keyspace = AlertProperties.getProperty(ALERTS_CASSANDRA_KEYSPACE, "hawkular_alerts");
instance.initScheme(session, keyspace);
}
}
if (session == null) {
throw new RuntimeException("Cassandra session is null");
}
return session;
}

Expand Down

0 comments on commit dea23ea

Please sign in to comment.