本文整理了Java中com.twitter.util.Duration.fromSeconds()
方法的一些代码示例,展示了Duration.fromSeconds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.fromSeconds()
方法的具体详情如下:
包路径:com.twitter.util.Duration
类名称:Duration
方法名:fromSeconds
暂无
代码示例来源:origin: twitter/distributedlog
public MovingAverageRateFactory(Timer timer) {
this.avgs = new CopyOnWriteArrayList<SampledMovingAverageRate>();
this.timer = timer;
Function0<BoxedUnit> sampleTask = new Function0<BoxedUnit>() {
public BoxedUnit apply() {
sampleAll();
return null;
}
};
this.timerTask = timer.schedulePeriodically(
Time.now(), Duration.fromSeconds(DEFAULT_INTERVAL_SECS), sampleTask);
}
代码示例来源:origin: twitter/distributedlog
public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception {
try {
return Await.result(future, Duration.fromSeconds(10));
} catch (Exception ex) {
fail("unexpected exception " + ex.getClass().getName());
throw ex;
}
}
}
代码示例来源:origin: twitter/distributedlog
.handshakeWithClientInfo(handshakeWithClientInfo)
.clientBuilder(ClientBuilder.get()
.connectTimeout(Duration.fromSeconds(1))
.tcpConnectTimeout(Duration.fromSeconds(1))
.requestTimeout(Duration.fromSeconds(2))
.hostConnectionLimit(2)
.hostConnectionCoresize(2)
代码示例来源:origin: twitter/distributedlog
static DistributedLogClientBuilder createDistributedLogClientBuilder(ServerSet serverSet) {
return DistributedLogClientBuilder.newBuilder()
.name("rebalancer_tool")
.clientId(ClientId$.MODULE$.apply("rebalancer_tool"))
.maxRedirects(2)
.serverSet(serverSet)
.clientBuilder(ClientBuilder.get()
.connectionTimeout(Duration.fromSeconds(2))
.tcpConnectTimeout(Duration.fromSeconds(2))
.requestTimeout(Duration.fromSeconds(10))
.hostConnectionLimit(1)
.hostConnectionCoresize(1)
.keepAlive(true)
.failFast(false));
}
代码示例来源:origin: twitter/distributedlog
private ClientBuilder getDefaultClientBuilder() {
return ClientBuilder.get()
.hostConnectionLimit(1)
.tcpConnectTimeout(Duration.fromMilliseconds(200))
.connectTimeout(Duration.fromMilliseconds(200))
.requestTimeout(Duration.fromSeconds(1));
}
代码示例来源:origin: twitter/distributedlog
@Override
protected int runCmd(CommandLine commandLine) throws Exception {
try {
parseCommandLine(commandLine);
} catch (ParseException pe) {
System.err.println("ERROR: failed to parse commandline : '" + pe.getMessage() + "'");
printUsage();
return -1;
}
DistributedLogClientBuilder clientBuilder = DistributedLogClientBuilder.newBuilder()
.name("proxy_tool")
.clientId(ClientId$.MODULE$.apply("proxy_tool"))
.maxRedirects(2)
.host(address)
.clientBuilder(ClientBuilder.get()
.connectionTimeout(Duration.fromSeconds(2))
.tcpConnectTimeout(Duration.fromSeconds(2))
.requestTimeout(Duration.fromSeconds(10))
.hostConnectionLimit(1)
.hostConnectionCoresize(1)
.keepAlive(true)
.failFast(false));
Pair<DistributedLogClient, MonitorServiceClient> clientPair =
ClientUtils.buildClient(clientBuilder);
try {
return runCmd(clientPair);
} finally {
clientPair.getLeft().close();
}
}
代码示例来源:origin: twitter/distributedlog
.serverSet(serverSet.getServerSet())
.clientBuilder(ClientBuilder.get()
.connectionTimeout(Duration.fromSeconds(2))
.tcpConnectTimeout(Duration.fromSeconds(2))
.requestTimeout(Duration.fromSeconds(10))
.hostConnectionLimit(1)
.hostConnectionCoresize(1)
代码示例来源:origin: twitter/distributedlog
private void checkAllSubmittedButFailed(BKAsyncLogWriter writer,
int batchSize,
int recSize,
long txIndex) throws Exception {
List<LogRecord> records = DLMTestUtil.getLogRecordInstanceList(txIndex, batchSize, recSize);
Future<List<Future<DLSN>>> futureResults = writer.writeBulk(records);
assertNotNull(futureResults);
List<Future<DLSN>> results = Await.result(futureResults, Duration.fromSeconds(10));
assertNotNull(results);
assertEquals(results.size(), records.size());
for (Future<DLSN> result : results) {
validateFutureFailed(result, IOException.class);
}
}
}
代码示例来源:origin: twitter/distributedlog
@Test(timeout = 60000)
public void testBuildClientsFromSameBuilder() throws Exception {
DistributedLogClientBuilder builder = DistributedLogClientBuilder.newBuilder()
.name("build-clients-from-same-builder")
.clientId(ClientId$.MODULE$.apply("test-builder"))
.finagleNameStr("inet!127.0.0.1:7001")
.streamNameRegex(".*")
.handshakeWithClientInfo(true)
.clientBuilder(ClientBuilder.get()
.hostConnectionLimit(1)
.connectTimeout(Duration.fromSeconds(1))
.tcpConnectTimeout(Duration.fromSeconds(1))
.requestTimeout(Duration.fromSeconds(10)));
DistributedLogClient client1 = builder.build();
DistributedLogClient client2 = builder.build();
assertFalse(client1 == client2);
}
}
代码示例来源:origin: twitter/distributedlog
@Test(timeout = 60000)
public void testGetLogRecordCountAsync() throws Exception {
DistributedLogManager dlm = createNewDLM(conf, testNames.getMethodName());
BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
DLMTestUtil.generateCompletedLogSegments(dlm, conf, 2, 10);
Future<Long> futureCount = dlm.getLogRecordCountAsync(DLSN.InitialDLSN);
Long count = Await.result(futureCount, Duration.fromSeconds(2));
assertEquals(20, count.longValue());
writer.close();
dlm.close();
}
代码示例来源:origin: twitter/distributedlog
private DLSN checkAllSucceeded(BKAsyncLogWriter writer,
int batchSize,
int recSize,
long ledgerIndex,
long entryIndex,
long slotIndex,
long txIndex) throws Exception {
List<LogRecord> records = DLMTestUtil.getLogRecordInstanceList(txIndex, batchSize, recSize);
Future<List<Future<DLSN>>> futureResults = writer.writeBulk(records);
assertNotNull(futureResults);
List<Future<DLSN>> results = Await.result(futureResults, Duration.fromSeconds(10));
assertNotNull(results);
assertEquals(results.size(), records.size());
long prevEntryId = 0;
DLSN lastDlsn = null;
for (Future<DLSN> result : results) {
DLSN dlsn = Await.result(result, Duration.fromSeconds(10));
lastDlsn = dlsn;
// If we cross a transmission boundary, slot id gets reset.
if (dlsn.getEntryId() > prevEntryId) {
slotIndex = 0;
}
assertEquals(ledgerIndex, dlsn.getLogSegmentSequenceNo());
assertEquals(slotIndex, dlsn.getSlotId());
slotIndex++;
prevEntryId = dlsn.getEntryId();
}
return lastDlsn;
}
代码示例来源:origin: twitter/distributedlog
@Test(timeout = 60000)
public void testWriteFutureDoesNotCompleteUntilWritePersisted() throws Exception {
String name = testNames.getMethodName();
DistributedLogConfiguration conf = new DistributedLogConfiguration();
conf.setPeriodicFlushFrequencyMilliSeconds(Integer.MAX_VALUE);
conf.setImmediateFlushEnabled(false);
DistributedLogManager dlmwriter = createNewDLM(conf, name);
DistributedLogManager dlmreader = createNewDLM(conf, name);
byte[] byteStream = DLMTestUtil.repeatString("abc", 51).getBytes();
// Can't reliably test the future is not completed until fsync is called, since writer.force may just
// happen very quickly. But we can test that the mechanics of the future write and api are basically
// correct.
AppendOnlyStreamWriter writer = dlmwriter.getAppendOnlyStreamWriter();
Future<DLSN> dlsnFuture = writer.write(DLMTestUtil.repeatString("abc", 11).getBytes());
// The real problem is the fsync completes before writes are submitted, so it never takes effect.
Thread.sleep(1000);
assertFalse(dlsnFuture.isDefined());
writer.force(false);
// Must not throw.
Await.result(dlsnFuture, Duration.fromSeconds(5));
writer.close();
dlmwriter.close();
AppendOnlyStreamReader reader = dlmreader.getAppendOnlyStreamReader();
byte[] bytesIn = new byte[byteStream.length];
int read = reader.read(bytesIn, 0, 31);
assertEquals(31, read);
reader.close();
dlmreader.close();
}
代码示例来源:origin: twitter/distributedlog
@Test(timeout = 60000)
public void testAsyncWritePendingWritesAbortedWhenLedgerRollTriggerFails() throws Exception {
String name = runtime.getMethodName();
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(testConf);
confLocal.setOutputBufferSize(1024);
confLocal.setMaxLogSegmentBytes(1024);
confLocal.setLogSegmentRollingIntervalMinutes(0);
DistributedLogManager dlm = createNewDLM(confLocal, name);
BKAsyncLogWriter writer = (BKAsyncLogWriter)(dlm.startAsyncLogSegmentNonPartitioned());
// Write one record larger than max seg size. Ledger doesn't roll until next write.
int txid = 1;
LogRecord record = DLMTestUtil.getLogRecordInstance(txid++, 2048);
Future<DLSN> result = writer.write(record);
DLSN dlsn = Await.result(result, Duration.fromSeconds(10));
assertEquals(1, dlsn.getLogSegmentSequenceNo());
record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1);
result = writer.write(record);
validateFutureFailed(result, LogRecordTooLongException.class);
record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1);
result = writer.write(record);
validateFutureFailed(result, WriteException.class);
record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1);
result = writer.write(record);
validateFutureFailed(result, WriteException.class);
writer.closeAndComplete();
dlm.close();
}
代码示例来源:origin: org.scray/scray-client-jdbc
private void refreshEndpointsWithError() throws Exception {
Future<List<ScrayTServiceEndpoint>> eplist = connection
.getCombinedClient().getServiceEndpoints();
endpointCache = Await.result(eplist, Duration.fromSeconds(TIMEOUT));
log.debug("Refreshed scray service endpoints: "
+ Joiner.on(", ").join(endpointCache));
}
代码示例来源:origin: org.scray/scray-client-jdbc
public ScrayUUID query(ScrayTQuery query, int queryTimeout)
throws SQLException {
try {
Future<ScrayUUID> fuuid = getClient().query(query);
return Await
.result(fuuid, Duration.fromSeconds(queryTimeout));
} catch (Exception e) {
throw new SQLException(e);
}
}
代码示例来源:origin: org.scray/scray-client-jdbc
public ScrayTResultFrame getResults(ScrayUUID queryId, int queryTimeout)
throws SQLException {
try {
Future<ScrayTResultFrame> fframe = getClient().getResults(queryId); // getResults(queryId);
ScrayTResultFrame frame = Await.result(fframe, Duration.fromSeconds(queryTimeout));
return frame;
} catch (Exception e) {
throw new SQLException(e);
}
}
}
代码示例来源:origin: org.scray/scray-client-jdbc
public ScrayUUID query(ScrayTQuery query, int queryTimeout)
throws SQLException {
try {
Future<ScrayUUID> fuuid = getClient().query(query);
return Await.result(fuuid, Duration.fromSeconds(queryTimeout));
} catch (Exception e) {
throw new SQLException(e);
}
}
代码示例来源:origin: org.scray/scray-client-jdbc
public ScrayTResultFrame getResults(ScrayUUID queryId, int queryTimeout)
throws SQLException {
try {
Future<ScrayTResultFrame> fframe = getClient().getResults(queryId,
pageIndex);
ScrayTResultFrame frame = Await.result(fframe, Duration.fromSeconds(queryTimeout));
pageIndex += 1;
return frame;
} catch (Exception e) {
throw new SQLException(e);
}
}
}
代码示例来源:origin: com.twitter/distributedlog-client
private ClientBuilder getDefaultClientBuilder() {
return ClientBuilder.get()
.hostConnectionLimit(1)
.tcpConnectTimeout(Duration.fromMilliseconds(200))
.connectTimeout(Duration.fromMilliseconds(200))
.requestTimeout(Duration.fromSeconds(1));
}
代码示例来源:origin: org.apache.distributedlog/distributedlog-client
private ClientBuilder getDefaultClientBuilder(ClientConfig clientConfig) {
ClientBuilder builder = ClientBuilder.get()
.tcpConnectTimeout(Duration.fromMilliseconds(200))
.connectTimeout(Duration.fromMilliseconds(200))
.requestTimeout(Duration.fromSeconds(1));
if (!clientConfig.getThriftMux()) {
builder = builder.hostConnectionLimit(1);
}
return builder;
}
内容来源于网络,如有侵权,请联系作者删除!