Is it possible / good idea to use Akka for multithreading in a Glassfish EAR? -


context: client server app. @ moment ejb looks like:

public class serversidejob {      @webmethod(operationname = "launchjob")     public string launchjob(@webparam(name = "iduser") string iduser, @webparam(name = "name") string name, @webparam(name = "param") object param) {          runnable controller = new jobcontroller(screenname, fof, mm, job);         new thread(controller).start();         return "job launched";     } } 

the job launching several other threads.

at point, i'd add possibility client interrupt job. interrupting thread "the outside" quite a dirty affair (i'd have add many more calls per op db that), , prompts me switch akka multithreading.

problem: not sure how / if can merge akka logic code of ejb above. how call top actor of hierarchy launchjob function? (ok, surely noob question...)

public class serversidejob {      @webmethod(operationname = "launchjob")     public string launchjob(@webparam(name = "iduser") string iduser, @webparam(name = "name") string name, @webparam(name = "param") object param) {  //how call akka actor here?         return "job launched";     } } 

that indeed noob question. did not know how because, following "hello world" example on akka.io, app launched without actorsystem ignored it. actorsystem need:

one class actorsystem, launched @ start @ app:

@singleton @startup // initialize @ deployment time instead of first invocation  public class sharedactorsystem {      actorsystem system;      @postconstruct     void loadconfiguration() {         system = actorsystem.create("systemjobs");     }      public actorsystem getsystem() {         return system;     } } 

and class server side job:

    public class serversidejob {      @ejb     sharedactorsystem sharedactorsystem;      @webmethod(operationname = "launchjob")     public string launchjob(@webparam(name = "iduser") string iduser) {      //getting actorsystem      actorsystem system = sharedactorsystem.getsystem();     final actorref myactor = system.actorof(props.create(myactor.class));    msglaunchactor msg = new msglaunchactor(iduser);    myactor.tell(msg, actorref.nosender());    return "job launched";    } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -