Topic
  • 6 replies
  • Latest Post - ‏2013-01-10T22:54:59Z by SystemAdmin
WJK1_Barani_Ramakrishnan
8 Posts

Pinned topic Nested Adapter calls with onSuccess call back problem

‏2013-01-10T16:26:57Z |
Hi,

I am having problem with calling nested adapters. My situation is, Call Adapter A and then based success get output and pass to input of another another adapter and process the output in the onSuccess of Adapter A. In this case onSuccess of Adapter B is not working. It works once completion of Adapter A call back is finished.

Adapter A {

onSuccess: success
onFailure: failure
}

success(){
Call Adapter B
getResults from B
and then process with out put of A
Show Results
}

Adapter B{
onSuccess: BSuccess
onFaioure: failure
}

BSuccess(){
return output.
}
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T17:30:25Z  
    Your flow would need to work something more like this:

    Adapter A {

    onSuccess: success
    onFailure: failure
    }

    success(){
    Save output of A somehow
    Call Adapter B
    getResults from B
    and then process with out put of A
    Show Results
    }

    Adapter B{
    onSuccess: BSuccess
    onFaioure: failure
    }

    BSuccess(){
    getResults from B
    and then process with saved output of A
    Show Results
    return output.
    }
    The call to Adapter B is asynchronous - so it can take a couple milliseconds, seconds, or may even time out. The flow for your logic cannot continue until it is guaranteed that the call for adapter B is done. You need to save the result for adapter A and then when the call for B is complete, then you can proceed with using the values.
  • WJK1_Barani_Ramakrishnan
    8 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T17:53:01Z  
    Your flow would need to work something more like this:

    Adapter A {

    onSuccess: success
    onFailure: failure
    }

    success(){
    Save output of A somehow
    Call Adapter B
    getResults from B
    and then process with out put of A
    Show Results
    }

    Adapter B{
    onSuccess: BSuccess
    onFaioure: failure
    }

    BSuccess(){
    getResults from B
    and then process with saved output of A
    Show Results
    return output.
    }
    The call to Adapter B is asynchronous - so it can take a couple milliseconds, seconds, or may even time out. The flow for your logic cannot continue until it is guaranteed that the call for adapter B is done. You need to save the result for adapter A and then when the call for B is complete, then you can proceed with using the values.
    Hi,

    Thanks for your quick reply.

    As per your suggestion, I tried. After completion of Adapter A success method then called Adapter B. But it doesn't invoke onSuccess of Adapter A. Adapter B calls immediately.

    As you said, its working asynchronously.

    Still problem remains same.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T18:37:11Z  
    Hi,

    Thanks for your quick reply.

    As per your suggestion, I tried. After completion of Adapter A success method then called Adapter B. But it doesn't invoke onSuccess of Adapter A. Adapter B calls immediately.

    As you said, its working asynchronously.

    Still problem remains same.
    "After completion of Adapter A success method" .... "But it doesn't invoke onSuccess of Adapter A. Adapter B calls immediately."

    Sorry I'm a bit confused by this. Aren't you calling Adapter B inside Adapter A's onSuccess method? Maybe you can copy/paste the exact code you are using so I can have a better understanding? Or were you expecting adapter B's onSuccess method to call adapter A's on success method? It is not clear to me.
  • WJK1_Barani_Ramakrishnan
    8 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T19:57:29Z  
    "After completion of Adapter A success method" .... "But it doesn't invoke onSuccess of Adapter A. Adapter B calls immediately."

    Sorry I'm a bit confused by this. Aren't you calling Adapter B inside Adapter A's onSuccess method? Maybe you can copy/paste the exact code you are using so I can have a better understanding? Or were you expecting adapter B's onSuccess method to call adapter A's on success method? It is not clear to me.
    Sorry its my bad. it doesn't invoke onSuccess of Adapter A instead Adapter B calls
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T20:52:22Z  
    Sorry its my bad. it doesn't invoke onSuccess of Adapter A instead Adapter B calls
    This still isn't clear...

    Can you post the exact code you're using? That would give me a better idea of what you're doing.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nested Adapter calls with onSuccess call back problem

    ‏2013-01-10T22:54:59Z  
    Sorry its my bad. it doesn't invoke onSuccess of Adapter A instead Adapter B calls
    I'm not sure what is the issue and why you are experiencing this problem, but I can follow up on some previous posts and give you few hints how adapter invocation works.
    All client adapter invocation calls are asynchronous.
    To perform nested adapter calls (ie. first adapter A and than adapter B) you need to invoke second adapter from within success method of the first adapter invocation.

    Example:

    /********************/
    function successB(result){
    WL.Logger.debug("success B");
    /* process response from adapter B */
    ...
    }
    function failureB(result){
    WL.Logger.error("Failure B");
    }

    function success(result){
    WL.Logger.debug("success");
    /* process response from adapter A */
    ...
    /* invoke adapter B */
    var invocationData = {
    adapter : 'adapterB',
    procedure : 'procedure1',
    parameters : []
    };

    WL.Client.invokeProcedure(invocationData,{
    onSuccess : successB,
    onFailure : failureB,
    });
    }
    function failure(result){
    WL.Logger.error("Failure");
    }
    function getData() {
    var invocationData = {
    adapter : 'adapterA',
    procedure : 'procedure1',
    parameters : []
    };

    WL.Client.invokeProcedure(invocationData,{
    onSuccess : success,
    onFailure : failure,
    });
    }
    /******************/

    Now, it might be good (from the performance perspective) to invoke only adapter A from the client, and to invoke adapter B from within adapter A.
    You can use WL.Server.invokeProcedure, but keep in mind that those calls are synchronous.