本文整理汇总了Java中com.stumbleupon.async.Deferred类的典型用法代码示例。如果您正苦于以下问题:Java Deferred类的具体用法?Java Deferred怎么用?Java Deferred使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deferred类属于com.stumbleupon.async包,在下文中一共展示了Deferred类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runEmptyMetric
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test
public void runEmptyMetric() throws Exception {
when(tsdb.addPoint(anyString(), anyLong(), anyLong(), anyMap()))
.thenReturn(Deferred.fromResult(null));
data = new Metric(null, TS, "42", TAGS);
when(message.message()).thenReturn(JSON.serializeToBytes(data));
KafkaRpcPluginThread writer = Mockito.spy(
new KafkaRpcPluginThread(group, 1, TOPICS));
writer.run();
verify(tsdb, never()).addPoint(anyString(), anyLong(), anyLong(), anyMap());
verify(tsdb, never()).addHistogramPoint(anyString(), anyLong(),
any(byte[].class), anyMap());
verify(tsdb, never()).addAggregatePoint(anyString(), anyLong(), anyLong(),
anyMap(), anyBoolean(), anyString(), anyString(), anyString());
verifyMessageRead(writer, false);
}
示例2: runStorageFailureRollup
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test
public void runStorageFailureRollup() throws Exception {
when(group.getConsumerType()).thenReturn(TsdbConsumerType.ROLLUP);
setupAggData(false, false);
when(tsdb.addAggregatePoint(anyString(), anyLong(), anyLong(), anyMap(),
anyBoolean(), anyString(), anyString(), anyString()))
.thenReturn(Deferred.fromResult(mock(HBaseException.class)));
KafkaRpcPluginThread writer = Mockito.spy(
new KafkaRpcPluginThread(group, 1, TOPICS));
writer.run();
verifyMessageRead(writer, true);
verify(tsdb, times(1)).addAggregatePoint(METRIC, TS, 42L, TAGS, false,
"1h", "sum", null);
verifyCtrsInc(new String[]{ "readRollupCounter", "requeuedRollupCounter",
"storageExceptionCounter" });
}
示例3: runStorageFailurePreAgg
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test
public void runStorageFailurePreAgg() throws Exception {
when(group.getConsumerType()).thenReturn(TsdbConsumerType.ROLLUP);
setupAggData(false, true);
when(tsdb.addAggregatePoint(anyString(), anyLong(), anyLong(), anyMap(),
anyBoolean(), anyString(), anyString(), anyString()))
.thenReturn(Deferred.fromResult(mock(HBaseException.class)));
KafkaRpcPluginThread writer = Mockito.spy(
new KafkaRpcPluginThread(group, 1, TOPICS));
writer.run();
verifyMessageRead(writer, true);
verify(tsdb, times(1)).addAggregatePoint(METRIC, TS, 42L, TAGS, true,
null, null, "sum");
verifyCtrsInc(new String[]{ "readAggregateCounter", "requeuedAggregateCounter",
"storageExceptionCounter" });
}
示例4: runStorageFailureHistogram
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test
public void runStorageFailureHistogram() throws Exception {
when(group.getConsumerType()).thenReturn(TsdbConsumerType.ROLLUP);
setupHistogramData(false);
when(tsdb.addHistogramPoint(anyString(), anyLong(), any(byte[].class),
anyMap()))
.thenReturn(Deferred.fromResult(mock(HBaseException.class)));
KafkaRpcPluginThread writer = Mockito.spy(
new KafkaRpcPluginThread(group, 1, TOPICS));
writer.run();
verifyMessageRead(writer, true);
verify(tsdb, times(1)).addHistogramPoint(eq(METRIC), eq(TS),
any(byte[].class), eq(TAGS));
verifyCtrsInc(new String[]{ "readHistogramCounter", "requeuedHistogramCounter",
"storageExceptionCounter" });
}
示例5: setupRawDataList
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
private void setupRawDataList(final boolean requeued) {
when(tsdb.addPoint(anyString(), anyLong(), anyLong(), anyMap()))
.thenReturn(Deferred.fromResult(null));
TypedIncomingData ev1 = new Metric(METRIC, TS, "42", TAGS);
TypedIncomingData ev2 = new Metric(METRIC2, TS, "42", TAGS);
if (requeued) {
ev1.setRequeueTS(TS + 60);
ev2.setRequeueTS(TS + 60);
}
StringBuilder sb = new StringBuilder();
sb.append("[");
sb.append(new String(JSON.serializeToBytes(ev1)));
sb.append(",");
sb.append(new String(JSON.serializeToBytes(ev2)));
sb.append("]");
when(message.message()).thenReturn(sb.toString().getBytes());
}
示例6: setupHistogramData
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
private void setupHistogramData(final boolean requeued) {
config.overrideConfig("tsd.core.histograms.config",
"{\"net.opentsdb.core.SimpleHistogramDecoder\": 42}");
final HistogramCodecManager manager;
manager = new HistogramCodecManager(tsdb);
when(tsdb.histogramManager()).thenReturn(manager);
when(tsdb.addHistogramPoint(anyString(), anyLong(), any(byte[].class),
anyMap()))
.thenReturn(Deferred.fromResult(null));
final Histogram histo = new Histogram();
histo.setMetric(METRIC);
histo.setTimestamp(TS);
histo.setTags(new HashMap<String, String>(TAGS));
histo.setOverflow(1);
histo.setBuckets(ImmutableMap.<String, Long>builder()
.put("0,1", 42L)
.put("1,5", 24L)
.build());
data = histo;
if (requeued) {
data.setRequeueTS(TS + 60);
}
when(message.message()).thenReturn(JSON.serializeToBytes(data));
}
示例7: shutdown
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see net.opentsdb.tsd.RTPublisher#shutdown()
*/
@Override
public Deferred<Object> shutdown() {
log.info(">>>>> Stopping TSDBChronicleEventPublisher");
stopDisruptor("CacheLookup", cacheRbDisruptor);
stopDisruptor("Dispatch", dispatchRbDisruptor);
keepRunning.set(false);
if(rolledFileDeletionThread!=null) rolledFileDeletionThread.interrupt();
try {
outQueue.close();
log.info("OutboundQueue Closed");
} catch (Exception ex) {
log.warn("Error closing OutboundQueue: {}", ex);
}
try {
JMXHelper.unregisterMBean(JMXHelper.objectName("net.opentsdb:service=TSDBChronicleEventPublisher"));
} catch (Exception x) {/* No Op */}
log.info("<<<<< TSDBChronicleEventPublisher Stopped");
return Deferred.fromResult(null);
}
示例8: Tagsets
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
Tagsets(AsyncKuduClient client, Tags tags, KuduTable tagsetsTable) {
this.client = client;
this.tagsetsTable = tagsetsTable;
this.tags = tags;
this.columnIndexes = ImmutableList.of(Tables.TAGSETS_ID_INDEX,
Tables.TAGSETS_TAGSET_INDEX);
this.tagsets = CacheBuilder.newBuilder()
.maximumSize(1024 * 1024)
.build(new CacheLoader<SerializedTagset, Deferred<Integer>>() {
@Override
public Deferred<Integer> load(SerializedTagset tagset) {
return lookupOrInsertTagset(tagset, hashForTesting == null ?
tagset.hashCode() : hashForTesting);
}
});
}
示例9: open
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
/**
* Opens a Kudu TS instance on a Kudu cluster.
*
* @param kuduMasterAddressess list of "host:port" pair master addresses
* @param name the name of the Kudu timeseries store. Multiple instances of
* Kudu TS can occupy the same Kudu cluster by using a different name.
* @return the opened {@code KuduTS}.
* @throws Exception on error
*/
public static KuduTS open(List<String> kuduMasterAddressess, String name) throws Exception {
AsyncKuduClient client = new AsyncKuduClient.AsyncKuduClientBuilder(kuduMasterAddressess).build();
Deferred<KuduTable> metricsDeferred = client.openTable(Tables.metricsTableName(name));
Deferred<KuduTable> tagsetsDeferred = client.openTable(Tables.tagsetsTableName(name));
Deferred<KuduTable> tagsDeferred = client.openTable(Tables.tagsTableName(name));
KuduTable metricsTable = metricsDeferred.join(client.getDefaultAdminOperationTimeoutMs());
KuduTable tagsetsTable = tagsetsDeferred.join(client.getDefaultAdminOperationTimeoutMs());
KuduTable tagsTable = tagsDeferred.join(client.getDefaultAdminOperationTimeoutMs());
Tags tags = new Tags(client, tagsTable);
Tagsets tagsets = new Tagsets(client, tags, tagsetsTable);
Metrics metrics = new Metrics(client, metricsTable, tagsets);
return new KuduTS(client, name, metrics, tagsets, tags);
}
示例10: openOrCreateTable
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
private static Deferred<KuduTable> openOrCreateTable(final AsyncKuduClient client,
final String table,
final Schema schema,
final CreateTableOptions options) throws Exception {
class CreateTableErrback implements Callback<Deferred<KuduTable>, Exception> {
@Override
public Deferred<KuduTable> call(Exception e) throws Exception {
// TODO(danburkert): we should only do this if the error is "not found"
LOG.debug("Creating table {}", table);
return client.createTable(table, schema, options);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("table", table).toString();
}
}
return client.openTable(table).addErrback(new CreateTableErrback());
}
示例11: testConcurrentLookup
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test(timeout = 10000)
public void testConcurrentLookup() throws Exception {
try (KuduTS ts = KuduTS.openOrCreate(ImmutableList.of(masterAddresses),
"testConcurrentLookup",
CreateOptions.defaults())) {
Tagsets tagsets = ts.getTagsets();
SortedMap<String, String> tagset = ImmutableSortedMap.of("k1", "v1");
List<Deferred<Integer>> deferreds = new ArrayList<>();
for (int i = 0; i < 10; i++) {
deferreds.add(tagsets.getTagsetID(tagset));
tagsets.clear();
}
assertEquals(1, ImmutableSet.copyOf(Deferred.group(deferreds).join()).size());
}
}
示例12: testHashCollisions
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
@Test(timeout = 100000)
public void testHashCollisions() throws Exception {
try (KuduTS ts = KuduTS.openOrCreate(ImmutableList.of(masterAddresses),
"testHashCollisions",
CreateOptions.defaults())) {
Tagsets tagsets = ts.getTagsets();
int numTagsets = 100;
tagsets.setHashForTesting(0);
List<Deferred<Integer>> deferreds = new ArrayList<>();
for (int i = 0; i <= numTagsets; i++) {
deferreds.add(tagsets.getTagsetID(ImmutableSortedMap.of("key", Integer.toString(i))));
}
List<Integer> ids = Deferred.group(deferreds).join();
Collections.sort(ids);
for (int i = 0; i < numTagsets; i++) {
assertEquals(i, ids.get(i).intValue());
}
}
}
示例13: 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);
}
}
示例14: flush
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
/**
* Flushes to BigTable any buffered client-side write operation.
* <p>
* @return A {@link Deferred}, whose callback chain will be invoked when
* everything that was buffered at the time of the call has been flushed.
* <p>
* Note that this doesn't guarantee that <b>ALL</b> outstanding RPCs have
* completed. This doesn't introduce any sort of global sync point. All
* it does really is it sends any buffered RPCs to BigTable.
*/
public Deferred<Object> flush() {
LOG.info("Flushing buffered mutations");
final ArrayList<Deferred<Object>> deferreds =
new ArrayList<Deferred<Object>>(mutators.size());
for (final BufferedMutator mutator : mutators.values()) {
try {
// TODO - run in a separate thread, breaks asynchronus behavior
// right now
mutator.flush();
deferreds.add(Deferred.fromResult(null));
} catch (IOException e) {
LOG.error("Error occurred while flushing buffer", e);
deferreds.add(Deferred.fromError(e));
}
}
num_flushes.increment();
@SuppressWarnings("unchecked")
final Deferred<Object> flushed = (Deferred) Deferred.group(deferreds);
return flushed;
}
示例15: openScanner
import com.stumbleupon.async.Deferred; //导入依赖的package包/类
/**
* Package-private access point for {@link Scanner}s to open themselves.
* @param scanner The scanner to open.
* @return A deferred scanner ID (long) if BigTable 0.94 and before, or a
* deferred {@link Scanner.Response} if BigTable 0.95 and up.
*/
Deferred<Object> openScanner(final Scanner scanner) {
num_scanners_opened.increment();
if (LOG.isDebugEnabled()) {
LOG.debug("BigTable API: Scanning table with {}", scanner.toString());
}
Table table = null;
try {
table = hbase_connection.getTable(TableName.valueOf(scanner.table()));
ResultScanner result = table.getScanner(scanner.getHbaseScan());
scanner.setResultScanner(result);
scanner.setHbaseTable(table);
return Deferred.fromResult(new Object());
} catch (IOException e) {
if (table != null) {
try {
table.close();
} catch (Exception e1) {}
}
return Deferred.fromError(e);
}
}