use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.
the class JdbcEventRepository method computeHitCount.
/**
* {@inheritDoc}
*/
private Map<String, MutableHitCount> computeHitCount(String sqlQuery, String columnName, long from, long to) {
Connection sqlConn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
try {
// Returns features
sqlConn = dataSource.getConnection();
ps = sqlConn.prepareStatement(sqlQuery);
ps.setTimestamp(1, new Timestamp(from));
ps.setTimestamp(2, new Timestamp(to));
rs = ps.executeQuery();
while (rs.next()) {
hitCount.put(rs.getString(columnName), new MutableHitCount(rs.getInt("NB")));
}
} catch (SQLException sqlEX) {
throw new FeatureAccessException(CANNOT_BUILD_PIE_CHART_FROM_REPOSITORY, sqlEX);
} finally {
closeResultSet(rs);
closeStatement(ps);
closeConnection(sqlConn);
}
return hitCount;
}
use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.
the class TimeSeriesChart method createNewSerie.
/**
* Create new Serie with existing slots.
*
* @param idSerie
* target serie id
*/
public void createNewSerie(String idSerie) {
// Init new Serie
Serie<Map<String, MutableHitCount>> newSerie = new Serie<Map<String, MutableHitCount>>(idSerie);
// Populate slots
Map<String, MutableHitCount> val = new HashMap<String, MutableHitCount>();
for (String slot : timeSlots) {
val.put(slot, new MutableHitCount());
}
newSerie.setValue(val);
series.put(idSerie, newSerie);
}
use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.
the class EventRepositoryElastic method getSourceHitCount.
@Override
public Map<String, MutableHitCount> getSourceHitCount(EventQueryDefinition query) {
JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
List<Event> events = result.getSourceAsObjectList(Event.class);
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
for (Event event : events) {
String source = event.getSource();
if (hitCount.containsKey(source)) {
hitCount.get(source).inc();
} else {
hitCount.put(source, new MutableHitCount(1));
}
}
return hitCount;
}
use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.
the class EventRepositoryElastic method getHostHitCount.
@Override
public Map<String, MutableHitCount> getHostHitCount(EventQueryDefinition query) {
JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
List<Event> events = result.getSourceAsObjectList(Event.class);
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
for (Event event : events) {
String hostName = event.getHostName();
if (hitCount.containsKey(hostName)) {
hitCount.get(hostName).inc();
} else {
hitCount.put(hostName, new MutableHitCount(1));
}
}
return hitCount;
}
use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.
the class EventRepositoryCassandra method getFeatureUsageHitCount.
/**
* {@inheritDoc}
*/
@Override
public Map<String, MutableHitCount> getFeatureUsageHitCount(EventQueryDefinition query) {
String cqlQuery = getBuilder().cqlFeatureUsageHitCount(query);
LOGGER.debug("Query " + cqlQuery);
ResultSet rs = conn.getSession().execute(cqlQuery);
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
for (Row row : rs.all()) {
String featureName = row.getString(COL_EVENT_NAME);
if (hitCount.containsKey(featureName)) {
hitCount.get(featureName).inc();
} else {
hitCount.put(featureName, new MutableHitCount(1));
}
}
return hitCount;
}
Aggregations