本文整理汇总了Java中io.netty.util.Timer类的典型用法代码示例。如果您正苦于以下问题:Java Timer类的具体用法?Java Timer怎么用?Java Timer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Timer类属于io.netty.util包,在下文中一共展示了Timer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Server
import io.netty.util.Timer; //导入依赖的package包/类
Server(
AddressResolver addressResolver,
EventLoopGroup eventLoopGroup,
boolean customEventLoop,
Timer timer,
boolean customTimer,
long bindTimeoutInNanos,
StubStore stubStore,
boolean activityLogging,
ServerBootstrap serverBootstrap) {
// custom constructor onyl made to help facilitate testing with a custom bootstrap.
this.addressResolver = addressResolver;
this.timer = timer;
this.customTimer = customTimer;
this.eventLoopGroup = eventLoopGroup;
this.customEventLoop = customEventLoop;
this.serverBootstrap = serverBootstrap;
this.bindTimeoutInNanos = bindTimeoutInNanos;
this.stubStore = stubStore;
this.activityLogging = activityLogging;
}
示例2: testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided
import io.netty.util.Timer; //导入依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided() throws Exception {
EventLoopGroup eventLoop;
Timer timer = new HashedWheelTimer();
try (Server server = Server.builder().withTimer(timer).build()) {
// Do nothing here, since this is a unit test, we don't want to create any inet sockets
// which is what Server does by default.
eventLoop = server.eventLoopGroup;
}
// event loop should have been closed since a custom one was not provided.
assertThat(eventLoop.isShutdown()).isTrue();
// timer should not have been closed since a custom one was provided.
timer.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
timer.stop();
}
示例3: RedisClient
import io.netty.util.Timer; //导入依赖的package包/类
@Deprecated
public RedisClient(final Timer timer, ExecutorService executor, EventLoopGroup group, Class<? extends SocketChannel> socketChannelClass, String host, int port,
int connectTimeout, int commandTimeout) {
RedisClientConfig config = new RedisClientConfig();
config.setTimer(timer).setExecutor(executor).setGroup(group).setSocketChannelClass(socketChannelClass)
.setAddress(host, port).setConnectTimeout(connectTimeout).setCommandTimeout(commandTimeout);
this.config = config;
this.executor = config.getExecutor();
this.timer = config.getTimer();
addr = new InetSocketAddress(config.getAddress().getHost(), config.getAddress().getPort());
channels = new DefaultChannelGroup(config.getGroup().next());
bootstrap = createBootstrap(config, Type.PLAIN);
pubSubBootstrap = createBootstrap(config, Type.PUBSUB);
this.commandTimeout = config.getCommandTimeout();
}
示例4: OFChannelInitializer
import io.netty.util.Timer; //导入依赖的package包/类
public OFChannelInitializer(IOFSwitchManager switchManager,
INewOFConnectionListener connectionListener,
IDebugCounterService debugCounters,
Timer timer,
List<U32> ofBitmaps,
OFFactory defaultFactory,
String keyStore,
String keyStorePassword) {
super();
this.switchManager = switchManager;
this.connectionListener = connectionListener;
this.timer = timer;
this.debugCounters = debugCounters;
this.defaultFactory = defaultFactory;
this.ofBitmaps = ofBitmaps;
this.keyStore = keyStore;
this.keyStorePassword = keyStorePassword;
}
示例5: OFConnection
import io.netty.util.Timer; //导入依赖的package包/类
public OFConnection(@Nonnull DatapathId dpid,
@Nonnull OFFactory factory,
@Nonnull Channel channel,
@Nonnull OFAuxId auxId,
@Nonnull IDebugCounterService debugCounters,
@Nonnull Timer timer) {
Preconditions.checkNotNull(dpid, "dpid");
Preconditions.checkNotNull(factory, "factory");
Preconditions.checkNotNull(channel, "channel");
Preconditions.checkNotNull(timer, "timer");
Preconditions.checkNotNull(debugCounters);
this.listener = NullConnectionListener.INSTANCE;
this.dpid = dpid;
this.factory = factory;
this.channel = channel;
this.auxId = auxId;
this.connectedSince = new Date();
this.xidDeliverableMap = new ConcurrentHashMap<>();
this.counters = new OFConnectionCounters(debugCounters, dpid, this.auxId);
this.timer = timer;
this.latency = U64.ZERO;
}
示例6: OFChannelHandler
import io.netty.util.Timer; //导入依赖的package包/类
/**
* Creates a handler for interacting with the switch channel
*
* @param controller
* the controller
* @param newConnectionListener
* the class that listens for new OF connections (switchManager)
* @param pipeline
* the channel pipeline
* @param threadPool
* the thread pool
* @param idleTimer
* the hash wheeled timer used to send idle messages (echo).
* passed to constructor to modify in case of aux connection.
* @param debugCounters
*/
OFChannelHandler(@Nonnull IOFSwitchManager switchManager,
@Nonnull INewOFConnectionListener newConnectionListener,
@Nonnull ChannelPipeline pipeline,
@Nonnull IDebugCounterService debugCounters,
@Nonnull Timer timer,
@Nonnull List<U32> ofBitmaps,
@Nonnull OFFactory defaultFactory) {
Preconditions.checkNotNull(switchManager, "switchManager");
Preconditions.checkNotNull(newConnectionListener, "connectionOpenedListener");
Preconditions.checkNotNull(pipeline, "pipeline");
Preconditions.checkNotNull(timer, "timer");
Preconditions.checkNotNull(debugCounters, "debugCounters");
this.pipeline = pipeline;
this.debugCounters = debugCounters;
this.newConnectionListener = newConnectionListener;
this.counters = switchManager.getCounters();
this.state = new InitState();
this.timer = timer;
this.ofBitmaps = ofBitmaps;
this.factory = defaultFactory;
log.debug("constructor on OFChannelHandler {}", String.format("%08x", System.identityHashCode(this)));
}
示例7: createInstance
import io.netty.util.Timer; //导入依赖的package包/类
@Override
public AutoCloseable createInstance() {
// The service is provided via blueprint so wait for and return it here for backwards compatibility.
final WaitingServiceTracker<Timer> tracker = WaitingServiceTracker.create(
Timer.class, bundleContext, "(type=global-timer)");
final Timer timer = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
return Reflection.newProxy(AutoCloseableTimerInterface.class, new AbstractInvocationHandler() {
@Override
protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (method.getName().equals("close")) {
tracker.close();
return null;
} else {
return method.invoke(timer, args);
}
}
});
}
示例8: TimeoutsHolder
import io.netty.util.Timer; //导入依赖的package包/类
public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFuture, NettyRequestSender requestSender, AsyncHttpClientConfig config) {
this.nettyTimer = nettyTimer;
this.nettyResponseFuture = nettyResponseFuture;
this.requestSender = requestSender;
this.readTimeoutValue = config.getReadTimeout();
int requestTimeoutInMs = nettyResponseFuture.getTargetRequest().getRequestTimeout();
if (requestTimeoutInMs == 0) {
requestTimeoutInMs = config.getRequestTimeout();
}
if (requestTimeoutInMs != -1) {
requestTimeoutMillisTime = millisTime() + requestTimeoutInMs;
requestTimeout = newTimeout(new RequestTimeoutTimerTask(nettyResponseFuture, requestSender, this, requestTimeoutInMs), requestTimeoutInMs);
} else {
requestTimeoutMillisTime = -1L;
requestTimeout = null;
}
}
示例9: OFChannelInitializer
import io.netty.util.Timer; //导入依赖的package包/类
public OFChannelInitializer(IOFSwitchManager switchManager,
INewOFConnectionListener connectionListener,
IDebugCounterService debugCounters,
Timer timer,
List<U32> ofBitmaps,
OFFactory defaultFactory,
String keyStore,
String keyStorePassword) {
super();
this.switchManager = switchManager;
this.connectionListener = connectionListener;
this.timer = timer;
this.debugCounters = debugCounters;
this.defaultFactory = defaultFactory;
this.ofBitmaps = ofBitmaps;
this.keyStore = keyStore;
this.keyStorePassword = keyStorePassword;
}
示例10: TimedDeferredRequest
import io.netty.util.Timer; //导入依赖的package包/类
/**
* Intentional private local constructor
* @param key the request key
* @param request the request object
* @param window the window
* @param timeoutMillis the time after which this future will be cancelled
* @param timer the timer used to implement the timeout functionality
*/
private TimedDeferredRequest(final K key,
final R request,
final Window<K, R, D> window,
final Timer timer,
final long timeoutMillis) {
super(key, request, window);
this.timeout = checkNotNull(timer).newTimeout(new TimerTask() {
@Override
public void run(Timeout timerTask) throws Exception {
window.fail(checkNotNull(key),
new TimeoutException("The operation timed out (Window full)"));
}
},
timeoutMillis,
TimeUnit.MILLISECONDS);
}
示例11: BoundNode
import io.netty.util.Timer; //导入依赖的package包/类
BoundNode(
SocketAddress address,
NodeSpec delegate,
Map<String, Object> peerInfo,
BoundCluster cluster,
BoundDataCenter parent,
Server server,
Timer timer,
Channel channel,
boolean activityLogging) {
super(
address,
delegate.getName(),
delegate.getId() != null ? delegate.getId() : 0,
delegate.getCassandraVersion(),
delegate.getDSEVersion(),
peerInfo,
parent);
this.cluster = cluster;
this.server = server;
// for test purposes server may be null.
this.bootstrap = server != null ? server.serverBootstrap : null;
this.timer = timer;
this.channel = new AtomicReference<>(channel);
this.stubStore = new StubStore();
this.activityLogging = activityLogging;
this.frameCodec = buildFrameCodec(delegate).orElse(parent.getFrameCodec());
}
示例12: testTryWithResourcesShouldCloseAllResources
import io.netty.util.Timer; //导入依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllResources() throws Exception {
EventLoopGroup eventLoop;
Timer timer;
try (Server server = Server.builder().build()) {
// Do nothing here, since this is a unit test, we don't want to create any inet sockets
// which is what Server does by default.
eventLoop = server.eventLoopGroup;
timer = server.timer;
}
// event loop should have been closed since a custom one was not provided.
assertThat(eventLoop.isShutdown()).isTrue();
// timer should have since a custom one was not provided.
try {
timer.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
fail("Expected IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
}
示例13: testTryWithResourcesShouldCloseAllClustersButNotEventLoopAndTimerIfProvided
import io.netty.util.Timer; //导入依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllClustersButNotEventLoopAndTimerIfProvided()
throws Exception {
EventLoopGroup eventLoop = new DefaultEventLoopGroup();
Timer timer = new HashedWheelTimer();
BoundCluster cluster;
MockClient client;
try (Server server =
Server.builder()
.withAddressResolver(localAddressResolver)
.withTimer(timer)
.withEventLoopGroup(eventLoop, LocalServerChannel.class)
.build()) {
cluster = server.register(ClusterSpec.builder().withNodes(5));
BoundNode node = cluster.node(0);
SocketAddress address = node.getAddress();
client = new MockClient(eventLoop);
client.connect(address);
}
// event loop should not have been closed.
assertThat(eventLoop.isShutdown()).isFalse();
// timer should not have since a custom one was not provided.
cluster
.getServer()
.timer
.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
eventLoop.shutdownGracefully(0, 0, TimeUnit.SECONDS);
timer.stop();
}
示例14: ConnectionWatcher
import io.netty.util.Timer; //导入依赖的package包/类
public ConnectionWatcher(Bootstrap bootstrap, Timer timer, String host, int port, boolean reconnect){
this.bootstrap = bootstrap;
this.timer = timer;
this.host = host;
this.port = port;
this.reconnect = reconnect;
}
示例15: HandshakeTimeoutHandler
import io.netty.util.Timer; //导入依赖的package包/类
public HandshakeTimeoutHandler(RPCChannelHandler handler,
Timer timer,
long timeoutSeconds) {
super();
this.handler = handler;
this.timer = timer;
this.timeoutNanos = TimeUnit.SECONDS.toNanos(timeoutSeconds);
}