3 Replies Latest reply on Nov 22, 2009 1:23 PM by lvdberg

    Need help, new to seam

    krzyswi

      Hello!


      I'm new to Seam, I'm looking for a solution to the following problem. I have to create a sort of a daemon process, that will awaken on a certain event and do some stuff, then go to sleep again. There has to be only one instance of this process running, if an event is risen when this process is active, nothing happens. In pure Java I'd create a thread that sleeps until notified to awaken and do its job, than fall asleep again. How do I do something like this in Seam? I heard, that doing it the old way is not the correct way.


      I'm looking for suggestions on which mechanism to use (events maybe or something else?), or an example maybe?


      Thanks for your help in advance,
      K.

        • 1. Re: Need help, new to seam
          lvdberg

          Hi,


          You have to look at two things to solve your problem. First you need an Application-Scoped bean which run as a type of singleton process. Next you need to look at the Observer pattern, which is implemented as a Observer annotation on the method you want to call. This methods get called when you raise an event in your application, which can be done with the Events component.


          These things are very good explained in the Seam documentation. If that isn' clear enough don't hesitate to ask


          Leo

          • 2. Re: Need help, new to seam
            krzyswi

            Hi,


            Thanks, events was the first thing that came to my mind, but as far as I know, whenever an event is thrown the observer is fired, isn't it? What I want to do is to wait for a signal, then do my processing, then wait again. If multiple events are risen, my observer will be fired several times in parallel won't it? Maybe there's a way to define an event in such a way, that when this event is already risen and being handled, rising it again does nothing?


            K.

            • 3. Re: Need help, new to seam
              lvdberg

              You can use timeevent, meaning after firing the event it will start a timer process. What you can do is use two different methods on one bean each with a specific event signatuse.