org.nustaq.kontraktor.RateLoggingRemoteCallMonitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontraktor Show documentation
Show all versions of kontraktor Show documentation
a light weight, efficient actor lib
The newest version!
package org.nustaq.kontraktor;
import org.nustaq.kontraktor.remoting.base.ObjectSocket;
import org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry;
import org.nustaq.kontraktor.util.RateMeasure;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
public class RateLoggingRemoteCallMonitor implements RemoteCallMonitor {
ConcurrentMap rateMeasureMap = new ConcurrentHashMap<>();
long intervalMillis;
public RateLoggingRemoteCallMonitor(long intervalMillis) {
this.intervalMillis = intervalMillis;
}
@Override
public void remoteCallObserved(Actor selfActor, ObjectSocket objSocket, RemoteCallEntry rce, Object authContext) {
RateMeasure rateMeasure = rateMeasureMap.get(selfActor.getClass());
if ( rateMeasure == null ) {
rateMeasure = new RateMeasure(selfActor.getClass().getSimpleName(), intervalMillis).print(true);
rateMeasureMap.put(selfActor.getClass(),rateMeasure);
}
rateMeasure.count();
}
public static void main(String[] args) throws InterruptedException {
Actor actor = Actors.AsActor(Actor.class);
RateLoggingRemoteCallMonitor mon = new RateLoggingRemoteCallMonitor(TimeUnit.SECONDS.toMillis(1));
for (int i = 0; i < 1_000_000_000; i++) {
mon.remoteCallObserved( actor, null, null, null );
Thread.sleep(1);
}
System.exit(1);
}
}