本文整理了Java中com.twitter.util.Duration.apply()
方法的一些代码示例,展示了Duration.apply()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.apply()
方法的具体详情如下:
包路径:com.twitter.util.Duration
类名称:Duration
方法名:apply
暂无
代码示例来源:origin: twitter/distributedlog
@Override
public RecordMetadata get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
try {
FutureUtils.result(dlsnFuture, Duration.apply(timeout, unit));
// TODO: align the DLSN concepts with kafka concepts
return new RecordMetadata(new TopicPartition(topic, 0), -1L, -1L);
} catch (DLInterruptedException e) {
throw new InterruptedException("Interrupted on waiting for response");
} catch (IOException e) {
throw new ExecutionException("Error on waiting for response", e);
}
}
}
代码示例来源:origin: pinterest/secor
public void start() {
Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
@SuppressWarnings("deprecation")
AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
this.mPort,
20,
List$.MODULE$.<StatsFactory>empty(),
Option.<String>empty(),
List$.MODULE$.<Regex>empty(),
Map$.MODULE$.<String, CustomHttpHandler>empty(),
JavaConversions
.asScalaBuffer(Arrays.asList(defaultLatchIntervals)).toList()
);
RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
adminServiceFactory.apply(runtimeEnvironment);
try {
Properties properties = new Properties();
properties.load(this.getClass().getResource("build.properties").openStream());
String buildRevision = properties.getProperty("build_revision", "unknown");
LOG.info("build.properties build_revision: {}",
properties.getProperty("build_revision", "unknown"));
StatsUtil.setLabel("secor.build_revision", buildRevision);
} catch (Throwable t) {
LOG.error("Failed to load properties from build.properties", t);
}
}
}
代码示例来源:origin: twitter/distributedlog
private static void readLoop(final DistributedLogManager dlm,
final DLSN dlsn) throws Exception {
final CountDownLatch keepAliveLatch = new CountDownLatch(1);
System.out.println("Wait for records starting from " + dlsn);
final AsyncLogReader reader = FutureUtils.result(dlm.openAsyncLogReader(dlsn));
final FutureEventListener<LogRecordWithDLSN> readListener = new FutureEventListener<LogRecordWithDLSN>() {
@Override
public void onFailure(Throwable cause) {
System.err.println("Encountered error on reading records from stream " + dlm.getStreamName());
cause.printStackTrace(System.err);
keepAliveLatch.countDown();
}
@Override
public void onSuccess(LogRecordWithDLSN record) {
System.out.println("Received record " + record.getDlsn());
System.out.println("\"\"\"");
System.out.println(new String(record.getPayload(), UTF_8));
System.out.println("\"\"\"");
reader.readNext().addEventListener(this);
}
};
reader.readNext().addEventListener(readListener);
keepAliveLatch.await();
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
}
代码示例来源:origin: twitter/distributedlog
private static void readLoop(final DistributedLogManager dlm,
final DLSN dlsn,
final AtomicReference<DLSN> lastDLSN)
throws Exception {
final CountDownLatch keepAliveLatch = new CountDownLatch(1);
System.out.println("Wait for records starting from " + dlsn);
final AsyncLogReader reader = FutureUtils.result(dlm.openAsyncLogReader(dlsn));
final FutureEventListener<LogRecordWithDLSN> readListener = new FutureEventListener<LogRecordWithDLSN>() {
@Override
public void onFailure(Throwable cause) {
System.err.println("Encountered error on reading records from stream " + dlm.getStreamName());
cause.printStackTrace(System.err);
keepAliveLatch.countDown();
}
@Override
public void onSuccess(LogRecordWithDLSN record) {
System.out.println("Received record " + record.getDlsn());
System.out.println("\"\"\"");
System.out.println(new String(record.getPayload(), UTF_8));
System.out.println("\"\"\"");
lastDLSN.set(record.getDlsn());
reader.readNext().addEventListener(this);
}
};
reader.readNext().addEventListener(readListener);
keepAliveLatch.await();
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
}
代码示例来源:origin: twitter/distributedlog
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
代码示例来源:origin: twitter/distributedlog
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
代码示例来源:origin: twitter/distributedlog
readLoop(srcDlm, srcDlsn, targetWriter, replicationTransformer);
} finally {
FutureUtils.result(targetWriter.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
targetDlm.close();
srcDlm.close();
代码示例来源:origin: twitter/distributedlog
FutureUtils.result(writer.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
代码示例来源:origin: twitter/distributedlog
bkdlm11.createReadHandler(Optional.of("s1"));
try {
Await.result(s11Handler.lockStream(), Duration.apply(10000, TimeUnit.MILLISECONDS));
fail("Should fail lock stream using same subscriber id");
} catch (OwnershipAcquireFailedException oafe) {
代码示例来源:origin: openimaj/openimaj
/**
* Get the next value in the queue
*
* @param queueName
* @param waitFor
* @return the next value
*/
public String get(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return get(queueName, waitDuration);
}
代码示例来源:origin: org.openimaj.storm/core-storm
/**
* Get the next value in the queue
*
* @param queueName
* @param waitFor
* @return the next value
*/
public byte[] getByte(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return getByte(queueName, waitDuration);
}
代码示例来源:origin: org.openimaj.storm/core-storm
/**
* The next value without popping it
*
* @param queueName
* @param waitFor
* an amount of time to wait before returning null
* @return the next value
*/
public byte[] peekByte(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return peekByte(queueName, waitDuration);
}
代码示例来源:origin: com.twitter/finagle-kestrelx
/**
* Dequeue an item
*
* @param key the queue name
* @return a Buf if the item exists, null otherwise.
*/
public Future<Buf> get(String key) {
return this.get(key, Duration.apply(0, TimeUnit.SECONDS));
}
代码示例来源:origin: openimaj/openimaj
/**
* Get the next value in the queue
*
* @param queueName
* @param waitFor
* @return the next value
*/
public byte[] getByte(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return getByte(queueName, waitDuration);
}
代码示例来源:origin: openimaj/openimaj
/**
* The next value without popping it
*
* @param queueName
* @param waitFor
* an amount of time to wait before returning null
* @return the next value
*/
public String peek(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return peek(queueName, waitDuration);
}
代码示例来源:origin: com.twitter/finagle-kestrel
/**
* Dequeue an item
*
* @param key the queue name
* @return a Buf if the item exists, null otherwise.
*/
public Future<Buf> get(String key) {
return this.get(key, Duration.apply(0, TimeUnit.SECONDS));
}
代码示例来源:origin: openimaj/openimaj
/**
* The next value without popping it
*
* @param queueName
* @param waitFor
* an amount of time to wait before returning null
* @return the next value
*/
public byte[] peekByte(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return peekByte(queueName, waitDuration);
}
代码示例来源:origin: org.openimaj.storm/core-storm
/**
* The next value without popping it
*
* @param queueName
* @param waitFor
* an amount of time to wait before returning null
* @return the next value
*/
public String peek(String queueName, int waitFor) {
final Duration waitDuration = Duration.apply(waitFor, TimeUnit.MILLISECONDS);
return peek(queueName, waitDuration);
}
代码示例来源:origin: pinterest/pinlater
public PinLaterClient(String host, int port, int concurrency) {
this.service = ClientBuilder.safeBuild(
ClientBuilder.get()
.hosts(new InetSocketAddress(host, port))
.codec(ThriftClientFramedCodec.apply(Option.apply(new ClientId("pinlaterclient"))))
.hostConnectionLimit(concurrency)
.tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS))
.requestTimeout(Duration.apply(10, TimeUnit.SECONDS))
.retries(1));
this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory());
}
代码示例来源:origin: pinterest/pinlater
public PinLaterClient(ServerSet serverSet, int concurrency) {
ZookeeperServerSetCluster cluster = new ZookeeperServerSetCluster(serverSet);
ClientBuilder builder = ClientBuilder.get().cluster(cluster);
this.service = ClientBuilder.safeBuild(
builder.codec(ThriftClientFramedCodec.get())
.tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS))
.requestTimeout(Duration.apply(10, TimeUnit.SECONDS))
.hostConnectionLimit(concurrency));
this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory());
}
内容来源于网络,如有侵权,请联系作者删除!