Jorb's jorbs is to make your asynchronous job processing life easier.
Create a context
import org.gaffo.jorb.pico.PicoContainerContext; import org.gaffo.jorb.hornetq.HornetQ; // ... IContext context = new PicoContainerContext(); IQueue queue = new HornetQ("queueName", 3 /* threads */, context);
Next add implementations to the context for any of the classes that your jorbs are going to need to do their work.
IUserProvider userProvider = new UserProvider(); // example class, use your own context.register(userProvider);
Make a job class.
- Make any fields you need to do your job as fields, so that they can be serialized.
- Also make a process method. It can take any # of parameters except just a context. All of the parameters will be populated by the context you created above.
class MyJob extends ACH { public String username; public MyJob(String username) { this.username = username; } public void process(UserProvider userProvider) { // Example work User user = userProvider.findUserByUsername(username); user.notify(); } }
Now queue up your work and it'll be executed:
queue.enqueue(new Job("gaffo"));