本文整理汇总了Java中com.twitter.common.quantity.Time类的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Time类属于com.twitter.common.quantity包,在下文中一共展示了Time类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: apply
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Override
public TServer apply(ServerSetup setup) throws TTransportException {
TNonblockingServerSocket socket = setup.getSocketTimeout() == null
? new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", setup.getPort()))
: new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", setup.getPort()),
setup.getSocketTimeout().as(Time.MILLISECONDS));
setup.setSocket(getServerSocketFor(socket));
THsHaServer.Args options = new THsHaServer.Args(socket);
options.processor(setup.getProcessor());
if (setup.getNumThreads() > 0) {
options.workerThreads(setup.getNumThreads());
}
// default queue size to num threads: max response time becomes double avg service time
final BlockingQueue<Runnable> queue =
new ArrayBlockingQueue<Runnable>(setup.getQueueSize() > 0 ? setup.getQueueSize()
: options.getWorkerThreads());
final ThreadPoolExecutor invoker = new ThreadPoolExecutor(options.getWorkerThreads(),
options.getWorkerThreads(), options.getStopTimeoutVal(), options.getStopTimeoutUnit(), queue);
final String serverName = (setup.getName() != null ? setup.getName() : "no-name");
return new THsHaServer(options);
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:25,代码来源:ThriftServer.java
示例2: invoke
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* Convenience method for invoking the method and shunting the capture into the callback if
* the call is asynchronous.
*
* @param method The method being invoked.
* @param args The arguments to call {@code method} with.
* @param callback The callback to use if the method is asynchronous.
* @param capture The result capture to notify of the call result.
* @param connectTimeoutOverride Optional override for the default connection timeout.
* @return The return value from invoking the method.
* @throws Throwable Exception, as prescribed by the method's contract.
*/
protected final Object invoke(Method method, Object[] args,
AsyncMethodCallback callback, final ResultCapture capture,
Amount<Long, Time> connectTimeoutOverride) throws Throwable {
// Swap the wrapped callback out for ours.
if (callback != null) {
callback = new WrappedMethodCallback(callback, capture);
}
try {
Object result = decoratedCaller.call(method, args, callback, connectTimeoutOverride);
if (callback == null && capture != null) capture.success();
return result;
} catch (Throwable t) {
// We allow this one to go to both sync and async captures.
if (callback != null) {
callback.onError((Exception)t);
return null;
} else {
if (capture != null) capture.fail(t);
throw t;
}
}
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:37,代码来源:CallerDecorator.java
示例3: getIfaceThrift
import com.twitter.common.quantity.Time; //导入依赖的package包/类
protected Thrift<HelloClient> getIfaceThrift(DynamicHostSet backends) {
Config thriftConfig = Config.builder()
.withRequestTimeout(Amount.of(0L, Time.SECONDS))
.withRetries(3)
.disableStats()
.withDebug(true)
.retryOn(ImmutableSet.<Class<? extends Exception>>builder()
.add(ThriftException.class)
.add(IOException.class)
.add(ConnectFailedException.class)
.add(TTimeoutException.class)
.add(ResourceExhaustedException.class)
.add(TTransportException.class).build())
.create();
try {
return ThriftFactory.create(HelloClient.class)
.useFramedTransport(true)
.withMaxConnectionsPerEndpoint(5)
.withThriftConfig(thriftConfig)
.build(backends);
} catch (Exception e) {
return null;
}
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:25,代码来源:BaseThriftTest.java
示例4: testTwoServer
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Test
public void testTwoServer() throws TException, InterruptedException {
ThriftServer server1 = mockServer(7911).awaitForAlive();
ThriftServer server2 = mockServer(7912).awaitForAlive();
Thrift<HelloClient> thrift = getIfaceThrift();
Hello.Iface iface = thrift.create();
ConcurrentMap<String, AtomicLong> hits = Maps.newConcurrentMap();
for (int i = 0; i < 10; i++) {
String port = iface.hi();
assertNotNull(port);
hits.putIfAbsent(port, new AtomicLong(0));
hits.get(port).incrementAndGet();
}
assertHit(hits, "7911");
assertHit(hits, "7912");
server1.awaitShutdown(Amount.of(5L, Time.SECONDS));
server2.awaitShutdown(Amount.of(5L, Time.SECONDS));
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:19,代码来源:SimpleThriftTest.java
示例5: of
import com.twitter.common.quantity.Time; //导入依赖的package包/类
public static DLZkServerSet of(URI uri,
int zkSessionTimeoutMs) {
// Create zookeeper and server set
String zkPath = uri.getPath() + "/" + ZNODE_WRITE_PROXY;
Iterable<InetSocketAddress> zkAddresses = getZkAddresses(uri);
ZooKeeperClient zkClient =
new ZooKeeperClient(Amount.of(zkSessionTimeoutMs, Time.MILLISECONDS), zkAddresses);
ServerSet serverSet = ServerSets.create(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, zkPath);
return new DLZkServerSet(zkClient, serverSet);
}
开发者ID:twitter,项目名称:distributedlog,代码行数:11,代码来源:DLZkServerSet.java
示例6: getClient
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* Return Thrift service client interface.
*
* @return OperationsThriftService.Iface
*/
public OperationsThriftService.Iface getClient() {
return thrift.builder()
.disableStats()
.withRequestTimeout(Amount.of(socketTimeout, Time.SECONDS))
.create();
}
开发者ID:kaaproject,项目名称:kaa,代码行数:12,代码来源:NeighborConnection.java
示例7: start
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* Start neighbor connection if it not started yet.
*/
public synchronized void start() {
if (!started) {
executor = Executors.newFixedThreadPool(maxNumberConnection);
messageQueue = new LinkedBlockingQueue<>(messageQueueLength);
workers = new LinkedList<>();
clientFactory = ThriftFactory.create(OperationsThriftService.Iface.class);
InetSocketAddress address = new InetSocketAddress(
connectionInfo.getThriftHost().toString(), connectionInfo.getThriftPort()
);
Set<InetSocketAddress> backends = new HashSet<>();
backends.add(address);
thrift = clientFactory.withMaxConnectionsPerEndpoint(maxNumberConnection)
.withSocketTimeout(Amount.of(socketTimeout, Time.SECONDS))
.withClientFactory(new Function<TTransport, OperationsThriftService.Iface>() {
@Override
public Iface apply(TTransport transport) {
TProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol mprotocol = new TMultiplexedProtocol(
protocol, KaaThriftService.OPERATIONS_SERVICE.getServiceName()
);
return new OperationsThriftService.Client(mprotocol);
}
}).build(backends);
for (int i = 0; i < maxNumberConnection; i++) {
EventWorker worker = new EventWorker(template);
workers.add(executor.submit(worker));
}
started = true;
} else {
LOG.debug("Neighbor Connection {} is already started", getId());
}
}
开发者ID:kaaproject,项目名称:kaa,代码行数:36,代码来源:NeighborConnection.java
示例8: create
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* create a client to a single endpoint
*
* @param endpoint
* @return
*/
public T create(HostAndPort endpoint, Amount<Long, Time> requestTimeout) {
T client = clientBuffer.get(endpoint);
if (client == null) {
synchronized (Thrift.class) {
client = clientBuffer.get(endpoint);
if (client == null) {
SingleBackend<HostAndPort> singleBackend = new SingleBackend<>(endpoint);
client = createClient(singleBackend, defaultConfig, null, requestTimeout);
clientBuffer.put(endpoint, client);
}
}
}
return client;
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:21,代码来源:Thrift.java
示例9: createClient
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* create a thrift client for calling
*
* @param loadBalancer
* @param config
* @param collectionCallback, collection callback, will apply this callback when get a collection from pool success.
* @return
*/
private T createClient(LoadBalancer<HostAndPort> loadBalancer, Config config, Closure<ThriftConnection<T>> collectionCallback,Amount<Long, Time> requestTimeout) {
// lease/call/[invalidate]/release
boolean debug = config.isDebug();
Caller decorated = new ThriftCaller<>(connectionPool, loadBalancer, clientFactory, collectionCallback);
// [retry]
if (config.getMaxRetries() > 0) {
decorated = new RetryingCaller(decorated, config.getMaxRetries(), config.getRetryableExceptions(), debug);
}
// [deadline]
if (requestTimeout!=null && requestTimeout.getValue() > 0) {
decorated = new DeadlineCaller(decorated, executorService, requestTimeout);
}
final Caller caller = decorated;
final MethodInterceptor invocationHandler = new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
AsyncMethodCallback callback = null;
return caller.call(method, args, callback, null);
}
};
return (T) Enhancer.create(serviceInterface, invocationHandler);
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:36,代码来源:Thrift.java
示例10: build
import com.twitter.common.quantity.Time; //导入依赖的package包/类
public Thrift<T> build(DynamicHostSet hostSets) {
checkBaseState();
Preconditions.checkNotNull(hostSets);
ThriftPoolConfig cfg = new ThriftPoolConfig();
cfg.put("thrift.pool.transport.framed",String.valueOf(framedTransport));
cfg.put("thrift.pool.maxTotalPerKey", String.valueOf(maxConnectionsPerEndpoint));
cfg.put("thrift.pool.transport.socket_timeout", String.valueOf(thriftConfig.getSocketTimeout().as(Time.MILLISECONDS)));
ThriftConnectionPool<T> pool = new ThriftConnectionPool(serviceInterface, cfg);
ExecutorService executorService = createManagedThreadpool();
Function<TTransport, T> clientFactory = createClientFactory(serviceInterface);
LoadBalancer<HostAndPort> loadBalancer = createLoadBalancer(hostSets);
return new Thrift<>(thriftConfig, executorService, pool, serviceName,
serviceInterface, clientFactory,loadBalancer);
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:15,代码来源:ThriftFactory.java
示例11: awaitShutdown
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* Attempts to shut down this server, and waits for the shutdown operation to complete.
*
* @param timeout Maximum amount of time to wait for shutdown before giving up. a timeout of
* zero means wait forever.
* @throws InterruptedException If interrupted while waiting for shutdown.
*/
public void awaitShutdown(Amount<Long, Time> timeout) throws InterruptedException {
Preconditions.checkNotNull(timeout);
shutdown();
if (listeningThread != null) {
listeningThread.join(timeout.as(Time.MILLISECONDS));
}
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:16,代码来源:ThriftServer.java
示例12: ServerSetup
import com.twitter.common.quantity.Time; //导入依赖的package包/类
public ServerSetup(String name, int port, TProcessor processor, TProtocolFactory protoFactory,
int numThreads, int queueSize, Amount<Integer, Time> socketTimeout) {
Preconditions.checkArgument(port >= 0 && port < 0xFFFF, "Invalid port: " + port);
Preconditions.checkArgument(numThreads != 0);
Preconditions.checkArgument(queueSize != 0);
if (socketTimeout != null) Preconditions.checkArgument(socketTimeout.getValue() >= 0);
this.name = name;
this.port = port;
this.processor = processor;
this.protoFactory = protoFactory;
this.numThreads = numThreads;
this.queueSize = queueSize;
this.socketTimeout = socketTimeout;
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:15,代码来源:ThriftServer.java
示例13: withRequestTimeout
import com.twitter.common.quantity.Time; //导入依赖的package包/类
/**
* Specifies that all calls be subject to a global timeout. This deadline includes all call
* activities, including obtaining a free connection and any automatic retries.
*/
public final T withRequestTimeout(Amount<Long, Time> timeout) {
Preconditions.checkNotNull(timeout);
Preconditions.checkArgument(timeout.getValue() >= 0,
"A negative deadline is invalid: %s", timeout);
config.requestTimeout = timeout;
return getThis();
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:12,代码来源:Config.java
示例14: call
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Override
public Object call(final Method method, final Object[] args,
final AsyncMethodCallback callback,
final Amount<Long, Time> connectTimeoutOverride) throws Throwable {
AtomicInteger attempts = new AtomicInteger();
Throwable exception = null;
boolean continueLoop;
try {
do {
try {
// If this is an async call, the looping will be handled within the capture.
return invoke(method, args, callback, null, connectTimeoutOverride);
} catch (Throwable t) {
exception = t;
if (!isRetryable(t)) {
if (debug) {
LOG.debug(String.format(
"Call failed with un-retryable exception of [%s]: %s, previous exceptions: %s",
t.getClass().getName(), t.getMessage(), t.getLocalizedMessage()));
}
throw t;
}
}
continueLoop = attempts.incrementAndGet() <= retries;
} while (continueLoop);
}finally {
// some exception found and retry fail
if (exception!=null) {
if(debug) {
LOG.debug(
String.format("Retried %d times, last error: %s",
attempts.get(), exception));
}
}
}
throw exception;
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:39,代码来源:RetryingCaller.java
示例15: testSingleCall
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Test
public void testSingleCall() throws TException, InterruptedException {
ThriftServer server = mockServer(7911);
server.awaitForAlive();
Thrift<HelloClient> thrift = getIfaceThrift();
thrift.create().hi();
server.awaitShutdown(Amount.of(5L, Time.SECONDS));
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:9,代码来源:SimpleThriftTest.java
示例16: testOneServer
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Test
public void testOneServer() throws TException, InterruptedException {
ThriftServer server = mockServer(7911);
server.awaitForAlive();
Thrift<HelloClient> thrift = getIfaceThrift();
Hello.Iface iface = thrift.create();
for (int i = 0; i < 10; i++) {
iface.hi();
}
server.awaitShutdown(Amount.of(5L, Time.SECONDS));
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:12,代码来源:SimpleThriftTest.java
示例17: testOneServerAndAllCall
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Test
public void testOneServerAndAllCall() throws TException, InterruptedException {
ThriftServer server2 = mockServer(7912).awaitForAlive();
Thrift<HelloClient> thrift = getIfaceThrift();
// random call should success
thrift.create().hi();
server2.awaitShutdown(Amount.of(5L, Time.SECONDS));
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:9,代码来源:SimpleThriftSingleTest.java
示例18: testOneServerAndSingleCall
import com.twitter.common.quantity.Time; //导入依赖的package包/类
@Test(expected = ThriftException.class)
public void testOneServerAndSingleCall() throws TException, InterruptedException {
ThriftServer server2 = mockServer(7912).awaitForAlive();
try {
Thrift<HelloClient> thrift = getIfaceThrift();
// random call should success
thrift.create(HostAndPort.fromParts("localhost", 7911)).hi();
}finally {
server2.awaitShutdown(Amount.of(5L, Time.SECONDS));
}
}
开发者ID:houdejun214,项目名称:lakeside-java,代码行数:12,代码来源:SimpleThriftSingleTest.java
示例19: getZooKeeperClient
import com.twitter.common.quantity.Time; //导入依赖的package包/类
public static ZooKeeperClient getZooKeeperClient(String zkQuorum, int sessionTimeoutSeconds)
throws UnknownHostException {
return new ZooKeeperClient(Amount.of(sessionTimeoutSeconds, Time.SECONDS),
getSocketAddressList(zkQuorum));
}
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:6,代码来源:TerrapinUtil.java
示例20: GeneratorMasterZk
import com.twitter.common.quantity.Time; //导入依赖的package包/类
public GeneratorMasterZk() {
redisCache = new RedisCache("localhost", 7000);
String propertiesPath = "/videogenmaster.properties";
PropertyPlaceholder propsHolder = new PropertyPlaceholder(propertiesPath);
propsHolder.generatePropertyMap();
Map<String, String> props = propsHolder.getPropertyMap();
videoCacheUpdatePool = Executors.newFixedThreadPool(Integer.parseInt(props.get("maxThreads")));
videoCacheUpdateTimer = new Timer();
/*videoCacheUpdateTimer.schedule(new VideoCache(videoCacheUpdatePool, propsHolder, client),
5000, 5000);*/
stats = new Statistics();
InetSocketAddress zkServer = new InetSocketAddress("localhost", 2181);
ZooKeeperClient zkClient = new ZooKeeperClient(Amount.of(5, Time.SECONDS), zkServer);
ServerSetImpl serverSet = new ServerSetImpl(zkClient, "/videogen/slave");
ZookeeperServerSetCluster cluster = new ZookeeperServerSetCluster(serverSet);
RetryPolicy<Try<Nothing$>> retryPolicy = new SimpleRetryPolicy<Try<Nothing$>>() {
@Override
public Duration backoffAt(int retryCount) {
if (retryCount > 3) {
return Duration.fromSeconds(16);
}
return Duration.fromSeconds((int) Math.pow(2.0, retryCount));
}
@Override
public boolean shouldRetry(Try<Nothing$> arg) {
return true;
}
};
ClientBuilder clientBuilder = ClientBuilder.get()
.codec(com.twitter.finagle.http.Http.get())
.retryPolicy(retryPolicy) // Retry forever, with exponential backoff <= 16
.hostConnectionLimit(500)
//.hosts("localhost:" + SLAVE_PORT);
.cluster(cluster);
client = ClientBuilder.safeBuild(clientBuilder);
// client = Http.newService("localhost:8001");
}
开发者ID:eternalthinker,项目名称:finagle-java-example-master-slave,代码行数:45,代码来源:GeneratorMasterZk.java
注:本文中的com.twitter.common.quantity.Time类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论