*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes PetStore EJBControllerLocalEJB ...Why is it used.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "PetStore EJBControllerLocalEJB ...Why is it used.." Watch "PetStore EJBControllerLocalEJB ...Why is it used.." New topic
Author

PetStore EJBControllerLocalEJB ...Why is it used..

Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
Can some who has really gone thru Pet store application explain me what advantage this component has. (EJBControllerLocalEJB)
IMO .. (And I may be wrong). It provides a resource usability where many state machines can be instantiated at the App server startup .
Going thru the code ... I couldnt figure a real use for EJB in this context. It could just as well have been implemented as a POJO . and eveyr POJO could have been doing the same thing in its contructor.

Any comments any one..

I am still trying to figure out some details of the EJB controller and how it ties up with invoking EJB actions. I would appreciate any help in this regards to help me continue with my assignment.
Thanks
Dhiren
Ganesh Krishnan
Ranch Hand

Joined: Sep 28, 2004
Posts: 42
Dhiren,

It is a stateful session bean and ensures that the StateMachine is independent for each client. Also note that the methods in StateMachine are synchronized.
Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
Thanks Ganesh,

It is a stateful session bean and ensures that the StateMachine is independent for each client. Also note that the methods in StateMachine are synchronized.


When you say the methods are synchronized .. Which methosd are you referring to .. The methods in EJB Actions ?
The state machine simpy invokes the EJB Actions.
As far State machine being independent of other clients a Request processor could instantiate a POJO for the controller. Yes that is memory extensive and so I can only think that as a reason for implementing this component as an EJB.

Also I could not see the state machine having synched code..
Please clarify.
Thanks

Dhiren
Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
Ganesh,
I did further code work through Pet store and this is what I have found.

