FileDocCategorySizeDatePackage
HandlerDispatcher.javaAPI DocAndroid 5.1 API3559Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.dispatch

HandlerDispatcher

public class HandlerDispatcher extends Object implements Dispatchable
Forward all interface calls into a handler by posting it as a {@code Runnable}.

All calls will return immediately; functions with return values will return a default value of {@code null}, {@code 0}, or {@code false} where that value is legal.

Any exceptions thrown on the handler while trying to invoke a method will be re-thrown. Throwing checked exceptions on a handler which doesn't expect any checked exceptions to be thrown will result in "undefined" behavior (although in practice it is usually thrown as normal).

Fields Summary
private static final String
TAG
private final Dispatchable
mDispatchTarget
private final android.os.Handler
mHandler
Constructors Summary
public HandlerDispatcher(Dispatchable dispatchTarget, android.os.Handler handler)
Create a dispatcher that forwards it's dispatch calls by posting them onto the {@code handler} as a {@code Runnable}.

param
dispatchTarget the destination whose method calls will be redirected into the handler
param
handler all calls into {@code dispatchTarget} will be posted onto this handler
param
the type of the element you want to wrap.
return
a dispatcher that will forward it's dispatch calls to a handler


                                                                             
         
        mDispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null");
        mHandler = checkNotNull(handler, "handler must not be null");
    
Methods Summary
public java.lang.Objectdispatch(java.lang.reflect.Method method, java.lang.Object[] args)

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    mDispatchTarget.dispatch(method, args);
                } catch (InvocationTargetException e) {
                    Throwable t = e.getTargetException();
                    // Potential UB. Hopefully 't' is a runtime exception.
                    UncheckedThrow.throwAnyException(t);
                } catch (IllegalAccessException e) {
                    // Impossible
                    Log.wtf(TAG, "IllegalAccessException while invoking " + method, e);
                } catch (IllegalArgumentException e) {
                    // Impossible
                    Log.wtf(TAG, "IllegalArgumentException while invoking " + method, e);
                } catch (Throwable e) {
                    UncheckedThrow.throwAnyException(e);
                }
            }
        });

        // TODO handle primitive return values that would avoid NPE if unboxed
        return null;