Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Executer implements Runnable{
- @Override
- public void run(){
- // Here will be the backend-method invocation for firing CDI-Events
- // CDI-Dummy-Event - Does not fire properly. receiveStatusEvent() does not invoke
- BeanManager beanManager = CDI.current().getBeanManager();
- beanManager.fireEvent(new ResultEvent("Result event example"));
- }
- }
- public class EventReceiver implements LoggingProvider{
- public EventReceiver(){
- }
- public void receiveStatusEvent(@Observes ResultEvent event) {
- this.info("Event received: " + event.toString());
- }
- }
- public void executeAsynchBackendMethod(){
- // CDI-Dummy-Event works - receiveStatusEvent() invokes correctly
- BeanManager beanManager = CDI.current().getBeanManager();
- beanManager.fireEvent(new ResultEvent("Result event example"));
- /* The following alternative starts a thread, but the events, which are fired in the run() method, do not take any action in the receiveStatusEvent() method */
- // Getting managedExecuterService
- this.managedExecuterService = (ManagedExecutorService) new InitialContext().lookup("java:comp/DefaultManagedExecutorService");
- // Getting Instance of executer-Runnable (for injecting the backend-service afterwards)
- Instance<Executer> executerInstance = CDI.current().select(Executer.class);
- Executer executer = workflowExecuterInstance.get();
- // Start thread
- this.managedExecuterService.submit(executer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement