jeudi 19 août 2021

Design help for execution flow of a java method

I'm stuck in a tricky situation here and not able to figure out how I can design this flow. Below is the sample code of what I'm trying to do.

class Service {
 
    private boolean wait = true;
    private boolean result;

    public void doSomething() {
        callExternalRestAPI()  // This API will send a callback to my app which will be received in the controller 
        while(wait) {} // Pause execution flow until callback is received
        print(result); // Execution will resume here 

    }

    public void callbackReceived(boolean result) {
        this.result = result;
        wait = false;
    }

}

class Controller {

    private Service instance; // Don't know how to initialize this instance

    @GetMapping("/{isInternalUser}")
    public void getCallback(@PathVariable("isInternalUser") boolean isInternalUser) {
        instance.callbackReceived(isInternalUser);
    }
}

I understand I need to send the current instance of the Service class to the Controller class but I am not sure how I can do this. If anyone has any suggestions that would be really appreciated.

Aucun commentaire:

Enregistrer un commentaire