List of usage examples for io.netty.util TimerTask TimerTask
TimerTask
From source file:io.scalecube.socketio.session.SocketIOHeartbeatScheduler.java
License:Apache License
private void scheduleHeartbeat() { hTimeout = hashedWheelTimer.newTimeout(new TimerTask() { @Override//from w w w . j ava2 s .c om public void run(Timeout timeout) throws Exception { if (!disabled) { session.sendHeartbeat(); scheduleHeartbeat(); } } }, heartbeatInterval, TimeUnit.SECONDS); }
From source file:io.scalecube.socketio.session.SocketIOHeartbeatScheduler.java
License:Apache License
public void scheduleDisconnect() { dTimeout = hashedWheelTimer.newTimeout(new TimerTask() { @Override/*from w ww. j a v a 2 s . c om*/ public void run(Timeout timeout) throws Exception { if (!disabled) { if (log.isDebugEnabled()) log.debug("{} Session will be disconnected by timeout", session.getSessionId()); session.disconnect(); } } }, heartbeatTimeout, TimeUnit.SECONDS); }
From source file:mmo.server.GameLoop.java
License:Open Source License
private void movingNow(final Room room, final Player player, final Direction dir) { messageHub.sendMessage(room.contents(), new Moving(room.getId(player), dir)); timer.newTimeout(new TimerTask() { @Override//from www . j a va 2s . c o m public void run(Timeout timeout) throws Exception { move(player, dir); } }, ACTION_DELAY_MILLIS, TimeUnit.MILLISECONDS); }
From source file:mmo.server.GameLoop.java
License:Open Source License
private void attackingNow(final Room room, final Player player, final Direction dir) { messageHub.sendMessage(room.contents(), new Attacking(room.getId(player), dir)); timer.newTimeout(new TimerTask() { @Override// www . j av a2 s . c om public void run(Timeout timeout) throws Exception { attack(player, dir); } }, ACTION_DELAY_MILLIS * 3 / 2, TimeUnit.MILLISECONDS); }
From source file:mmo.server.GameLoop.java
License:Open Source License
private void attack(final Player player, final Direction dir) { loop.submit(new Runnable() { @Override//from w ww .j a v a2 s . c o m public void run() { PlayerState s = players.get(player); final Room room = roomIds.inverse().get(s.currentRoom); Coord target = room.getCoord(player).toThe(dir); if (!room.isCoordInRoom(target)) { messageHub.sendMessage(room.contents(), new Miss(room.getId(player))); } else { Player p = room.playerAt(target); if (p instanceof Mob) { messageHub.sendMessage(room.contents(), new Hit(room.getId(player), 1)); int mobId = room.getId(p); final SpawnPoint spawn = room.pwn((Mob) p); messageHub.sendMessage(room.contents(), new Pwnd(mobId)); timer.newTimeout(new TimerTask() { @Override public void run(Timeout timeout) throws Exception { loop.submit(new Runnable() { @Override public void run() { Mob m = room.spawnMob(spawn); // TODO m == null? Spawned spawned = new Spawned( new PlayerInRoom(room.getId(m), m, room.getCoord(m))); messageHub.sendMessage(room.contents(), spawned); } }); } }, spawn.getIntervalMillis(), TimeUnit.MILLISECONDS); } else { messageHub.sendMessage(room.contents(), new Miss(room.getId(player))); } } workQueue(s, room, player); } }); }
From source file:mmo.server.MessageReceiver.java
License:Open Source License
private void welcomeMessages(final Player player) { String[] msgs = new String[] { "<big>Welcome to POS1-mmo!</big>", "<big><strong>Please use responsibly!</strong></big>", "Find code and updates here: " + "<ul>" + "<li>" + "<a href='https://github.com/H4ssi/mmo-server'>" + "https://github.com/H4ssi/mmo-server" + "</a>" + "</li>" + "<li>" + "<a href='https://github.com/H4ssi/mmo-client'>" + "https://github.com/H4ssi/mmo-client" + "</a>" + "</li>" + "</ul>", "<small>mmo-server is free software, and you are welcome to " + "redistribute it under the terms of the GNU AGPL: " + "<a href='https://gnu.org/licenses/agpl.html'>" + "https://gnu.org/licenses/agpl.html" + "</a></small>", "<small>This server will receive the newest features " + "and will be updated regularly!<br>" + "For the a more stable version use " + "<a href='http://89.110.148.15:33333'>" + "http://89.110.148.15:33333 (port 33333)" + "</a>" + "</small>", "<big><strong>hf</strong></big>" }; int delay = 2; for (final String msg : msgs) { timer.newTimeout(new TimerTask() { @Override/*from w w w .j a v a 2 s .c o m*/ public void run(Timeout timeout) throws Exception { messageHub.sendMessage(player, new Chat(null, msg)); } }, delay, TimeUnit.SECONDS); delay += 1; } }
From source file:net.hasor.rsf.remoting.transport.customer.RsfRequestManager.java
License:Apache License
/**?*/ private void startRequest(RsfFuture rsfFuture) { this.requestCount.incrementAndGet();// i++; this.rsfResponse.put(rsfFuture.getRequest().getRequestID(), rsfFuture); final RsfRequestImpl request = (RsfRequestImpl) rsfFuture.getRequest(); TimerTask timeTask = new TimerTask() { public void run(Timeout timeoutObject) throws Exception { ///*from w w w .j av a 2 s . c o m*/ RsfFuture rsfCallBack = RsfRequestManager.this.getRequest(request.getRequestID()); if (rsfCallBack == null) return; //?Response String errorInfo = "timeout is reached on client side:" + request.getTimeout(); LoggerHelper.logWarn(errorInfo); //Response RsfRequestManager.this.putResponse(request.getRequestID(), new RsfTimeoutException(errorInfo)); } }; // int reqTimeout = validateTimeout(request.getTimeout()); this.timer.newTimeout(timeTask, reqTimeout, TimeUnit.MILLISECONDS); }
From source file:net.hasor.rsf.rpc.caller.RsfRequestManager.java
License:Apache License
/** * ?//from w w w . j a va 2 s .c om * @param rsfFuture */ private void startRequest(RsfFuture rsfFuture) { this.requestCount.incrementAndGet();// i++; this.rsfResponse.put(rsfFuture.getRequest().getRequestID(), rsfFuture); final RsfRequestFormLocal request = (RsfRequestFormLocal) rsfFuture.getRequest(); TimerTask timeTask = new TimerTask() { public void run(Timeout timeoutObject) throws Exception { RsfFuture rsfCallBack = getRequest(request.getRequestID()); /*???*/ if (rsfCallBack == null) return; /*?*/ String errorInfo = "request(" + request.getRequestID() + ") -> timeout for client."; invLogger.error(errorInfo); /*Response*/ putResponse(request.getRequestID(), new RsfTimeoutException(errorInfo)); } }; invLogger.info("request({}) -> startRequest, timeout at {} ,bindID ={}, callMethod ={}.", // request.getRequestID(), request.getTimeout(), request.getBindInfo().getBindID(), request.getMethod()); this.getContext().getEnvironment().atTime(timeTask, request.getTimeout()); }
From source file:net.hasor.rsf.rpc.net.LinkPool.java
License:Apache License
public synchronized BasicFuture<RsfChannel> preConnection(String hostPortKey) { if (!this.inited.get()) { throw new IllegalStateException("LinkPool not inited."); }//from ww w .j ava 2s . com // //Future???Futureget? final BasicFuture<RsfChannel> channel = new BasicFuture<RsfChannel>(); BasicFuture<RsfChannel> oldFuture = this.channelMap.putIfAbsent(hostPortKey, channel); if (oldFuture != null) { return oldFuture; } // int timeout = this.environment.getSettings().getConnectTimeout(); this.environment.atTime(new TimerTask() { @Override public void run(Timeout timeout) throws Exception { if (!channel.isDone()) { channel.failed(new RsfException(ProtocolStatus.Timeout, "connection not ready within the given time.")); } } }, timeout); return channel; }
From source file:net.qing.sms.simulator.HashedWheelScheduler.java
License:Apache License
public void schedule(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) { Timeout timeout = executorService.newTimeout(new TimerTask() { @Override//from w w w . j a v a2 s. c o m public void run(Timeout timeout) throws Exception { try { runnable.run(); } finally { scheduledFutures.remove(key); } } }, delay, unit); if (!timeout.isExpired()) { Timeout preTimeout = scheduledFutures.put(key, timeout); if (preTimeout != null) { preTimeout.cancel(); } } }