The web controller has synchronized methods.
The handle event called on the web controller by the request processor calls this. So is this the synchronization methods u were referring to ?
infact this now brings more doubts as to why the entire EJB controller is under a synch block.
public synchronized EventResponse handleEvent(Event ev, HttpSession session) throws EventException {
DefaultComponentManager cm = (DefaultComponentManager)session.getAttribute(WebKeys.COMPONENT_MANAGER);
EJBControllerLocal controllerEJB =cm.getEJBController(session);
return controllerEJB.processEvent(ev);


Only this could suffice to be a synched block though it hardly matters. Why would a ComponentManager need to be in synch block.


EJBControllerLocal controllerEJB =cm.getEJBController(session);
return controllerEJB.processEvent(ev);

Ganesh I may have misinterpretted this archictecture implementation hence all the wrong inferences so please correct me in my assumptions.
Thanks
Dhiren
Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
someone please reply. I am not getting any responses for any petstore architecture questions ... Resurrecting this thread...
Thanks
Dhiren
Ganesh Krishnan
Ranch Hand

Joined: Sep 28, 2004
Posts: 42
Dhiren,
Sorry I was out for couple of weeks so couldn't respond to your thread earlier. Yep, I mistakenly specified that the Synchronized method were available in StateMachine instead of WebController.

Actually I thought of mentioning to note that WebController.handleEvent method is synchronized which feeds the StateMachine via EJBController and misquoted it.

Both the EJBController and WebController acts as a proxy to EJB-Tier and Web-Tier respectively. According to blueprints the suggested method to store the session is via Stateful Session Bean. The EJBController is also used for the same. You can also find the ShoppingControllerEJB extending the EJBController to do the module specific operation.

Hope it gives some useful information to you.

Ganesh.
Josep Andreas
Ranch Hand

Joined: Jan 09, 2005
Posts: 90
Dhiren,
I seem to be following the same path as you and deepak..
I'am studying the petstore example now. I have a question that you might be able to answer.
In the petsore application, the state machine is a separate class from the ejbcontroller. Do you know the reason for this? I was thinking of using en ejbcontroller without the statemachine. The logic could be refactored into the controller itself.

Regards,
J
Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463

In the petsore application, the state machine is a separate class from the ejbcontroller. Do you know the reason for this? I was thinking of using en ejbcontroller without the statemachine. The logic could be refactored into the controller itself.


the state machine is really the caching mechanism also the statemechine is the real implementation of the application service pattern. Only if u have a statemachine type of class referenced from the ejb controller can u create EJBAction classes.

Look at the processEvent method of Statemachine ,that gets called by the ejbController and is the actual entry point to any business tier call getting called from the EJB controller.


The logic may be refractored in the controller


The controller is a SFSB, and StateMachine is a caching object. Keeping them separate is a good practice. gives cleaner code and readability. I dont see any other reason for doing what Petstore did.


HTH
Dhiren
[ January 20, 2005: Message edited by: Dhiren Joshi ]
Josep Andreas
Ranch Hand

Joined: Jan 09, 2005
Posts: 90
With respect to the ejbcontroller.

1. The most complete picture is here:
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/app-arch/app-arch5.html
(Access to ejb-tier for View is via BD/Facade; Access to ejb-tier for Model-update(command/events) via Event/EJBController)
(I cannot find an example where this option is used in reality); I think this option is an overkill for this assignment

2.On the sun site, there are two (almost identical) variations on this concept; The most noticable change is that the only access to the ejb-tier is via webController-ejbController (Both for view and model update)
It is here:
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/sample-app/sample-app1.3.1a3.html
(Figure 14)

and here:

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/sample_application/mvc/index.html
I like the second the most, especially because it is very well documented!!
, here: http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/sample_application/controller/index.html

What I understand from this second example;
A: The view related actions are executed from the ejbController directly.
(sort of a facade.....); e.g. getOrders
B: The commands on the model are forwarded to the state machine; that translates the actions; and performs the operations on the model.

But what really, really, really bugs me ( ) is the fact that in the diagram, there is no relation between the statemachine and the Model??
How is this possible? The statemachine clearly executes operations to the Model.
All the sources are here:
http://java.sun.com/blueprints/code/jps10/src/com.sun.estore.control.ejb.index.html

Does anyone have a clue?
Thanks again,
J
============================
Just read some other threads on this issue;
You could also forget the ejbcontroller and just go for the solution in Cade's guide:
-> Have a controller per session facade and use a singleton service locator
(maybe throw in a business delegate).
They also got good scores on this.....
[ January 23, 2005: Message edited by: Josep Andreas ]
Josep Andreas
Ranch Hand

Joined: Jan 09, 2005
Posts: 90
In the large 'Parag-Thread' is also a message about the use of the ejbcontroller:

quote
=================================================================
I didnt follow the petstore (I found it too complicated for this assignment) or struts, though mine was a simplified version of struts where the front controller talks to request handlers who talks to business delegate. The request handlers were quite similar to the action classes, though I didnt show any Action Forms, Beans etc.

quote:
Did you use EJBController, or the Front Controller talks to the business delegate? Did you use one gigantic business delegate, or several (one for each session facade)? Or the web clients and application clients use seperate delegate?

I used the Front controller for the web tier. It communicated with a web based implementation of the business delegate and my swing client communicated with a standalone client based implementation of the business delegate. Both the clients used different implementation of business delegate. The swing client communicated directly with the ejb tier (via the swing business delegate). I had only 1 business delegate (it didnt end up looking very gigantic as the methods were pretty coarse grained) per client, but several session facades.
=================
unqoute

Looks like Parag only used the BD/Facade for acess webtier-ejbtier..
The requestHandler sits in between the Frontcontroller
and the 1 Business delegate...
[ January 23, 2005: Message edited by: Josep Andreas ]
Deepak Pant
Ranch Hand

Joined: Feb 13, 2004
Posts: 443
Josep,

Just to share I am following a similar design like Parag.
BD-->SF-->AS-->BO-->DAO

I feel that EJBController mechanism complicates and confuses the whole picture. Creation/Mapping of events, additional layer of Command like objects in between Controller and actual ejb layer etc etc.

It is always recommended to make the Web Tier controller driven. But I have not seeen lot of references where controller has been put right in the EJB Tier.

There is a reference in "EJB Design Pattern" book by Floyd Marinescu about not using Command pattern in the EJB Tier. The author suggests having Command Pattern in EJB Tier is not maintainable.

Hope this helps !!!

Deepak
Josep Andreas
Ranch Hand

Joined: Jan 09, 2005
Posts: 90
Deepak,
Yes, thanks helps lot.
I did not change my class diagram for two days now (Yes!),
so I am realy getting into the component diagram and designing the web-tier now.
With respect to your design, Do you still use a requestProcessor,Screenflowmanager..?
Do you use multiple Controllers/servlets (Just as in Cade's guide)?
And did you show the requestHandler in the sequence diagram or just the controllers? (Just as in Cade's Guide)
Thanks,J

[ January 24, 2005: Message edited by: Josep Andreas ]
[ January 24, 2005: Message edited by: Josep Andreas ]
Deepak Pant
Ranch Hand

Joined: Feb 13, 2004
Posts: 443
Originally posted by Josep Andreas:
Deepak,
With respect to your design, Do you still use a requestProcessor,Screenflowmanager..?
Do you use multiple Controllers/servlets (Just as in Cade's guide)?
And did you show the requestHandler in the sequence diagram or just the controllers? (Just as in Cade's Guide)
Thanks,J


(a) Yes I have a FrontController and ApplicationController (same as RequestProcessor of struts) for Web Tier. No special ScreenFlowManager, this responsibility is with ApplicationController

(b) As far as Servlet is concerned, there is only 1 servlet.

(c) No FrontController, ApplicationController, ServiceLocator etc are not in use specific sequence diagram. I have one top level diagram, which depicts these classes in one seq diagram
Josep Andreas
Ranch Hand

Joined: Jan 09, 2005
Posts: 90
Thanks for the quick reply,
I was looking for some documentation of the Application COntroller,
But could not find any. The description on j2eedesignpatterns.com looked promising to me, but is very basic:
http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationController.htm

This seems to be a fairly new pattern; it is not in my books on patterns. DO you know of an online example?
I was thinking of buying second edition of:
http://www.amazon.com/exec/obidos/ASIN/0131422464/corej2eepatte-20/102-5313107-3482507
thanks,J
Deepak Pant
Ranch Hand

Joined: Feb 13, 2004
Posts: 443
Yes you are correct ApplicationController is a new design pattern and was published in Core J2EE Patterns 2nd Edition.

In Struts 1.1: The main servlet ActionServlet is an implementation of FrontController and RequestProcessor is an implementation of ApplicationController.

The RequestProcessor has lot of responsibilities like CommandFactory, ViewFactory, CommandProcessing, ViewDelegation.

This is the reason I am following this approach in my design.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PetStore EJBControllerLocalEJB ...Why is it used..
 
Similar Threads
EJB is making me dizzy
How to start with entity bean
pojo into ejb & web services
How to change Java Classpath Context
JSP calling POJO - Synchronization question