@Override protected void destroy() { scheduler.stop(); } }
@Override protected void init() { scheduler.scheduleAtFixedRate(() -> { boolean leaked = false; Reference<? extends T> ref; while ((ref = referenceQueue.poll()) != null) { try { leaked = true; Optional.ofNullable(registeredMap.remove(ref)).ifPresent(Action0::call); } catch (Exception e) { System.err.println(e.getMessage()); } } if (!leaked) { noLeakCallback.call(); } }, initialDelay, delay, unit); }
@Override protected void init() { scheduler.scheduleWithFixedDelay(() -> map.forEach((id, session) -> { if (session.isInvalid()) { map.remove(id); log.info("remove expired local HTTP session -> {}", id); } }), 1, 1, TimeUnit.SECONDS); }
private void scheduleIdleTimeout(long delay) { Scheduler.Future newTimeout = null; if (isOpen() && delay > 0 && scheduler != null) newTimeout = scheduler.schedule(idleTask, delay, TimeUnit.MILLISECONDS); Scheduler.Future oldTimeout = timeout.getAndSet(newTimeout); if (oldTimeout != null) oldTimeout.cancel(); }
@Override protected void init() { scheduler.scheduleAtFixedRate(() -> { boolean leaked = false; Reference<? extends T> ref; while ((ref = referenceQueue.poll()) != null) { try { leaked = true; Optional.ofNullable(registeredMap.remove(ref)).ifPresent(Action0::call); } catch (Exception e) { System.err.println(e.getMessage()); } } if (!leaked) { noLeakCallback.call(); } }, initialDelay, delay, unit); }
@Override protected void init() { scheduler.scheduleWithFixedDelay(() -> map.forEach((id, session) -> { if (session.isInvalid()) { map.remove(id); log.info("remove expired local HTTP session -> {}", id); } }), 1, 1, TimeUnit.SECONDS); }
private void scheduleIdleTimeout(long delay) { Scheduler.Future newTimeout = null; if (isOpen() && delay > 0 && scheduler != null) newTimeout = scheduler.schedule(idleTask, delay, TimeUnit.MILLISECONDS); Scheduler.Future oldTimeout = timeout.getAndSet(newTimeout); if (oldTimeout != null) oldTimeout.cancel(); }
@Override protected void init() { scheduler.scheduleAtFixedRate(() -> checkTaskMap.forEach((name, task) -> { try { task.getTask().call() .thenAccept(result -> Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, result, null))) .exceptionally(ex -> { Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, Result.FAILURE, ex)); return null; }); } catch (Exception ex) { Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, Result.FAILURE, ex)); } }), initialDelay, delay, unit); }
@Override protected void destroy() { scheduler.stop(); } }
@Override protected void init() { if (!CollectionUtils.isEmpty(activatedList)) { activatedList.forEach(hostPort -> { try { FlexConnection connection = createConnection(hostPort); if (connection != null) { connectionMap.put(hostPort, connection); } } catch (Exception e) { log.error("Connect " + hostPort + " exception", e); } }); updateActivatedList(); } scheduler.scheduleWithFixedDelay(() -> { log.info("Client current activated address list: {}", activatedList); activatedList = convert(addressProvider.getAddressList()); }, 5, 5, TimeUnit.SECONDS); }
private void scheduleIdleTimeout(long delay) { Scheduler.Future newTimeout = null; if (isOpen() && delay > 0 && scheduler != null) newTimeout = scheduler.schedule(idleTask, delay, TimeUnit.MILLISECONDS); Scheduler.Future oldTimeout = timeout.getAndSet(newTimeout); if (oldTimeout != null) oldTimeout.cancel(); }
@Override protected void init() { scheduler.scheduleAtFixedRate(() -> checkTaskMap.forEach((name, task) -> { try { task.getTask().call() .thenAccept(result -> Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, result, null))) .exceptionally(ex -> { Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, Result.FAILURE, ex)); return null; }); } catch (Exception ex) { Optional.ofNullable(task.getResultListener()).ifPresent(ret -> ret.call(name, Result.FAILURE, ex)); } }), initialDelay, delay, unit); }
@Override protected void destroy() { scheduler.stop(); } }
@Override protected void init() { if (!CollectionUtils.isEmpty(activatedList)) { activatedList.forEach(hostPort -> { try { FlexConnection connection = createConnection(hostPort); if (connection != null) { connectionMap.put(hostPort, connection); } } catch (Exception e) { log.error("Connect " + hostPort + " exception", e); } }); updateActivatedList(); } scheduler.scheduleWithFixedDelay(() -> { log.info("Client current activated address list: {}", activatedList); activatedList = convert(addressProvider.getAddressList()); }, 5, 5, TimeUnit.SECONDS); }
public static void main(String[] args) throws Exception { Scheduler scheduler = Schedulers.createScheduler(); Path path = Paths.get(WebSocketServerDemo.class.getResource("/").toURI()); $.httpServer() .router().get("/static/*").handler(new StaticFileHandler(path.toAbsolutePath().toString())) .router().get("/").handler(ctx -> ctx.renderTemplate("template/websocket/index.mustache")) .webSocket("/helloWebSocket") .onConnect(conn -> { Scheduler.Future future = scheduler.scheduleAtFixedRate(() -> conn.sendText("Current time: " + new Date()), 0, 1, TimeUnit.SECONDS); conn.onClose(c -> future.cancel()); }) .onText((text, conn) -> System.out.println("Server received: " + text)) .listen("localhost", 8080); } }
@Override protected void destroy() { scheduler.stop(); } }
session.setAttribute(HEARTBEAT_KEY, scheduler.scheduleAtFixedRate( () -> flexConnection.getSession().ping(new PingFrame(false)), configuration.getHeartbeatInterval(),
@Override protected void destroy() { scheduler.stop(); } }
session.setAttribute(HEARTBEAT_KEY, scheduler.scheduleAtFixedRate( () -> flexConnection.getSession().ping(new PingFrame(false)), configuration.getHeartbeatInterval(),
@Override protected void destroy() { scheduler.stop(); } }