本文整理汇总了Java中com.stumbleupon.async.Deferred.fromResult方法的典型用法代码示例。如果您正苦于以下问题:Java Deferred.fromResult方法的具体用法?Java Deferred.fromResult怎么用?Java Deferred.fromResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.stumbleupon.async.Deferred
的用法示例。
在下文中一共展示了Deferred.fromResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: atomicIncrement
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Atomically and durably increments a value in BigTable.
* <p>
* This is equivalent to
* {@link #atomicIncrement(AtomicIncrementRequest, boolean) atomicIncrement}
* {@code (request, true)}
* @param request The increment request.
* @return The deferred {@code long} value that results from the increment.
*/
public Deferred<Long> atomicIncrement(final AtomicIncrementRequest request) {
num_atomic_increments.increment();
Table table = null;
try {
table = hbase_connection.getTable(TableName.valueOf(request.table()));
long val = table.incrementColumnValue(request.key(),
request.family(), request.qualifier(),
request.getAmount(),
request.isDurable() ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
LOG.info("BigTable API: AtomicIncrement for {} returned {}", request, val);
return Deferred.fromResult(val);
} catch (IOException e) {
return Deferred.fromError(e);
} finally {
close(table);
}
}
示例4: shutdown
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Closes the producer if it's not null already
*/
public Deferred<Object> shutdown() {
LOG.warn("Shutting down Kafka requeue producer");
if (producer != null) {
producer.close();
}
return Deferred.fromResult(null);
}
示例5: call
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
@Override
public Deferred<TagsetLookupResult> call(RowResultIterator rows) {
for (RowResult row : rows) {
int id = row.getInt(Tables.TAGSETS_ID_INDEX);
Preconditions.checkState(id >= probe);
if (id != probe) {
// We found a hole in the table where we expected the tagset.
return Deferred.fromResult(new TagsetLookupResult(false, probe));
}
if (tagset.equals(row.getBinary(Tables.TAGSETS_TAGSET_INDEX))) {
return Deferred.fromResult(new TagsetLookupResult(true, id));
}
probe++;
}
// We probed through the entire RowResult and didn't find the tagset.
if (!scanner.hasMoreRows()) {
if (probe <= Ints.saturatedCast((long) id + TAGSETS_PER_SCAN)) {
// We found a hole at the end of the scan.
return Deferred.fromResult(new TagsetLookupResult(false, probe));
}
// The current scanner has been exhausted; create a new scanner from the
// latest probe point.
scanner = tagsetScanner(probe);
id = probe;
}
return scanner.nextRows().addCallbackDeferring(this);
}
示例6: publishDataPoint
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see net.opentsdb.tsd.RTPublisher#publishDataPoint(java.lang.String, long, long, java.util.Map, byte[])
*/
@Override
public Deferred<Object> publishDataPoint(final String metric, final long timestamp, final long value, final Map<String, String> tags, final byte[] tsuid) {
final Context ctx = eventHandlerTimer.time();
longDataPointsMeter.mark();
totalEventsMeter.mark();
dataPointsMeter.mark();
ctx.stop();
return Deferred.fromResult(null);
}
示例7: publishAnnotation
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see net.opentsdb.tsd.RTPublisher#publishAnnotation(net.opentsdb.meta.Annotation)
*/
@Override
public Deferred<Object> publishAnnotation(final Annotation annotation) {
final Context ctx = eventHandlerTimer.time();
annotationsMeter.mark();
totalEventsMeter.mark();
ctx.stop();
return Deferred.fromResult(null);
}
示例8: testLookup
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
public Deferred<EnumMap<UniqueIdType, Map<String, String>>> testLookup(final TSDBMetricMeta meta) {
final Context ctx = resolveUidsTimer.time();
final EnumMap<UniqueIdType, Map<String, String>> map = new EnumMap<UniqueIdType, Map<String, String>>(UniqueIdType.class);
final TSDBMetricMeta m = metricMetas.get(meta.getTsuid());
map.put(UniqueIdType.METRIC, Collections.singletonMap(m.getMetricName(), m.getMetricUid()));
map.put(UniqueIdType.TAGK, m.getTagKeyUids());
map.put(UniqueIdType.TAGV, m.getTagValueUids());
ctx.close();
return Deferred.fromResult(map);
}
示例9: publishDataPoint
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see net.opentsdb.tsd.RTPublisher#publishDataPoint(java.lang.String, long, long, java.util.Map, byte[])
*/
@Override
public Deferred<Object> publishDataPoint(final String metric, final long timestamp, final long value, final Map<String, String> tags, final byte[] tsuid) {
final long sequence = cacheRb.next();
final TSDBMetricMeta meta = cacheRb.get(sequence);
meta.reset().load(metric, tags, tsuid).startTimer();
cacheRb.publish(sequence);
return Deferred.fromResult(null);
}
示例10: insertTagset
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Attempts to insert the provided tagset and ID. Returns {@code true} if the
* write was successful, or {@code false} if the write failed due to a tagset
* with the same ID already existing in the table.
*
* @param tagset the tagset to insert
* @param id the ID to insert the tagset with
* @return whether the write succeeded
*/
private Deferred<Boolean> insertTagset(final SerializedTagset tagset, final int id) throws KuduException {
final class InsertTagsetCB implements Callback<Deferred<Boolean>, OperationResponse> {
@Override
public Deferred<Boolean> call(OperationResponse response) {
if (response.hasRowError()) {
if (response.getRowError().getErrorStatus().isAlreadyPresent()) {
LOG.info("Attempted to insert duplicate tagset; id: {}, tagset: {}", id, tagset);
// TODO: Consider adding a backoff with jitter before attempting
// the insert again (if the lookup fails).
return Deferred.fromResult(false);
}
return Deferred.fromError(new RuntimeException(
String.format("Unable to insert tagset; id: %s, tagset: %s, error: %s",
id, tagset, response.getRowError())));
} else {
return Deferred.fromResult(true);
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).toString();
}
}
LOG.debug("Inserting tagset; id: {}, tags: {}", id, tagset);
final AsyncKuduSession session = client.newSession();
try {
// We don't have to handle PleaseThrottleException because we are only
// inserting a single row.
final Insert insert = tagsetsTable.newInsert();
insert.getRow().addInt(Tables.TAGSETS_ID_INDEX, id);
insert.getRow().addBinary(Tables.TAGSETS_TAGSET_INDEX, tagset.getBytes());
return session.apply(insert).addCallbackDeferring(new InsertTagsetCB());
} finally {
session.close();
}
}
示例11: shutdown
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see net.opentsdb.tsd.HttpRpcPlugin#shutdown()
*/
@Override
public Deferred<Object> shutdown() {
log.info(">>>>> Stopping WebSocketRPC service....");
log.info("<<<<< WebSocketRPC service Stopped.");
return Deferred.fromResult(null);
}
示例12: addPoint
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see com.heliosapm.tsdbex.test.mocks.EmptyTSDB#addPoint(java.lang.String, long, double, java.util.Map)
*/
@Override
public Deferred<Object> addPoint(String metric, long timestamp,
double value, Map<String, String> tags) {
KafkaRPCTest.latch.get().countDown();
if (rt_publisher != null) {
rt_publisher.publishDataPoint(metric, timestamp, value, tags, (metric + ":" + tags.toString()).getBytes());
}
return Deferred.fromResult(null);
}
示例13: getTagsetIDsForTag
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Retrieves the tagset IDs of all tagsets which contain the specified tag.
* The tagset IDs are returned in sorted order.
*
* @param key the tag key
* @param value the tag value
* @return the sorted tagset IDs
*/
public Deferred<IntVec> getTagsetIDsForTag(final String key, final String value) {
AsyncKuduScanner.AsyncKuduScannerBuilder scan = client.newScannerBuilder(table);
scan.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGS_KEY_COLUMN,
ComparisonOp.EQUAL, key));
scan.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGS_VALUE_COLUMN,
ComparisonOp.EQUAL, value));
scan.setProjectedColumnIndexes(TAGSET_ID_PROJECTION);
final AsyncKuduScanner scanner = scan.build();
class GetTagCB implements Callback<Deferred<IntVec>, RowResultIterator> {
private final IntVec tagsetIDs = IntVec.create();
@Override
public Deferred<IntVec> call(RowResultIterator results) {
for (RowResult result : results) {
tagsetIDs.push(result.getInt(0));
}
if (scanner.hasMoreRows()) {
return scanner.nextRows().addCallbackDeferring(this);
}
// The Kudu java client doesn't yet allow us to specify a sorted
// (fault-tolerant) scan, so have to sort manually.
tagsetIDs.sort();
return Deferred.fromResult(tagsetIDs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("key", key).add("value", value).toString();
}
}
return scanner.nextRows().addCallbackDeferring(new GetTagCB());
}
示例14: compareAndSet
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/**
* Atomic Compare-And-Set (CAS) on a single cell.
* <p>
* Note that edits sent through this method <b>cannot be batched</b>, and
* won't be subject to the {@link #setFlushInterval flush interval}. This
* entails that write throughput will be lower with this method as edits
* have to be sent out to the wire one by one.
* <p>
* This request enables you to atomically update the value of an existing
* cell in BigTable using a CAS operation. It's like a {@link PutRequest}
* except that you also pass an expected value. If the last version of the
* cell identified by your {@code PutRequest} matches the expected value,
* BigTable will atomically update it to the new value.
* <p>
* If the expected value is the empty byte array, BigTable will atomically
* create the cell provided that it doesn't exist already. This can be used
* to ensure that your RPC doesn't overwrite an existing value. Note
* however that this trick cannot be used the other way around to delete
* an expected value atomically.
* @param edit The new value to write.
* @param expected The expected value of the cell to compare against.
* <strong>This byte array will NOT be copied.</strong>
* @return A deferred boolean, if {@code true} the CAS succeeded, otherwise
* the CAS failed because the value in BigTable didn't match the expected value
* of the CAS request.
*/
public Deferred<Boolean> compareAndSet(final PutRequest edit,
final byte[] expected) {
long ts1 = System.currentTimeMillis();
Table table = null;
try {
table = hbase_connection.getTable(TableName.valueOf(edit.table()));
Put put = new Put(edit.key());
long ts = edit.timestamp();
for (int i = 0; i < edit.qualifiers().length; i++) {
put.addColumn(edit.family, edit.qualifiers()[i], ts, edit.values()[i]);
}
boolean success = table.checkAndPut(edit.key(), edit.family(), edit.qualifier(),
Bytes.memcmp(EMPTY_ARRAY, expected) == 0 ? null : expected,
put);
long ts2 = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug("BigTable API compareAndSet for cell: [{}], expected: [{}] "
+ "returned success: {} in {}ms", edit,Bytes.pretty(expected),
success, ts2 - ts1);
}
return Deferred.fromResult(success);
} catch (IOException e) {
return Deferred.fromError(e);
} finally {
close(table);
}
}
示例15: newDeferred
import com.stumbleupon.async.Deferred; //导入方法依赖的package包/类
/** Creates a new Deferred that's already called back. */
private static <T> Answer<Deferred<T>> newDeferred(final T result) {
return new Answer<Deferred<T>>() {
public Deferred<T> answer(final InvocationOnMock invocation) {
return Deferred.fromResult(result);
}
};
}