4 Replies Latest reply on Jun 17, 2008 3:28 PM by mkiel

    Application Scoped Service layer

    mtorres

      Hi,


      I'm new to seam and I'm coming from a spring background. I'm trying to fill in some gaps between the concepts I'm used to in Spring and the new concepts introduced by Seam.


      My question pertains to application scoped service layer. What's the best way to implement these stateless components in seam fashion?


      I realized from reading the reference manual that something like  the code below can cause synchronization issues.


      @Name(userService)
      @AutoCreate
      @Scope(ScopeType.APPLICATION)
      public class UserServiceImpl implements UserService {
           @In
           private Session bookingDatabase;


      ...


      I dont think using @Synchronized is the right approach because it may have a negative and significant impact on performance.


      What's a good approach to implementing such components? Are singletons components for this kind of scenario out of the question? I also want conversations to work transparently within this service layer. I'm currently trying to stay out of the J2EE container, so the setup is hibernate, and mostly pojo action and service layer.


      Any insight to this will be much appreciated.

        • 1. Re: Application Scoped Service layer
          mkiel

          Seam also features a stateless scope which you should probably use for your service layer:


          @Scope(ScopeType.STATELESS)
          



          As far as I know, stateless JavaBean components in Seam are pooled just like stateless EJB session beans are, so every caller gets his own instance. That means synchronization is not necessary and there are no performance issues.

          • 2. Re: Application Scoped Service layer
            diegocoronel

            Hey,


            Is it a good approach make my facade and my DAOs stateless seam components? is there any problem ?

            • 3. Re: Application Scoped Service layer
              barbacena

              Hi Mark,


              I had your problem before and asked myself exactly the same questions :D. I was hoping to have something like stateless singletons but there isn't. Therefore I had to switch to plain stateless beans. You can that with plain Seam components or EJB.


              But the good news are that EJB 3.1 will have the singleton scope. I don´t really know the semantics but I hope they put something good.


              • 4. Re: Application Scoped Service layer
                mkiel

                That's how I do it. On the other hand, the Seam wiki example uses event-scoped JavaBean DAOs, but they don't actually have any state. As far as I understand this, there should only be very minor differences in performance and/or memory usage. (But I am quite sure that any scope other than stateless or event should not be used for these effectively stateless components.)