@Override protected Log self() { if ( Lg instanceof ActorProxy) return super.self(); else return this; }
@Override protected Log self() { if ( Lg instanceof ActorProxy) return super.self(); else return this; }
@CallerSideMethod public Actor getUntypedRef() { Actor actor = new Actor(); actor.__publishTarget = self(); return actor; }
@CallerSideMethod public Actor getUntypedRef() { Actor actor = new Actor(); actor.__publishTarget = self(); return actor; }
/** * execute a callable asynchronously (in a different thread) and return a future * of the result (delivered in caller thread). Can be used to isolate blocking operations * * WARNING: do not access local actor state (instance fields) from within the callable (=hidden parallelism). * WARNING: a similar named method execute() works different (bad naming) * * @param callable * @param <T> * @return */ public <T> IPromise<T> execInThreadPool(Callable<T> callable) { Promise<T> prom = new Promise<>(); __scheduler.runBlockingCall(self(), callable, prom); return prom; }
/** * execute a callable asynchronously (in a different thread) and return a future * of the result (delivered in caller thread). Can be used to isolate blocking operations * * WARNING: do not access local actor state (instance fields) from within the callable (=hidden parallelism). * WARNING: a similar named method execute() works different (bad naming) * * @param callable * @param <T> * @return */ public <T> IPromise<T> execInThreadPool(Callable<T> callable) { Promise<T> prom = new Promise<>(); __scheduler.runBlockingCall(self(), callable, prom); return prom; }
/** * stop receiving events. If there are no actors left on the underlying dispatcher, * the dispatching thread will be terminated. */ @CallerSideMethod public void stop() { if ( isRemote() ) { throw new RuntimeException("Cannot stop remote ref"); } SELF self = self(); if ( self != null ) { self.ping().then(() -> { SELF selfInner = self(); if ( selfInner != null ) selfInner.asyncstop(); }); // ensure all queues are cleaned } }
/** * stop receiving events. If there are no actors left on the underlying dispatcher, * the dispatching thread will be terminated. */ @CallerSideMethod public void stop() { if ( isRemote() ) { throw new RuntimeException("Cannot stop remote ref"); } SELF self = self(); if ( self != null ) { self.ping().then(() -> { SELF selfInner = self(); if ( selfInner != null ) selfInner.asyncstop(); }); // ensure all queues are cleaned } }
/** * just enqueue given runable to this actors mailbox and execute on the actor's thread * WARNING: the similar named method execInThreadPool() works different (bad naming) * @param command */ @CallerSideMethod @Local @Override public void execute(Runnable command) { self().__submit(command); }
/** * just enqueue given runable to this actors mailbox and execute on the actor's thread * WARNING: the similar named method execInThreadPool() works different (bad naming) * @param command */ @CallerSideMethod @Local @Override public void execute(Runnable command) { self().__submit(command); }
/** * schedule an action or call delayed. * typical use case: * delayed( 100, () -> { self().doAction( x, y, ); } ); * */ @CallerSideMethod @Local public void delayed( long millis, final Runnable toRun ) { __scheduler.delayedCall(millis, inThread(self(), 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) ); } }
@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) ); } }
/** * schedule an action or call delayed. * typical use case: * delayed( 100, () -> { self().doAction( x, y, ); } ); * */ @CallerSideMethod @Local public void delayed( long millis, final Runnable toRun ) { __scheduler.delayedCall(millis, inThread(self(), toRun)); }
/** * avoids exception when closing an actor after stop has been called. */ @CallerSideMethod public void stopSafeClose() { if ( isStopped() ) { getActor().close(); // is threadsafe } else { self().close(); } }
/** * avoids exception when closing an actor after stop has been called. */ @CallerSideMethod public void stopSafeClose() { if ( isStopped() ) { getActor().close(); // is threadsafe } else { self().close(); } }
@CallerSideMethod protected void __stopImpl() { Log.Debug(this,"stopping actor "+getClass().getSimpleName()); Actor self = __self; if ( self == null || getActor() == null || (self.isStopped() && getActor().isStopped()) ) return; getActorRef().__stopped = true; getActor().__stopped = true; if (__stopHandlers!=null) { __stopHandlers.forEach( (cb) -> cb.complete(self(), null) ); __stopHandlers.clear(); } // remove ref to real actor as ref might still be referenced in threadlocals and // queues. //FIXME: this causes NPE instead of deadletter // try { // getActorRef().getClass().getField("__target").set( getActorRef(), null ); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } catch (NoSuchFieldException e) { // e.printStackTrace(); // } throw InternalActorStoppedException.Instance; }
@CallerSideMethod protected void __stopImpl() { Log.Debug(this,"stopping actor "+getClass().getSimpleName()); Actor self = __self; if ( self == null || getActor() == null || (self.isStopped() && getActor().isStopped()) ) return; getActorRef().__stopped = true; getActor().__stopped = true; if (__stopHandlers!=null) { __stopHandlers.forEach( (cb) -> cb.complete(self(), null) ); __stopHandlers.clear(); } // remove ref to real actor as ref might still be referenced in threadlocals and // queues. //FIXME: this causes NPE instead of deadletter // try { // getActorRef().getClass().getField("__target").set( getActorRef(), null ); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } catch (NoSuchFieldException e) { // e.printStackTrace(); // } throw InternalActorStoppedException.Instance; }
rce.unpackArgs(registry.getConf()); try { Object future = getScheduler().enqueueCallFromRemote(registry, null, self(), rce.getMethod(), rce.getArgs(), false, null, callInterceptor); if ( future instanceof IPromise) { Promise p = null; self().execute(runnable); else runnable.run(); Log.Warn(this,th); if ( rce.getFutureKey() != 0 ) { self().execute(() -> { try { registry.receiveCBResult(objSocket, rce.getFutureKey(), null, FSTUtil.toString(th));
rce.unpackArgs(registry.getConf()); try { Object future = getScheduler().enqueueCallFromRemote(registry, null, self(), rce.getMethod(), rce.getArgs(), false, null, callInterceptor); if ( future instanceof IPromise) { Promise p = null; self().execute(runnable); else runnable.run(); Log.Warn(this,th); if ( rce.getFutureKey() != 0 ) { self().execute(() -> { try { registry.receiveCBResult(objSocket, rce.getFutureKey(), null, FSTUtil.toString(th));