
ru.taskurotta.service.hz.config.ComputeQueueBalanceTask Maven / Gradle / Ivy
The newest version!
package ru.taskurotta.service.hz.config;
import ru.taskurotta.service.console.retriever.metrics.MetricsMethodDataRetriever;
import ru.taskurotta.service.metrics.model.DataPointVO;
import ru.taskurotta.service.metrics.handler.MetricsDataHandler;
import ru.taskurotta.service.metrics.model.QueueBalanceVO;
import ru.taskurotta.service.metrics.MetricName;
import java.io.Serializable;
import java.util.concurrent.Callable;
/**
* Created with IntelliJ IDEA.
* User: dimadin
* Date: 01.10.13 16:28
*/
public class ComputeQueueBalanceTask implements Callable, Serializable {
private String queueName;
public ComputeQueueBalanceTask(String queueName) {
this.queueName = queueName;
}
@Override
public QueueBalanceVO call() throws Exception {
MetricsMethodDataRetriever metricsDataRetriever = MetricsDataHandler.getInstance();
if (metricsDataRetriever == null) {
return null;
}
DataPointVO[] outHour = metricsDataRetriever.getCountsForLastHour(MetricName.SUCCESSFUL_POLL.getValue(), queueName);
DataPointVO[] outDay = metricsDataRetriever.getCountsForLastDay(MetricName.SUCCESSFUL_POLL.getValue(), queueName);
DataPointVO[] inHour = metricsDataRetriever.getCountsForLastHour(MetricName.ENQUEUE.getValue(), queueName);
DataPointVO[] inDay = metricsDataRetriever.getCountsForLastDay(MetricName.ENQUEUE.getValue(), queueName);
QueueBalanceVO result = new QueueBalanceVO();
result.setTotalInDay(getTotal(inDay));
result.setInDayPeriod(getPeriod(inDay));
result.setTotalInHour(getTotal(inHour));
result.setInHourPeriod(getPeriod(inHour));
result.setTotalOutDay(getTotal(outDay));
result.setOutDayPeriod(getPeriod(outDay));
result.setTotalOutHour(getTotal(outHour));
result.setOutHourPeriod(getPeriod(outHour));
return result;
}
private long[] getPeriod(DataPointVO[] target) {
long[] result = getInitialValue(target);
if (target != null && target.length > 0) {
for (DataPointVO dp: target) {
if (dp!=null && dp.getTime()>0) {
long time = dp.getTime();
if(timeresult[1]) {
result[1] = time;
}
}
}
}
return result;
}
private long[] getInitialValue(DataPointVO [] target) {
long[] result = {-1l, -1l};
if (target != null && target.length > 0) {
for (DataPointVO dp: target) {
if (dp!=null && dp.getTime()>0) {
result[0] = dp.getTime();
result[1] = dp.getTime();
break;
}
}
}
return result;
}
private int getTotal(DataPointVO[] target) {
int result = -1;
if (target != null && target.length > 0) {
result = 0;
for (DataPointVO dp: target) {
if (dp!=null && dp.getValue()>0) {
result += dp.getValue();
}
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy