Errai
  1. Errai
  2. ERRAI-293

Ability to batch/chain rpc service requests to server

    Details

    • Type: Feature Request Feature Request
    • Status: Closed Closed (View Workflow)
    • Priority: Major Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ErraiBus
    • Labels:
    • Similar Issues:
      Show 10 results 

      Description

      One of the nice features of the RequestFactory framework is to chain requests together before sending them to the server. The use cases for this type of requirement are numerous. For example, a "page" can be provided modules which are each responsible for loading their own component. A Single request can be passed into the module and the module can append its service calls. The entire request is either passed/failed together.

      Advantages:

      • Keeps the Service API clean and simple, rather than creating specific methods/response beans to handle the loading requirements for a particular page view.
      • Moves Errai further along towards erasing the line between client and server (I believe). This is a more natural way of programming, and makes the asynchronous nature less of a burden

      Workaround:

      • Create specific method calls for complex loading requirements OR
      • chain the requests, with each subsequent request only occurring once the first one is finished. This is more unnatural for the developer.

      I've put together a sample, which is purely for informational purposes of how something like this could look:

      public class ChainedCaller {
      
      	@Inject BatchCaller batchCaller;
      
      	@Inject Caller<Service1> service1;
      	@Inject Caller<Service2> service2;
      	
      	public ChainedCaller() {
      
      		
      		batchCaller.batch(service1.call( responseHandler1 ).method1() );
      		batchCaller.batch(service2.call( responseHandler2 ).method2() );
      		
      		batchCaller.callBatch( responsehandler3 );
      	}
      }
      

        Activity

        Hide
        Christian Sadilek
        added a comment - - edited

        RPC batching is implemented now. The current API looks as follows:

        public class MyBean {
        
          @Inject BatchCaller batchCaller;
        
          public MyBean() {
            batchCaller.call(remoteCallback1, RemoteService1.class).method1();
            batchCaller.call(remoteCallback2, RemoteService2.class).method2();
        
            batchCaller.sendBatch();
            //batchCaller.sendBatch(remoteCallback3);
          }
        }
        

        Josh, does this meet all your needs?

        We could build a higher lever API based on your suggestion but we'd need to qualify the injected callers so they know that they're in batch mode.

        public class ChainedCaller {
        
          @Inject BatchCaller batchCaller;
        
          @Inject @Batched Caller<Service1> service1;
          @Inject @Batched Caller<Service2> service2;
        
          public ChainedCaller() {
        
            batchCaller.batch(service1).call(responseHandler1).method1();
            batchCaller.batch(service2).call(responseHandler2).method2();
        		
            batchCaller.sendBatch();
            //batchCaller.sendBatch(remoteCallback3);
          }
        }
        

        I am not sure if the latter API is required since it is not really shorter or more expressive.

        Show
        Christian Sadilek
        added a comment - - edited RPC batching is implemented now. The current API looks as follows: public class MyBean { @Inject BatchCaller batchCaller; public MyBean() { batchCaller.call(remoteCallback1, RemoteService1.class).method1(); batchCaller.call(remoteCallback2, RemoteService2.class).method2(); batchCaller.sendBatch(); //batchCaller.sendBatch(remoteCallback3); } } Josh, does this meet all your needs? We could build a higher lever API based on your suggestion but we'd need to qualify the injected callers so they know that they're in batch mode. public class ChainedCaller { @Inject BatchCaller batchCaller; @Inject @Batched Caller<Service1> service1; @Inject @Batched Caller<Service2> service2; public ChainedCaller() { batchCaller.batch(service1).call(responseHandler1).method1(); batchCaller.batch(service2).call(responseHandler2).method2(); batchCaller.sendBatch(); //batchCaller.sendBatch(remoteCallback3); } } I am not sure if the latter API is required since it is not really shorter or more expressive.
        Hide
        Josh B
        added a comment -

        Christian,

        This is FANTASTIC. As I said, your implementation is actually quite a bit more elegant than my proposal. I think we can think a little more about the name of the two methods (call/endBatch). I would vote more for something like "batch" and "call/execute", but I leave it to the errai team to figure it out (obviously). Thanks so much, this will be put to good use.

        Show
        Josh B
        added a comment - Christian, This is FANTASTIC. As I said, your implementation is actually quite a bit more elegant than my proposal. I think we can think a little more about the name of the two methods (call/endBatch). I would vote more for something like "batch" and "call/execute", but I leave it to the errai team to figure it out (obviously). Thanks so much, this will be put to good use.

          People

          • Assignee:
            Christian Sadilek
            Reporter:
            Josh B
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: