5 Replies Latest reply on Nov 6, 2007 10:02 PM by dcowan

    Starting Threads and Socket listeners

    dcowan

      I'm trying to determine the best method to integrate a legacy protocol that starts Threads that listen on ServerSockets within a seam application. I have considered writing an MBean wrapper, but haven't really determined the most appropriate method. My legacy protocol start several threads that listen on sockets to communicate to legacy clients that need to send and receive data that I would like to use existing seam beans for. Can someone suggest some ideas of how to handle this. I thought about application scoped beans but that doesn't seem like the proper way to do it either.

      Thanks for any advice

        • 1. Re: Starting Threads and Socket listeners
          dcowan

          I did some research on this and was wondering what peoples thoughts on using a Resource Adapter to do this or is there a more general way to do it in seam. My sockets that listen need to access my beans in a synchronous manner so mdb's are out.

          • 2. Re: Starting Threads and Socket listeners
            dhinojosa

            You can't call a session bean remotely and invoke it from your client? Doing that is synchronous.

            • 3. Re: Starting Threads and Socket listeners
              pmuir

              The normal approach here is to write a JCA adaptor. But this does require an endpoint in your application. Another option is to use the Seam Manager component pattern (@Unwrap).

              Dan's approach also seesm good to me.

              • 4. Re: Starting Threads and Socket listeners
                dcowan

                I currently use an application scoped bean to start the Socket listener so using the Seam Manager compenent sounds like a good option. If I used that would Threads created from the socket threads be able to call the manager in the context of a transaction?

                • 5. Re: Starting Threads and Socket listeners
                  dcowan

                  For anyone that stumbles upon this I solved this by using Lifecycle.beginCall within my callback method


                  Lifecycle.beginCall();
                  
                  try {
                   IEventDataService eventDataService = (IEventDataService) Component.getInstance("eventDataService", true);
                   eventDataService.createEventData(eventData.getDevice().getIdentifier(), eventData);
                   Lifecycle.endCall();
                  
                  } catch (Exception ex) {
                   ex.printStackTrace();
                  }