Child pages
  • Story async clients for all generated sync client
Skip to end of metadata
Go to start of metadata

async clients for all generated sync client

TBD

 

 

Required Features:

  • ability to 'fire-and-forget' -> asynchronous method calls without waiting for results (optional with callback handlers).
  • call and return after - return with/out exception after max amount of time.
  • above options configurable per call/service. @MaxCallDuration
  • Multi-Request -> call multiple requests and get notified when all are ready.
  • Configurable default max call duration value for all calls.

 

Implementation Plan

  • Create a org.distributeme.generator.AsynchInterfaceGenerator which generates AsynchFooService extends FooService interface and has an additional method (..., CallHandler ... handlers) for each method.
  • Create org.distributeme.generator.AsynchStubGenerator which generates AsynchFooStub

 

Asynch StubGenerator

The synch stub should offer all the same methods as the original interface, but execute them via special synch methods. Example:

@DistributeMe
 public interface TestService extends Service {
    void sleep(long sleepTime);
 }


The corresponding asynch interface should look like: 

public interface AsynchTestService extends org.distributeme.test.asynch.TestService {
   void sleep(long sleepTime, CallBackHandler ... diMeCallBackHandlers);
}

The Stub should contain an Executor pool with a configurable number of threads. The configuration should happen at class leven (DistributeMe annotation) as well as globally in Defaults.getAsynchExecutorPoolSize().

The 'normal' implementation of the sleep method should call the asynch version and wait for results for the timeout duration. The timeout can be configured globally (Defaults.getDefaultAsynchCallTimeout()), on class level (DistributeMe annotation) or with method level annotation (@MaxAsynchCallWait or something).

public void sleep(long sleepTime){
  CallHandler handler = new PredefinedCallHandlerWeYetHaveToImplement();
  sleep(sleepTime, handler);
  handler.wait(timeout);  
} 

 

The special asynchronous method should behave a little bit differently:

public void sleep(long sleepTime, CallHandler... handlers){
   Callable c = new Callable(handers){...}
   executorService.execute(c);
   return;  
}
  

 

After successful or unsuccessful execution of original method, all CallHandlers should be called with either onSuccess or onError. 

 

CallHandler

Call handler is an interface. There are built in call handlers, but they can also be provided by the client.

 

Multi-CallHandler

MultiCall handlers are built in call handlers which allow the client to fire multiple requests (from multiple services) and wait for execution of all of them. Example:

MultiCallHandler mch = new MultiCallHandler();
service1.method1(..., mch);
service1.method2(..., mch);
service2.method1(..., mch);
mch.waitForAll(timeout);     

 

 

 

 

 

 

 

 

 

 

 

 

  • No labels