本文整理汇总了Java中com.stumbleupon.async.Deferred.addCallback方法的典型用法代码示例。如果您正苦于以下问题:Java Deferred.addCallback方法的具体用法?Java Deferred.addCallback怎么用?Java Deferred.addCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.stumbleupon.async.Deferred
的用法示例。
在下文中一共展示了Deferred.addCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persist
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
@Override
public void persist(String metric, DataPoint dp, Map<String, String> tags, final Function<Object, Void> callback) {
try {
if(callback == null) {
tsdb.addPoint(metric, dp.getTimestamp(), dp.getValue(), tags).joinUninterruptibly();
}
else {
Deferred<Object> ret = tsdb.addPoint(metric, dp.getTimestamp(), dp.getValue(), tags);
ret.addCallback(new Callback<Object, Object>() {
@Override
public Object call(Object o) throws Exception {
return callback.apply(o);
}
});
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例2: writeDataPoints
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Main entry method for adding points
*
* @param data points list
*/
private void writeDataPoints(List<EventData> data) throws Exception {
if (data.size() < 1)
return;
final WritableDataPoints dataPoints = tsdb.newDataPoints();
final EventData first = data.get(0);
dataPoints.setSeries(first.metric, first.tags);
dataPoints.setBatchImport(false); // we need data to be persisted
long prevTs = 0;
Set<String> failures = new HashSet<String>();
for (EventData eventData : data) {
try {
if (eventData.timestamp == prevTs)
continue;
sinkCounter.incrementEventDrainAttemptCount();
prevTs = eventData.timestamp;
final Deferred<Object> d =
eventData.makeDeferred(dataPoints, this);
d.addCallback(new Callback<Object, Object>() {
@Override
public Object call(Object o) throws Exception {
pointsCounter.mark();
inFlight.decrementAndGet();
signal.release();
return null;
}
});
d.addErrback(this);
if (throttle)
throttle(d);
inFlight.incrementAndGet();
sinkCounter.incrementEventDrainSuccessCount();
} catch (IllegalArgumentException ie) {
failures.add(ie.getMessage());
}
}
if (failures.size() > 0) {
logger.error("Points imported with " + failures.toString() + " IllegalArgumentExceptions");
}
}