/** * closes the connection to the remote client which has sent currently executing message. * If current message was not sent by a client, NOP. */ protected void closeCurrentClient() { ConnectionRegistry remoteConnection = connection.get(); if ( remoteConnection != null ) { delayed(1000, () -> remoteConnection.close(this)); } }
@Local public void debounce(long timeout, String tag, Runnable toRun ) { if ( _debounceMap == null ) _debounceMap = new HashMap<>(7); _debounceMap.put(tag,toRun); delayed(timeout, () -> { if ( _debounceMap.get(tag) == toRun ) { _debounceMap.remove(tag); toRun.run(); } }); }
@Local public void debounce(long timeout, String tag, Runnable toRun ) { if ( _debounceMap == null ) _debounceMap = new HashMap<>(7); _debounceMap.put(tag,toRun); delayed(timeout, () -> { if ( _debounceMap.get(tag) == toRun ) { _debounceMap.remove(tag); toRun.run(); } }); }
/** * closes the connection to the remote client which has sent currently executing message. * If current message was not sent by a client, NOP. */ protected void closeCurrentClient() { ConnectionRegistry remoteConnection = connection.get(); if ( remoteConnection != null ) { delayed(1000, () -> remoteConnection.close(this)); } }
public AbstractHttpServerConnector(Actor facade) { this.facade = facade; facade.delayed( HttpObjectSocket.LP_TIMEOUT/2, () -> houseKeeping() ); }
/** * see IPromise (inheriting Callback) interface */ @Override public IPromise timeoutIn(long millis) { final Actor actor = Actor.sender.get(); if ( actor != null ) actor.delayed(millis, ()-> timedOut(Timeout.INSTANCE)); else { Actors.delayedCalls.schedule( new TimerTask() { @Override public void run() { timedOut(Timeout.INSTANCE); } },millis); } return this; }
/** * see IPromise (inheriting Callback) interface */ @Override public IPromise timeoutIn(long millis) { final Actor actor = Actor.sender.get(); if ( actor != null ) actor.delayed(millis, ()-> timedOut(Timeout.INSTANCE)); else { Actors.delayedCalls.schedule( new TimerTask() { @Override public void run() { timedOut(Timeout.INSTANCE); } },millis); } return this; }
public void run() { pollThread = Thread.currentThread(); if ( underway ) return; underway = true; try { int count = 1; while( count > 0 ) { // as long there are messages, keep sending them count = onePoll(); if ( sendJobs.size() > 0 ) { if ( count > 0 ) { int debug =1; } else { if ( remoteRefCounter == 0 ) // no remote actors registered { Actor.current().delayed(100, this); // backoff massively } else { Actor.current().delayed(1, this); // backoff a bit (remoteactors present, no messages) } } } else { // no schedule entries (== no clients) Actor.current().delayed(100, this ); } } } finally { underway = false; } }
public void run() { pollThread = Thread.currentThread(); if ( underway ) return; underway = true; try { int count = 1; while( count > 0 ) { // as long there are messages, keep sending them count = onePoll(); if ( sendJobs.size() > 0 ) { if ( count > 0 ) { int debug =1; } else { if ( remoteRefCounter == 0 ) // no remote actors registered { Actor.current().delayed(100, this); // backoff massively } else { Actor.current().delayed(1, this); // backoff a bit (remoteactors present, no messages) } } } else { // no schedule entries (== no clients) Actor.current().delayed(100, this ); } } } finally { underway = false; } }
public void houseKeeping() { // System.out.println("----------------- HOUSEKEEPING ------------------------"); long now = System.currentTimeMillis(); ArrayList<String> toRemove = new ArrayList<>(0); sessions.entrySet().forEach( entry -> { HttpObjectSocket socket = entry.getValue(); if ( now- socket.getLongPollTaskTime() >= HttpObjectSocket.LP_TIMEOUT/2 ) { socket.triggerLongPoll(); } if ( now- socket.getLastUse() > getSessionTimeout() ) { toRemove.add(entry.getKey()); } }); toRemove.forEach(sessionId -> closeSession(sessionId)); if ( ! isClosed ) { facade.delayed( HttpObjectSocket.LP_TIMEOUT/4, () -> houseKeeping() ); } }
@Local public void cyclic(long interval, Callable<Boolean> toRun) { if ( ! isStopped() ) { Boolean res = true; try { res = toRun.call(); } catch (Exception e) { Log.Warn(this,e); } if (res) self().delayed(interval,() -> cyclic(interval,toRun) ); } }
@Local public void cyclic(long interval, Callable<Boolean> toRun) { if ( ! isStopped() ) { Boolean res = true; try { res = toRun.call(); } catch (Exception e) { Log.Warn(this,e); } if (res) self().delayed(interval,() -> cyclic(interval,toRun) ); } }
Actor.current().execute(this); } else { Actor.current().delayed( 2, this );
Actor.current().execute(this); } else { Actor.current().delayed( 2, this );
actor.execute( () -> receiveLoop() ); } else { actor.delayed( 1, () -> receiveLoop() );
actor.execute( () -> receiveLoop() ); } else { actor.delayed( 1, () -> receiveLoop() );