[akka-user] Integration test for actor with router created in the constructor
Hi all, I have an actor which in the constructor creates a router actor which creates several workers. Also, in that actor, it creates an actor do so some separate stuff, so the structure is like: actor router -- a bunch of workers listener As said, router and listener are created in the constructor of the leftmost actor. I want to do some integration test on the leftmost actor, how to do that? I would like to use JavaTestKit. Thanks! George -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
[akka-user] Re: akka system shutdown in sub actor
Ok, thanks Jim. Can I ask another question, if I shutdown akka in one of the actor (getContext().system().shutdown()), what is the behavior? Thanks! George On Friday, 27 February 2015 13:32:51 UTC+8, Jim Hazen wrote: Seems logical. From an actor within a running system you ask the system if it's dead. It says no, because it still has actors running (there's at least the one asking the question). Then, from outside the system you wait for it to terminate, and then check that it has terminated, which it confirms to be true. -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
[akka-user] Akka SupervisorStrategy strange behavior
Dear all, For learning Akka, I wrote below in Java to test fault-tolerance. I have a master actor to assign job to worker actors, in the master actor, simply divide the job into several pieces and use round robin router to assign to workers (i.e. let workers add slices of a summation). In the worker onReceive, I let the first worker who does its job to throw an Exception, please consider below code: WorkerActor/onReceive: if(RetryCount =1 ) { RetryCount--; throw new Exception(exception thrown from worker); } WorkerActor/preRestart: public void preRestart(Throwable cause, OptionObject msg) { System.out.println(Thread +Thread.currentThread().getId()+ get restart message ); if(cause instanceof Exception msg.nonEmpty()) { WorkerMessage workerMsg = (WorkerMessage)msg.get(); getSelf().forward(workerMsg, getContext()); //getSelf().tell(workerMsg, getSender()); } else { return; } } For the master actor: router = getContext().actorOf( Props.create(WorkerActor.class).withRouter( new RoundRobinRouter(10))); private static SupervisorStrategy strategy = new OneForOneStrategy(10, Duration.create(1, TimeUnit.MINUTES), new FunctionThrowable, Directive() { public Directive apply(Throwable exception) throws Exception { if (exception instanceof Exception) { return SupervisorStrategy.restart(); } else { return SupervisorStrategy.escalate(); } } }); @Override public SupervisorStrategy supervisorStrategy() { return strategy; } I have 10 workers running and tasks assigned in round-robin algorithm, after running the example, the restart run as expected, but I have several questions: 1) All 10 workers' preRestart get called, why is that, is that correct as I used OneForOneStrategy and I thrown exception only from one worker? I use the msg.nonEmpty() to get rid of those null msg passed in as from my running result, all 10 workers run the preRestart which I am quite confused. 2) After one worker forwards the message, another worker receives the message and re-process it, they are not the same thread, is that correct? Thread 11 processing worker 1 Thread 11 throw exception Thread 18 processing worker 1 From the output, thread 11 throw exception and thread 18 process later for fail-over. From understanding, if one child actor failed, then parent actor should invoke that child actor's preRestart method only, not for all child actors. Is that correct? Thanks in advance! Regards, George -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
[akka-user] Akka threads prevents jvm from existing
Dear all, I searched on Google but cannot find any similar topics. I am a Akka newbie and used Akka to start some workers to process time consuming tasks. I used system.AwaitTermination() and system.shutdown() to shutdown Akka. My Akka used RoundRobinRouter and schedules 10 workers. But, the JVM does not exit. Then I print all running threads. MapThread, StackTraceElement[] threads = Thread.getAllStackTraces(); for(Thread t:threads.keySet()){ System.out.println(); System.out.println(t.getId()+:+t.getName()+ is daemon:+t.isDaemon()); for(StackTraceElement stackTrace: threads.get(t)){ System.out.println(stackTrace.getFileName()); System.out.println(stackTrace.getClassName()); System.out.println(stackTrace.getMethodName()); System.out.println(stackTrace.isNativeMethod()); } System.out.println(); } The following is the output. Can anyone give me any hint whether is Akka prevent the JVM from exiting and if it is, how to prevent that? Thanks! George 2:Reference Handler is daemon:true Object.java java.lang.Object wait true Object.java java.lang.Object wait false Reference.java java.lang.ref.Reference$ReferenceHandler run false 27:CreationSystem-akka.actor.default-dispatcher-6 is daemon:false Unsafe.java sun.misc.Unsafe park true ForkJoinPool.java scala.concurrent.forkjoin.ForkJoinPool idleAwaitWork false ForkJoinPool.java scala.concurrent.forkjoin.ForkJoinPool scan false ForkJoinPool.java scala.concurrent.forkjoin.ForkJoinPool runWorker false ForkJoinWorkerThread.java scala.concurrent.forkjoin.ForkJoinWorkerThread run false 20:pool-3-thread-1 is daemon:false Unsafe.java sun.misc.Unsafe park true LockSupport.java java.util.concurrent.locks.LockSupport park false AbstractQueuedSynchronizer.java java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject await false ScheduledThreadPoolExecutor.java java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue take false ScheduledThreadPoolExecutor.java java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue take false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor getTask false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor runWorker false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor$Worker run false Thread.java java.lang.Thread run false 18:CreationSystem-akka.actor.default-dispatcher-4 is daemon:false Unsafe.java sun.misc.Unsafe park true ForkJoinPool.java scala.concurrent.forkjoin.ForkJoinPool scan false ForkJoinPool.java scala.concurrent.forkjoin.ForkJoinPool runWorker false ForkJoinWorkerThread.java scala.concurrent.forkjoin.ForkJoinWorkerThread run false 12:C3P0PooledConnectionPoolManager[identityToken-1hge24797149gw291ezhx58|6badc6a5]-HelperThread-#0 is daemon:true Object.java java.lang.Object wait true ThreadPoolAsynchronousRunner.java com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread run false 22:pool-3-thread-3 is daemon:false Unsafe.java sun.misc.Unsafe park true LockSupport.java java.util.concurrent.locks.LockSupport park false AbstractQueuedSynchronizer.java java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject await false ScheduledThreadPoolExecutor.java java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue take false ScheduledThreadPoolExecutor.java java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue take false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor getTask false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor runWorker false ThreadPoolExecutor.java java.util.concurrent.ThreadPoolExecutor$Worker run false Thread.java java.lang.Thread run false 28:Keep-Alive-Timer is daemon:true Thread.java java.lang.Thread sleep true KeepAliveCache.java sun.net.www.http.KeepAliveCache run false Thread.java java.lang.Thread run false 4:Signal Dispatcher is daemon:true
[akka-user] Re: Question on background thread which invoke Akka on single machine
Thanks Patrik! On Friday, 13 February 2015 10:05:28 UTC+8, George Lu wrote: Dear all, I have a background thread pool which read messages from a queue and invokes Akka system in a single node (actually several nodes which reads from the single queue, but each node will have Akka of its own, no distributed execution environment). Ideally, my background thread only read message and invoke Akka on the single node, after that, the background will back to thread pool. I am afraid that after the background thread return to thread pool, will the akka system be garbage collected? As in my current code, I use AwaitTermination in the background thread after I send the message to mater. Do I need to invoke AwaitTermination, if I don't invoke this, is it for sure that akka will finish all the task if no exception are thrown? Thanks! Regards, George -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.