本文整理了Java中org.jboss.netty.util.Timer.newTimeout()
方法的一些代码示例,展示了Timer.newTimeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timer.newTimeout()
方法的具体详情如下:
包路径:org.jboss.netty.util.Timer
类名称:Timer
方法名:newTimeout
[英]Schedules the specified TimerTask for one-time execution after the specified delay.
[中]将指定的TimerTask安排为在指定延迟后一次性执行。
代码示例来源:origin: io.netty/netty
/**
* Start the monitoring process.
*/
public void start() {
if (monitorActive) {
return;
}
lastTime.set(milliSecondFromNano());
// if executor is null, it means it is piloted by a GlobalChannelTrafficCounter, so no executor
if (checkInterval.get() > 0 && timer != null) {
monitorActive = true;
timerTask = new TrafficMonitoringTask(trafficShapingHandler, this);
timeout =
timer.newTimeout(timerTask, checkInterval.get(), TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
/**
* Start the monitoring process.
*/
@Override
public synchronized void start() {
if (monitorActive) {
return;
}
lastTime.set(milliSecondFromNano());
long localCheckInterval = checkInterval.get();
if (localCheckInterval > 0) {
monitorActive = true;
timerTask =
new MixedTrafficMonitoringTask(
(GlobalChannelTrafficShapingHandler) trafficShapingHandler, this);
timeout = timer.newTimeout(timerTask, checkInterval.get(), TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
private void initialize(ChannelHandlerContext ctx) {
State state = state(ctx);
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
synchronized (state) {
switch (state.state) {
case 1:
case 2:
return;
}
state.state = 1;
}
state.lastReadTime = state.lastWriteTime = System.currentTimeMillis();
if (readerIdleTimeMillis > 0) {
state.readerIdleTimeout = timer.newTimeout(
new ReaderIdleTimeoutTask(ctx),
readerIdleTimeMillis, TimeUnit.MILLISECONDS);
}
if (writerIdleTimeMillis > 0) {
state.writerIdleTimeout = timer.newTimeout(
new WriterIdleTimeoutTask(ctx),
writerIdleTimeMillis, TimeUnit.MILLISECONDS);
}
if (allIdleTimeMillis > 0) {
state.allIdleTimeout = timer.newTimeout(
new AllIdleTimeoutTask(ctx),
allIdleTimeMillis, TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (!counter.monitorActive) {
return;
}
counter.resetAccounting(milliSecondFromNano());
if (trafficShapingHandler1 != null) {
trafficShapingHandler1.doAccounting(counter);
}
counter.timer.newTimeout(this, counter.checkInterval.get(), TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
return;
}
State state = (State) ctx.getAttachment();
long currentTime = System.currentTimeMillis();
long lastReadTime = state.lastReadTime;
long nextDelay = readerIdleTimeMillis - (currentTime - lastReadTime);
if (nextDelay <= 0) {
// Reader is idle - set a new timeout and notify the callback.
state.readerIdleTimeout =
timer.newTimeout(this, readerIdleTimeMillis, TimeUnit.MILLISECONDS);
fireChannelIdle(ctx, IdleState.READER_IDLE, lastReadTime);
} else {
// Read occurred before the timeout - set a new timeout with shorter delay.
state.readerIdleTimeout =
timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
}
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
return;
}
State state = (State) ctx.getAttachment();
long currentTime = System.currentTimeMillis();
long lastIoTime = Math.max(state.lastReadTime, state.lastWriteTime);
long nextDelay = allIdleTimeMillis - (currentTime - lastIoTime);
if (nextDelay <= 0) {
// Both reader and writer are idle - set a new timeout and
// notify the callback.
state.allIdleTimeout =
timer.newTimeout(this, allIdleTimeMillis, TimeUnit.MILLISECONDS);
fireChannelIdle(ctx, IdleState.ALL_IDLE, lastIoTime);
} else {
// Either read or write occurred before the timeout - set a new
// timeout with shorter delay.
state.allIdleTimeout =
timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
}
}
}
代码示例来源:origin: io.netty/netty
private void initialize(ChannelHandlerContext ctx) {
State state = state(ctx);
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
synchronized (state) {
switch (state.state) {
case 1:
case 2:
return;
}
state.state = 1;
}
if (timeoutMillis > 0) {
state.timeout = timer.newTimeout(new ReadTimeoutTask(ctx), timeoutMillis, TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
return;
}
State state = (State) ctx.getAttachment();
long currentTime = System.currentTimeMillis();
long lastWriteTime = state.lastWriteTime;
long nextDelay = writerIdleTimeMillis - (currentTime - lastWriteTime);
if (nextDelay <= 0) {
// Writer is idle - set a new timeout and notify the callback.
state.writerIdleTimeout =
timer.newTimeout(this, writerIdleTimeMillis, TimeUnit.MILLISECONDS);
fireChannelIdle(ctx, IdleState.WRITER_IDLE, lastWriteTime);
} else {
// Write occurred before the timeout - set a new timeout with shorter delay.
state.writerIdleTimeout =
timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
}
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (!counter.monitorActive) {
return;
}
long newLastTime = milliSecondFromNano();
counter.resetAccounting(newLastTime);
for (PerChannel perChannel : trafficShapingHandler1.channelQueues.values()) {
perChannel.channelTrafficCounter.resetAccounting(newLastTime);
}
trafficShapingHandler1.doAccounting(counter);
counter.timer.newTimeout(this, counter.checkInterval.get(), TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled()) {
return;
}
if (!ctx.getChannel().isOpen()) {
return;
}
State state = (State) ctx.getAttachment();
long currentTime = System.currentTimeMillis();
long nextDelay = timeoutMillis - (currentTime - state.lastReadTime);
if (nextDelay <= 0) {
// Read timed out - set a new timeout and notify the callback.
state.timeout =
timer.newTimeout(this, timeoutMillis, TimeUnit.MILLISECONDS);
fireReadTimedOut(ctx);
} else {
// Read occurred before the timeout - set a new timeout with shorter delay.
state.timeout =
timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
}
}
代码示例来源:origin: io.netty/netty
public void run() {
int timeout = channel.getConfig().getConnectTimeoutMillis();
if (timeout > 0) {
if (!channel.isConnected()) {
channel.timoutTimer = timer.newTimeout(wakeupTask,
timeout, TimeUnit.MILLISECONDS);
}
}
try {
channel.channel.register(
boss.selector, SelectionKey.OP_CONNECT, channel);
} catch (ClosedChannelException e) {
channel.worker.close(channel, succeededFuture(channel));
}
int connectTimeout = channel.getConfig().getConnectTimeoutMillis();
if (connectTimeout > 0) {
channel.connectDeadlineNanos = System.nanoTime() + connectTimeout * 1000000L;
}
}
}
代码示例来源:origin: io.netty/netty
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
long timeoutMillis = getTimeoutMillis(e);
if (timeoutMillis > 0) {
// Set timeout only when getTimeoutMillis() returns a positive value.
ChannelFuture future = e.getFuture();
final Timeout timeout = timer.newTimeout(
new WriteTimeoutTask(ctx, future),
timeoutMillis, TimeUnit.MILLISECONDS);
future.addListener(new TimeoutCanceller(timeout));
}
super.writeRequested(ctx, e);
}
代码示例来源:origin: io.netty/netty
writeTimeout = timer.newTimeout(new TimerTask() {
public void run(Timeout timeout) throws Exception {
sendAllValid(ctx, futureNow);
代码示例来源:origin: io.netty/netty
timer.newTimeout(new TimerTask() {
public void run(Timeout timeout) throws Exception {
sendAllValid(ctx, forSchedule, futureNow);
代码示例来源:origin: io.netty/netty
timer.newTimeout(new TimerTask() {
public void run(Timeout timeout) throws Exception {
sendAllValid(ctx, forSchedule, futureNow);
代码示例来源:origin: com.ning/async-http-client
public Timeout newTimeout(TimerTask task, long delay) {
return nettyTimer.newTimeout(task, delay, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: com.ning/async-http-client
private void scheduleNewIdleChannelDetector(TimerTask task) {
nettyTimer.newTimeout(task, cleanerPeriod, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: io.netty/netty
rws.reopenReadTimerTask = new ReopenReadTimerTask(ctx);
timeout = timer.newTimeout(rws.reopenReadTimerTask, wait,
TimeUnit.MILLISECONDS);
代码示例来源:origin: io.netty/netty
rws.reopenReadTimerTask = new ReopenReadTimerTask(ctx);
timeout = timer.newTimeout(rws.reopenReadTimerTask, wait,
TimeUnit.MILLISECONDS);
代码示例来源:origin: io.netty/netty
handshakeFuture = this.handshakeFuture = future(channel);
if (handshakeTimeoutInMillis > 0) {
handshakeTimeout = timer.newTimeout(new TimerTask() {
public void run(Timeout timeout) throws Exception {
ChannelFuture future = SslHandler.this.handshakeFuture;
内容来源于网络,如有侵权,请联系作者删除!