本文整理汇总了Java中com.twitter.util.Duration类的典型用法代码示例。如果您正苦于以下问题:Java Duration类的具体用法?Java Duration怎么用?Java Duration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Duration类属于com.twitter.util包,在下文中一共展示了Duration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startAdminHttpService
import com.twitter.util.Duration; //导入依赖的package包/类
public void startAdminHttpService() {
try {
Properties properties = new Properties();
properties.load(this.getClass().getResource("build.properties").openStream());
LOG.info("build.properties build_revision: {}",
properties.getProperty("build_revision", "unknown"));
} catch (Throwable t) {
LOG.warn("Failed to load properties from build.properties", t);
}
Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
Iterator<Duration> durationIterator = Arrays.asList(defaultLatchIntervals).iterator();
@SuppressWarnings("deprecation")
AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
this.port,
20,
List$.MODULE$.empty(),
Option.empty(),
List$.MODULE$.empty(),
Map$.MODULE$.empty(),
JavaConversions.asScalaIterator(durationIterator).toList());
RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
for (Map.Entry<String, CustomHttpHandler> entry : this.customHttpHandlerMap.entrySet()) {
service.httpServer().createContext(entry.getKey(), entry.getValue());
}
}
示例2: makeMemcachedClient
import com.twitter.util.Duration; //导入依赖的package包/类
/**
* Constructs a finagle java memcached client for the list of endpoints..
*
* @param endpoints list of {@code InetSocketAddress} for all the memcached servers.
* @return {@link Client} to read/write to the hash ring of the servers..
*/
static Client makeMemcachedClient(Options opts, List<InetSocketAddress> endpoints)
throws UnknownHostException {
com.twitter.finagle.memcached.Client client =
KetamaClientBuilder.get()
.nodes(getHostPortWeightTuples(endpoints))
.clientBuilder(ClientBuilder.get()
.codec(new Memcached())
.tcpConnectTimeout(new Duration(TimeUnit.MILLISECONDS.toNanos(opts.connectTimeoutMillis)))
.requestTimeout(new Duration(TimeUnit.MILLISECONDS.toNanos(opts.requestTimeoutMillis)))
.timeout(new Duration(TimeUnit.MILLISECONDS.toNanos(opts.e2eTimeoutMillis)))
.hostConnectionLimit(opts.hostConnectionLimit)
.hostConnectionMaxWaiters(opts.maxWaiters)
.retries(opts.requestRetries))
.build();
return new ClientBase(client);
}
示例3: flushesIncompleteSpans
import com.twitter.util.Duration; //导入依赖的package包/类
@Test public void flushesIncompleteSpans() throws Exception {
advanceAndRecord(0, root, new Annotation.Rpc("GET"));
advanceAndRecord(15, root, new Annotation.ServiceName("frontend"));
advanceAndRecord(0, root, new Annotation.ServerRecv());
// Note: there's no ServerSend() which would complete the span.
time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer
timer.tick(); // invokes a flush
Span span = spansSent.take();
assertThat(span.idString()).isEqualTo(root.toString());
assertThat(span.name).isEqualTo("get");
assertThat(span.annotations).extracting(a -> a.value).containsExactly(
"sr", "finagle.flush"
);
assertThat(span.duration).isNull();
}
示例4: testBuildClientsFromSameBuilder
import com.twitter.util.Duration; //导入依赖的package包/类
@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);
}
示例5: testChecksumFlag
import com.twitter.util.Duration; //导入依赖的package包/类
/**
* Sanity check to make sure both checksum flag values work.
*/
@Test(timeout = 60000)
public void testChecksumFlag() throws Exception {
String name = "dlserver-basic-write";
LocalRoutingService routingService = LocalRoutingService.newBuilder().build();
routingService.addHost(name, dlServer.getAddress());
DistributedLogClientBuilder dlClientBuilder = DistributedLogClientBuilder.newBuilder()
.name(name)
.clientId(ClientId$.MODULE$.apply("test"))
.routingService(routingService)
.handshakeWithClientInfo(true)
.clientBuilder(ClientBuilder.get()
.hostConnectionLimit(1)
.connectionTimeout(Duration.fromSeconds(1))
.requestTimeout(Duration.fromSeconds(60)))
.checksum(false);
DistributedLogClient dlClient = (DistributedLogClientImpl) dlClientBuilder.build();
Await.result(dlClient.write(name, ByteBuffer.wrap(("1").getBytes())));
dlClient.close();
dlClient = dlClientBuilder.checksum(true).build();
Await.result(dlClient.write(name, ByteBuffer.wrap(("2").getBytes())));
dlClient.close();
}
示例6: testBulkWriteEmptyBuffer
import com.twitter.util.Duration; //导入依赖的package包/类
@Test(timeout = 60000)
public void testBulkWriteEmptyBuffer() throws Exception {
String name = String.format("dlserver-bulk-write-%s", "empty");
dlClient.routingService.addHost(name, dlServer.getAddress());
List<ByteBuffer> writes = new ArrayList<ByteBuffer>();
writes.add(ByteBuffer.wrap(("").getBytes()));
writes.add(ByteBuffer.wrap(("").getBytes()));
List<Future<DLSN>> futures = dlClient.dlClient.writeBulk(name, writes);
assertEquals(2, futures.size());
for (Future<DLSN> future : futures) {
// No throw == pass
DLSN dlsn = Await.result(future, Duration.fromSeconds(10));
}
}
示例7: TwoRegionDLClient
import com.twitter.util.Duration; //导入依赖的package包/类
protected TwoRegionDLClient(String name, Map<SocketAddress, String> regionMap) {
localRoutingService = new LocalRoutingService();
remoteRoutingService = new LocalRoutingService();
RegionsRoutingService regionsRoutingService =
RegionsRoutingService.of(new DefaultRegionResolver(regionMap),
localRoutingService, remoteRoutingService);
dlClientBuilder = DistributedLogClientBuilder.newBuilder()
.name(name)
.clientId(ClientId$.MODULE$.apply(name))
.routingService(regionsRoutingService)
.streamNameRegex(".*")
.handshakeWithClientInfo(true)
.maxRedirects(2)
.clientBuilder(ClientBuilder.get()
.hostConnectionLimit(1)
.connectionTimeout(Duration.fromSeconds(1))
.requestTimeout(Duration.fromSeconds(10)));
dlClient = (DistributedLogClientImpl) dlClientBuilder.build();
}
示例8: start
import com.twitter.util.Duration; //导入依赖的package包/类
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(),
List.<Duration>fromArray(defaultLatchIntervals));
RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
AdminHttpService service = adminServiceFactory.apply(runtimeEnvironment);
for (Map.Entry<String, CustomHttpHandler> entry : this.mCustomHttpHandlerMap.entrySet()) {
service.httpServer().createContext(entry.getKey(), entry.getValue());
}
}
示例9: requestComplete
import com.twitter.util.Duration; //导入依赖的package包/类
/**
* Call this when each request completes.
*
* @param latency Latency for that request.
*/
public synchronized void requestComplete(Duration latency) {
queriesIssued++;
totalLatencyMicros += latency.inMicroseconds();
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis >= lastLogTimestampMillis + logIntervalSeconds * 1000) {
long qps = queriesIssued * 1000 / (currentTimeMillis - lastLogTimestampMillis);
double avgLatencyMillis = totalLatencyMicros / (queriesIssued * 1000.0);
LOG.info(String.format("QPS: %d Avg Latency (ms): %.5f", qps, avgLatencyMillis));
queriesIssued = 0;
totalLatencyMicros = 0;
lastLogTimestampMillis = currentTimeMillis;
}
}
示例10: startThriftServer
import com.twitter.util.Duration; //导入依赖的package包/类
private void startThriftServer(int thriftPort) throws UnknownHostException {
TerrapinController.ServiceIface serviceImpl = new TerrapinControllerServiceImpl(
this.configuration,
this.zkManager,
this.hdfsClient,
this.helixAdmin,
this.clusterName);
TerrapinController.Service service =
new TerrapinController.Service(serviceImpl, new TBinaryProtocol.Factory());
this.server = ServerBuilder.safeBuild(
service,
ServerBuilder.get()
.name("TerrapinController")
.codec(ThriftServerFramedCodec.get())
.hostConnectionMaxIdleTime(Duration.fromTimeUnit(
configuration.getInt(Constants.THRIFT_CONN_MAX_IDLE_TIME, 1), TimeUnit.MINUTES))
.maxConcurrentRequests(configuration.getInt(Constants.THRIFT_MAX_CONCURRENT_REQUESTS,
100))
.reportTo(new OstrichStatsReceiver(Stats.get("")))
.bindTo(new InetSocketAddress(thriftPort)));
new OstrichAdminService(configuration.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();
}
示例11: main
import com.twitter.util.Duration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final PropertiesConfiguration config = TerrapinUtil.readPropertiesExitOnFailure(
System.getProperties().getProperty("terrapin.config", "thrift.properties"));
OstrichStatsReceiver statsReceiver = new OstrichStatsReceiver(Stats.get(""));
int listenPort = config.getInt("thrift_port", 9090);
TerrapinServiceImpl serviceImpl = new TerrapinServiceImpl(config,
(List) config.getList("cluster_list"));
Service<byte[], byte[]> service = new TerrapinService.Service(serviceImpl,
new TBinaryProtocol.Factory());
Server server = ServerBuilder.safeBuild(
service,
ServerBuilder.get()
.name("TERRAPIN_THRIFT")
.codec(ThriftServerFramedCodec.get())
.hostConnectionMaxIdleTime(Duration.apply(1, TimeUnit.MINUTES))
.maxConcurrentRequests(3000)
.reportTo(statsReceiver)
.bindTo(new InetSocketAddress(listenPort)));
new OstrichAdminService(config.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();
LOG.info("\n#######################################"
+ "\n# Ready To Serve Requests. #"
+ "\n#######################################");
}
示例12: testGetEmptyClusters
import com.twitter.util.Duration; //导入依赖的package包/类
@Test
public void testGetEmptyClusters() {
ByteBuffer key = ByteBuffer.wrap(KEY);
TerrapinGetRequest request = prepareGetRequest();
RequestOptions options = new RequestOptions();
options.setSelectionPolicy(SelectionPolicy.PRIMARY_FIRST);
request.setOptions(options);
request.setClusterList(ImmutableList.copyOf(new String[]{}));
TerrapinResponse response = new TerrapinResponse().setResponseMap(ImmutableMap.of(
key, new TerrapinSingleResponse().setValue(ByteBuffer.wrap("value".getBytes()))));
when(mockClient1.getMany(eq(FILESET), eq(Sets.newHashSet(key)))).thenReturn(
Future.value(response));
when(mockClient2.getManyNoRetries(eq(FILESET), eq(Sets.newHashSet(key)))).thenReturn(
Future.value(response));
Try<TerrapinSingleResponse> singleResponseTry = serviceIface.get(request).get(Duration.forever());
assertTrue(singleResponseTry.isThrow());
assertEquals(TerrapinGetErrorCode.INVALID_REQUEST,
((TerrapinGetException)((Throw)singleResponseTry).e()).getErrorCode());
}
示例13: testMultiGetEmptyClusters
import com.twitter.util.Duration; //导入依赖的package包/类
@Test
public void testMultiGetEmptyClusters() {
TerrapinMultiGetRequest request = prepareMultiGetRequest();
RequestOptions options = new RequestOptions();
options.setSelectionPolicy(SelectionPolicy.PRIMARY_FIRST);
request.setOptions(options);
request.setClusterList(ImmutableList.copyOf(new String[]{}));
TerrapinResponse response = new TerrapinResponse().setResponseMap(ImmutableMap.of(
ByteBuffer.wrap("key1".getBytes()),
new TerrapinSingleResponse().setValue("value1".getBytes()),
ByteBuffer.wrap("key2".getBytes()),
new TerrapinSingleResponse().setErrorCode(TerrapinGetErrorCode.READ_ERROR)));
Set<ByteBuffer> keys = Sets.newHashSet(ByteBuffer.wrap("key1".getBytes()),
ByteBuffer.wrap("key2".getBytes()),
ByteBuffer.wrap("key3".getBytes()));
when(mockClient1.getMany(eq(FILESET), eq(keys))).thenReturn(Future.value(response));
when(mockClient2.getManyNoRetries(eq(FILESET), eq(keys))).thenReturn(Future.value(response));
Try<TerrapinResponse> returnResponseTry = serviceIface.multiGet(request).get(Duration.forever());
assertTrue(returnResponseTry.isThrow());
assertEquals(TerrapinGetErrorCode.INVALID_REQUEST,
((TerrapinGetException)((Throw)returnResponseTry).e()).getErrorCode());
}
示例14: testMultiGetError
import com.twitter.util.Duration; //导入依赖的package包/类
@Test
public void testMultiGetError() {
TerrapinMultiGetRequest request = prepareMultiGetRequest();
Set<ByteBuffer> keys = Sets.newHashSet(ByteBuffer.wrap("key1".getBytes()),
ByteBuffer.wrap("key2".getBytes()),
ByteBuffer.wrap("key3".getBytes()));
when (mockClient1.getMany(eq(FILESET), eq(keys))).thenReturn(
Future.<TerrapinResponse>exception(new TerrapinGetException("Failed",
TerrapinGetErrorCode.FILE_SET_NOT_FOUND)));
Try<TerrapinResponse> responseTry = serviceIface.multiGet(request).get(Duration.forever());
assertTrue(responseTry.isThrow());
assertEquals(TerrapinGetErrorCode.FILE_SET_NOT_FOUND,
((TerrapinGetException)((Throw)responseTry).e()).getErrorCode());
when(mockClient1.getMany(eq(FILESET), eq(keys))).thenThrow(
new RuntimeException(new NullPointerException()));
responseTry = serviceIface.multiGet(request).get(Duration.forever());
assertTrue(responseTry.isThrow());
assertEquals(TerrapinGetErrorCode.OTHER,
((TerrapinGetException)((Throw)responseTry).e()).getErrorCode());
}
示例15: startThriftServer
import com.twitter.util.Duration; //导入依赖的package包/类
private void startThriftServer(int thriftPort) {
TerrapinServerInternal.ServiceIface serviceImpl = new TerrapinServerInternalImpl(configuration,
resourcePartitionMap);
TerrapinServerInternal.Service service =
new TerrapinServerInternal.Service(serviceImpl, new TBinaryProtocol.Factory());
this.server = ServerBuilder.safeBuild(
service,
ServerBuilder.get()
.name("TerrapinServer")
.codec(ThriftServerFramedCodec.get())
.hostConnectionMaxIdleTime(Duration.fromTimeUnit(
configuration.getInt(Constants.THRIFT_CONN_MAX_IDLE_TIME, 1), TimeUnit.MINUTES))
.maxConcurrentRequests(configuration.getInt(Constants.THRIFT_MAX_CONCURRENT_REQUESTS,
100))
.reportTo(new OstrichStatsReceiver(Stats.get("")))
.bindTo(new InetSocketAddress(thriftPort)));
new OstrichAdminService(configuration.getInt(Constants.OSTRICH_METRICS_PORT, 9999)).start();
}