Results 1 to 4 of 4

Thread: Is there a spring equivalent to the EJB Observer Pattern?

  1. #1
    Join Date
    Sep 2004
    Posts
    346

    Default Is there a spring equivalent to the EJB Observer Pattern?

    I basically would like that a service method fire events related to what was inserted, updated or deleted in the DAO layer and any other arbritrary events I might fire explicitly in my service layer. These events should somehow be available in my caller. So the code would be like

    Caller:

    serviceInstance.addListener(eventListener);
    serviceInstance.doSomething();
    if (eventListener.isEvent1Fired()) {
    ...
    }

    } finally {
    serviceInstance.removeListener(eventListener);
    }


    ServiceInstance:
    void doSomeThing() {
    fireEvent1();
    }


    Haven't specified in full the interface. But hopefully one of you will get the idea and let me know if there is a similar thing is Spring that is available for doing this sort of thing.

    Thanks,
    Garry

    EJB Observer Pattern
    This article explains how to implement the observer pattern in a suite of integrated EJB apps. The suite has a shared repository and each EJB application has it own repository. Every application in the suite runs on a separate host. Each application needs to observe changes in the shared repository as they occur -- and within the transaction in which they occur. If a proposed change to the shared data is unacceptable to any given application then the transaction must be aborted before the change is made permanent.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    You should be able to use a combination of Spring AOP (to capture and fire events without code duplication) and the event publication method oof a Spring ApplicationContext to do this. See EventPublicationInterceptor as a starting point.

    Without a URL, it's hard to comment on the article. It sounds like it's not EJB specific. If you need to propagate events around a cluster, you should look at JMS. You could have a listener that fires Spring application context events to a JMS queue.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Sep 2004
    Posts
    346

    Default I looked for an example but I can't find any.

    I looked for an example but I can't find any. Could you provide an example of how best to accomplish this in a Spring way?

    Basically what I want to accomplish is the best pattern for the following:

    1) Struts Action-> calls Spring Transaction Proxied Service Method
    2) need feedback in struts action about events (successes and errors) that occured in Service Method. Also the service could have derived a value or multiple values which need to be passed back to the client in request attributes.

    For instance

    struts action:
    service method:
    Listener quantityNotificationListener = new QuantityNotificationListener();
    getWebApplicationContext()
    .registerNotificationListener(quantityNotification Listener);
    Listener eventListener = new EventListener
    getWebApplicationContext()
    .registerEventListener(eventListener);

    processOrder(orderId,orderName,orderQuantity);
    // now some through WebApplicationContext
    // action is aware of fired events and fired notifications i.e:
    request.setAttribute("NEW_QUANTITY", quantityNotificationListener.getNotificationObject ());
    addMessages to ActionMessages based on events fired

    service method:
    processOrder(orderId,orderQuantity) {
    try {
    Order order = getOrderFromSupply(orderId,orderQuantity);
    } catch (OrderNotAvailableException e) {
    fireEvent(new OrderNotAvailableEvent());
    try {
    savebackOrder(orderId,orderQuantity);
    } catch (OrderDiscontinuedException e) {
    fireEvent(new OrderDiscontinuedEvent());
    }
    completeOrder(order);
    fireNotify(new QuantityNotification());
    fireEvent(new OrderCompletedEvent());
    }



    }

  4. #4
    Join Date
    Sep 2004
    Posts
    346

    Default You'd asked article about the Publisher-Observer wrt EJB

    I think the following is a pretty good article to illustrate the programming issues I'm trying to address.

    http://www.javaworld.com/javaworld/j...avatip110.html

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 11
    Last Post: Jun 1st, 2006, 04:30 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Spring Rich Client and the HMVC Pattern
    By cyboc in forum Swing
    Replies: 0
    Last Post: Oct 14th, 2004, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •