[jboss-user] [EJB3] - Event Handling between two EJB-JARs (Observer Pattern?)

Patrick M. do-not-reply at jboss.com
Wed Dec 12 06:12:39 EST 2012


Patrick M. [https://community.jboss.org/people/patsinnervoice] created the discussion

"Event Handling between two EJB-JARs (Observer Pattern?)"

To view the discussion, visit: https://community.jboss.org/message/783044#783044

--------------------------------------------------------------
Hi,

I'm new to EJB development and currently search for the best/correct way to handle events between two EJB-JARs which are in one EAR.

I tried to use the Observer Pattern. The event gets fired in BeanA but does not reach BeanB (as stated, two different EJB-JARs = two different Eclipse Projects in one Workspace / EAR).

My Code currently looks kind of like this:
@DependsOn("BeanB")
@Startup
@Singleton
@WebService
public class BeanA implements BeanARemote, BeanBLocal{ 
 
          @PersistenceContext
          private EntityManager em;
 
          @EJB
          private BeanA beanA;
 
        public void listenToReceivedEvent(@Observes ReceivedEvent events){
          Query query = em.Query("some query");
          //implementation
        }
}
 
@Singleton
public class BeanB implements BeanBLocal {
   
          @Inject
          Event<ReceivedEvent> events;
 
          public void fireEvent() {
               //implementation
               ReceivedEvent e = new ReceivedEvent(stringList);
               event.fire(e);
          }
}
 
public class ReceivedEvent  {
  
          private List<String> stringList;
  
          public ReceivedEvent(final List<String> stringList) {
                    this.stringList= stringList;
          }
 
 
          public List<String> getStrings() {
                    return stringList;
          }
}
 


Currently, when on BeanB the event is fired at BeanA nothing happens. My question now is: is the Observer Pattern the correct pattern in this case? Did I forgot something in this sample why the BeanA does not gets the event? Is the Observer Pattern made for event communication between two differen EJB-JARs? 

Thanks
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/783044#783044]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121212/26e937bd/attachment-0001.html 


More information about the jboss-user mailing list