@Get("json")
public Map<String, Object> retrieve() {
String counterTitle =
(String) getRequestAttributes().get("counterTitle");
Map<String, Object> model = new HashMap<String,Object>();
CounterValue v;
if (counterTitle.equalsIgnoreCase("all")) {
Map<String, ICounter> counters = this.counterStore.getAll();
if (counters != null) {
Iterator<Map.Entry<String, ICounter>> it =
counters.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ICounter> entry = it.next();
String counterName = entry.getKey();
v = entry.getValue().getCounterValue();
if (CounterValue.CounterType.LONG == v.getType()) {
model.put(counterName, v.getLong());
} else if (v.getType() == CounterValue.CounterType.DOUBLE) {
model.put(counterName, v.getDouble());
}
}
}
} else {
ICounter counter = this.counterStore.getCounter(counterTitle);
if (counter != null) {
v = counter.getCounterValue();
} else {
v = new CounterValue(CounterValue.CounterType.LONG);
}
if (CounterValue.CounterType.LONG == v.getType()) {
model.put(counterTitle, v.getLong());
} else if (v.getType() == CounterValue.CounterType.DOUBLE) {
model.put(counterTitle, v.getDouble());
}
}
return model;
}