Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Callback Handler

Tags:

java

I am trying to understand mechanism of callback handler. How is the handle() method invoked? Can anybody give an example of usage of custom callback handler (other than those used in Login Modules of JASS or so) in non Swing application?

like image 203
Partha Avatar asked Jul 21 '11 15:07

Partha


People also ask

What is a callback handler?

Custom code that defines the callout logic. Used by the operational server to call out to third-party systems or to implement conditional security, event notification, or more processing steps.

What is callback handler in Java?

An application implements a CallbackHandler and passes it to underlying security services so that they may interact with the application to retrieve specific authentication data, such as usernames and passwords, or to display certain information, such as error and warning messages.


1 Answers

Define an interface to handle the callback.

public interface ServiceListener<T> {
    void callback(T result);
}

Define a method that takes ServiceListener as parameter and returns void.

Public void runInBackground(ServiceListener listener) {
    ...code that runs in the background...
    listener.callback(...data to return to caller...);
}

And you can now do this from your main code:

 runInBackground(new ServiceListener() {


        @Override
        public void callback(..returned data...) {
            ...Do stuff with returned data...
        }
 });
like image 124
slott Avatar answered Sep 29 '22 08:09

slott