本文整理匯總了Java中org.jboss.netty.util.TimerTask類的典型用法代碼示例。如果您正苦於以下問題:Java TimerTask類的具體用法?Java TimerTask怎麽用?Java TimerTask使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TimerTask類屬於org.jboss.netty.util包,在下文中一共展示了TimerTask類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
switchManager = createMock(IOFSwitchManager.class);
roleManager = createMock(RoleManager.class);
sw = createMock(IOFSwitchBackend.class);
timer = createMock(Timer.class);
expect(timer.newTimeout(anyObject(TimerTask.class), anyLong(), anyObject(TimeUnit.class))).andReturn(EasyMock.createNiceMock(Timeout.class));
replay(timer);
seenXids = null;
// TODO: should mock IDebugCounterService and make sure
// the expected counters are updated.
debugCounterService = new DebugCounterServiceImpl();
SwitchManagerCounters counters =
new SwitchManagerCounters(debugCounterService);
expect(switchManager.getCounters()).andReturn(counters).anyTimes();
replay(switchManager);
connection = new MockOFConnection(featuresReply.getDatapathId(), OFAuxId.MAIN);
switchHandler = new OFSwitchHandshakeHandler(connection, featuresReply, switchManager, roleManager, timer);
// replay sw. Reset it if you need more specific behavior
replay(sw);
}
示例2: setUp
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
switchManager = createMock(IOFSwitchManager.class);
roleManager = createMock(RoleManager.class);
sw = createMock(IOFSwitchBackend.class);
timer = createMock(Timer.class);
expect(timer.newTimeout(anyObject(TimerTask.class), anyLong(), anyObject(TimeUnit.class))).andReturn(EasyMock.createNiceMock(Timeout.class));
replay(timer);
seenXids = null;
// TODO: should mock IDebugCounterService and make sure
// the expected counters are updated.
debugCounterService = new DebugCounterServiceImpl();
SwitchManagerCounters counters =
new SwitchManagerCounters(debugCounterService);
expect(switchManager.getCounters()).andReturn(counters).anyTimes();
replay(switchManager);
connection = new MockOFConnection(featuresReply.getDatapathId(), OFAuxId.MAIN);
switchHandler = new OFSwitchHandshakeHandler(connection, featuresReply, switchManager, roleManager, timer);
// replay sw. Reset it if you need more specific behavior
replay(sw);
}
示例3: setUp
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
switchManager = createMock(IOFSwitchManager.class);
roleManager = createMock(RoleManager.class);
sw = createMock(IOFSwitchBackend.class);
timer = createMock(Timer.class);
expect(timer.newTimeout(anyObject(TimerTask.class), anyLong(), anyObject(TimeUnit.class))).andReturn(EasyMock.createNiceMock(Timeout.class));
replay(timer);
seenXids = null;
// TODO: should mock IDebugCounterService and make sure
// the expected counters are updated.
debugCounterService = new DebugCounterServiceImpl();
SwitchManagerCounters counters =
new SwitchManagerCounters(debugCounterService);
expect(switchManager.getCounters()).andReturn(counters).anyTimes();
replay(switchManager);
connection = new MockOFConnection(featuresReply.getDatapathId(), OFAuxId.MAIN);
switchHandler = new OFSwitchHandshakeHandler(connection, featuresReply, switchManager, roleManager, timer,null);
// replay sw. Reset it if you need more specific behavior
replay(sw);
}
示例4: reconnect
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private void reconnect() {
if (!reconnecting.get()) {
reconnecting.set(true);
timer.newTimeout(new TimerTask() {
@Override public void run(Timeout timeout) throws Exception {
reconnecting.set(false);
int port = uri.getPort();
if (port == -1) {
port = (uri.getScheme().equals("https")) ? 443 : 80;
}
bootstrap.setOption("remoteAddress", new InetSocketAddress(uri.getHost(), port));
bootstrap.connect().await();
}
}, reconnectionTimeMillis, TimeUnit.MILLISECONDS);
}
}
示例5: reconnect
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private void reconnect() {
if (!reconnecting.get()) {
reconnecting.set(true);
data = new StringBuffer();
lastEventId = null;
status = null;
eventStreamOk = false;
headerDone = false;
timer.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
reconnecting.set(false);
int port = uri.getPort();
if (port == -1) {
port = (uri.getScheme().equals("https")) ? 443 : 80;
}
bootstrap.setOption("remoteAddress", new InetSocketAddress(uri.getHost(), port));
bootstrap.connect().await();
}
}, reconnectionTimeMillis, TimeUnit.MILLISECONDS);
}
}
示例6: fireNext
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
public void fireNext(final Channel channel, final long delay) {
final Event readyForNext = new Event(currentConversationId);
if(delay > timerTickSize) {
timer.newTimeout(new TimerTask() {
@Override public void run(Timeout timeout) {
if(logger.isDebugEnabled()) {
logger.debug("running after delay: {}", delay);
}
if(readyForNext.conversationId != currentConversationId) {
logger.debug("pending 'next' event found obsolete, aborting");
return;
}
Channels.fireMessageReceived(channel, readyForNext);
}
}, delay, TimeUnit.MILLISECONDS);
} else {
Channels.fireMessageReceived(channel, readyForNext);
}
}
示例7: newTimeout
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private Timeout newTimeout() {
if (requestTimeoutInMs > 0) {
return timeoutExecutor.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) {
fsm.sendEvent(new HandshakeTimeoutEvent());
}
}, 30, TimeUnit.SECONDS);
} else {
return null;
}
}
示例8: ConnectionFailedState
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
ConnectionFailedState(final StateMachine.Fsm fsm, final Throwable exception) {
super(fsm);
LOG.debug("NEW STATE: CONNECTION FAILED [RE-CONNECTION BACKOFF]");
this.exception = exception;
reconnectionTimeoutExecutor.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) {
fsm.sendEvent(new ReconnectEvent());
}
}, tsoReconnectionDelayInSecs, TimeUnit.SECONDS);
}
示例9: channelClosed
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
logger.warn("channel closed.do connect after:{} seconds.", CONN_DELAY);
//重連
timer.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
ChannelFuture channelfuture = client.getBootstrap().connect();
client.setChannel(channelfuture);
}
}, CONN_DELAY, TimeUnit.SECONDS);
}
示例10: channelClosed
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
logger.warn("channel closed.do connect after:{} seconds.", CONN_DELAY);
//重連
timer.newTimeout( new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
ChannelFuture channelfuture = client.getBootstrap().connect();
client.setChannel(channelfuture);
}
}, CONN_DELAY, TimeUnit.SECONDS);
}
示例11: newTimeout
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Override
public synchronized Timeout newTimeout(final TimerTask task,
final long delay,
final TimeUnit unit) {
if (pausedTask == null) {
pausedTask = task;
} else if (newPausedTask == null) {
newPausedTask = task;
} else {
throw new IllegalStateException("Cannot Pause Two Timer Tasks");
}
return null;
}
示例12: setUp
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
/*
* This needs to be called explicitly to ensure the featuresReply is not null.
* Otherwise, there is no guarantee @Before will for setUpFeaturesReply() will
* call that function before our @Before setUp() here.
*/
setUpFeaturesReply();
switchManager = createMock(IOFSwitchManager.class);
roleManager = createMock(RoleManager.class);
sw = createMock(IOFSwitchBackend.class);
timer = createMock(Timer.class);
expect(timer.newTimeout(anyObject(TimerTask.class), anyLong(), anyObject(TimeUnit.class))).andReturn(EasyMock.createNiceMock(Timeout.class));
replay(timer);
seenXids = null;
// TODO: should mock IDebugCounterService and make sure
// the expected counters are updated.
debugCounterService = new DebugCounterServiceImpl();
SwitchManagerCounters counters =
new SwitchManagerCounters(debugCounterService);
expect(switchManager.getCounters()).andReturn(counters).anyTimes();
replay(switchManager);
connection = new MockOFConnection(featuresReply.getDatapathId(), OFAuxId.MAIN);
switchHandler = new OFSwitchHandshakeHandler(connection, featuresReply, switchManager, roleManager, timer);
// replay sw. Reset it if you need more specific behavior
replay(sw);
}
示例13: sendPing
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private void sendPing() {
logger.debug("sendPing");
final TimerTask pintTask = new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled()) {
newPingTimeout(this);
return;
}
final ChannelGroupFuture write = channelGroup.write(PingPacket.PING_PACKET);
if (logger.isWarnEnabled()) {
write.addListener(new ChannelGroupFutureListener() {
private final ChannelFutureListener listener = new WriteFailFutureListener(logger, "ping write fail", "ping write success");
@Override
public void operationComplete(ChannelGroupFuture future) throws Exception {
if (logger.isWarnEnabled()) {
for (ChannelFuture channelFuture : future) {
channelFuture.addListener(listener);
}
}
}
});
}
newPingTimeout(this);
}
};
newPingTimeout(pintTask);
}
示例14: newPingTimeout
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private void newPingTimeout(TimerTask pintTask) {
try {
logger.debug("newPingTimeout");
pingTimer.newTimeout(pintTask, 1000 * 60 * 5, TimeUnit.MILLISECONDS);
} catch (IllegalStateException e) {
// stop in case of timer stopped
logger.debug("timer stopped. Caused:{}", e.getMessage());
}
}
示例15: newTimer
import org.jboss.netty.util.TimerTask; //導入依賴的package包/類
private TimerTask newTimer() {
return new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
onTimeout(System.nanoTime() - startTime);
}
};
}