2 Replies Latest reply on Nov 22, 2012 1:54 AM by Jonas Zuberbuehler

    Notify single client after long running RPC

    Jonas Zuberbuehler Newbie

      Hey guys


      We have the following situation: Client makes a RPC service call in which we need to process lots of data in order to check whether further actions need to be undertaken or not. Since the calculation should be transparent for the user we do the processing asynchronously in a separate thread and let the RPC return before the outcome of the calculations is clear. If further actions are needed we somehow would like to inform the client that initiated the RPC. Firing an event and catching it via @Observes won't do the trick obviously because the event is being broadcasted. I guess using @Conversational won't help either (assumed I got that right) since the conversation has to be initiated with an event.


      I had the idea of storing the session id of the incoming RPC and to use it after the processing is done to push a message to it. But I'm not sure if that's ever gonna work, therefore I decided to ask you guys first if it's possible to solve the scenario described.


      Any help appreciated!




        • 1. Re: Notify single client after long running RPC
          Jonathan Fuerth Master

          Hi Jonas,


          What about making the RPC method synchronous? Then you can return the "further actions needed/not needed" status code simply with a return statement in the RPC method. This will save you the trouble of managing a thread pool on the server side, which is a bit of a no-no in Java EE anyway.


          In either case, the call site on the client is always asynchronous. It doesn't matter how long it takes to respond to a message on the server--the client always receives the result in a callback.


          Hope that helps!



          • 2. Re: Notify single client after long running RPC
            Jonas Zuberbuehler Newbie

            Thanks for your answer Jonathan


            Of course we are not managing a thread pool on our own, I was refering to @Asynchronous (javax.ejb), sorry I wasn't clear.


            The use case is the following: the initial RPC is for composing and sending a mail, thus the service returns whether the mail was successfully sent or not. As a new requirement the sent mail must now be processed to check if further actions are needed. I decided to not change the mailing components (I think it's not their responsibility to do the processing and the service should alwas return whether the mail was sent or not) and instead introduced a MailSentEvent that is fired after the mail is gone and dispatched in a @Asynchronous method (in which the processing is done, i.e., creating several documents). I'm wondering now if it is possible to notify the client that initiated the mail sending about 'The document xy has been created'.


            Hope that clarifies my question.