// Path: qbit/core/src/main/java/io/advantageous/qbit/reakt/Reakt.java
// public class Reakt {
// 
// 
//     /**
//      * Converts a Reakt promise into a QBit callback.
//      *
//      * @param promise reakt promise
//      * @param <T>     type of promise
//      * @return new QBit callback that wraps promise.
//      */
//     public static <T> Callback<T> convertPromise(final Promise<T> promise) {
//         return convertPromiseToCallback(promise, CallbackBuilder.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt promise into a QBit callback.
//      * Reactor is used to manage timeouts and ensure callback happens on same thread as caller.
//      *
//      * @param reactor QBit reactor
//      * @param promise reakt promise
//      * @param <T>     type of promise
//      * @return new QBit callback that wraps promise.
//      */
//     public static <T> Callback<T> convertPromise(final Reactor reactor, final Promise<T> promise) {
//         return convertPromiseToCallback(promise, reactor.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      *
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> Callback<T> convertCallback(final io.advantageous.reakt.CallbackHandler<T> callback) {
//         return convertReaktCallbackToQBitCallback(callback, CallbackBuilder.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      *
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> io.advantageous.reakt.CallbackHandler<T> convertQBitCallback(final Callback<T> callback) {
//         return result -> {
// 
//             if (result.failure()) {
//                 callback.onError(result.cause());
//             } else {
//                 callback.accept(result.get());
//             }
//         };
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      * <p>
//      * Reactor is used to manage timeouts and ensure callback happens on same thread as caller.
//      *
//      * @param reactor  QBit reactor
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> Callback<T> convertCallback(final Reactor reactor,
//                                                   final io.advantageous.reakt.CallbackHandler<T> callback) {
//         return convertReaktCallbackToQBitCallback(callback, reactor.callbackBuilder());
//     }
// 
//     private static <T> Callback<T> convertPromiseToCallback(final Promise<T> promise, CallbackBuilder callbackBuilder) {
//         return convertReaktCallbackToQBitCallback(promise.asHandler(), callbackBuilder);
//     }
// 
//     private static <T> Callback<T> convertReaktCallbackToQBitCallback(final io.advantageous.reakt.CallbackHandler<T> callback, CallbackBuilder callbackBuilder) {
//         return callbackBuilder
//                 .withCallback(o -> {
//                     callback.onResult(Result.result((T) o));
//                 })
//                 .withErrorHandler(throwable -> callback.onResult(Result.error(throwable)))
//                 .withTimeoutHandler(() -> callback.onResult(Result.error(new TimeoutException()))).build();
// 
//     }
// 
//     /**
//      * Creates a QBit callback based on promise created.
//      *
//      * @param promiseConsumer promise consumer
//      * @param <T>             T
//      * @return QBit callback
//      */
//     public <T> Callback<T> callback(final Consumer<Promise<T>> promiseConsumer) {
//         Promise<T> promise = Promises.promise();
//         promiseConsumer.accept(promise);
//         return Reakt.convertPromise(promise);
//     }
// 
// }


import io.advantageous.qbit.client.BeforeMethodSent;
import io.advantageous.qbit.message.MethodCall;
import io.advantageous.qbit.message.MethodCallBuilder;
import io.advantageous.qbit.queue.SendQueue;
import io.advantageous.qbit.reakt.Reakt;
import io.advantageous.qbit.util.Timer;
import io.advantageous.reakt.Callback;
import io.advantageous.reakt.CallbackHandler;
import io.advantageous.reakt.promise.Promise;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static io.advantageous.boon.core.Str.sputs;
            }
        }
        return false;
    }

    @Override
    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {

        switch (method.getName()) {
            case "clientProxyFlush":
            case "flush":
                sendQueue.flushSends();
                return null;
            case "stop":
                sendQueue.stop();
                return null;
            case "toString":
                return sputs("{Local Proxy", serviceName, "}");
            case "equals":
                return proxy == args[0];
            case "hashCode":
                return proxy.hashCode();

        }


        if (isPromise(method)) {

            final MethodCallBuilder methodCallBuilder = createMethodBuilder(method, args);

// Path: qbit/core/src/main/java/io/advantageous/qbit/reakt/Reakt.java
// public class Reakt {
// 
// 
//     /**
//      * Converts a Reakt promise into a QBit callback.
//      *
//      * @param promise reakt promise
//      * @param <T>     type of promise
//      * @return new QBit callback that wraps promise.
//      */
//     public static <T> Callback<T> convertPromise(final Promise<T> promise) {
//         return convertPromiseToCallback(promise, CallbackBuilder.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt promise into a QBit callback.
//      * Reactor is used to manage timeouts and ensure callback happens on same thread as caller.
//      *
//      * @param reactor QBit reactor
//      * @param promise reakt promise
//      * @param <T>     type of promise
//      * @return new QBit callback that wraps promise.
//      */
//     public static <T> Callback<T> convertPromise(final Reactor reactor, final Promise<T> promise) {
//         return convertPromiseToCallback(promise, reactor.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      *
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> Callback<T> convertCallback(final io.advantageous.reakt.CallbackHandler<T> callback) {
//         return convertReaktCallbackToQBitCallback(callback, CallbackBuilder.callbackBuilder());
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      *
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> io.advantageous.reakt.CallbackHandler<T> convertQBitCallback(final Callback<T> callback) {
//         return result -> {
// 
//             if (result.failure()) {
//                 callback.onError(result.cause());
//             } else {
//                 callback.accept(result.get());
//             }
//         };
//     }
// 
//     /**
//      * Converts a Reakt callback into a QBit callback.
//      * <p>
//      * Reactor is used to manage timeouts and ensure callback happens on same thread as caller.
//      *
//      * @param reactor  QBit reactor
//      * @param callback reakt callback
//      * @param <T>      type of result
//      * @return QBit callback
//      */
//     public static <T> Callback<T> convertCallback(final Reactor reactor,
//                                                   final io.advantageous.reakt.CallbackHandler<T> callback) {
//         return convertReaktCallbackToQBitCallback(callback, reactor.callbackBuilder());
//     }
// 
//     private static <T> Callback<T> convertPromiseToCallback(final Promise<T> promise, CallbackBuilder callbackBuilder) {
//         return convertReaktCallbackToQBitCallback(promise.asHandler(), callbackBuilder);
//     }
// 
//     private static <T> Callback<T> convertReaktCallbackToQBitCallback(final io.advantageous.reakt.CallbackHandler<T> callback, CallbackBuilder callbackBuilder) {
//         return callbackBuilder
//                 .withCallback(o -> {
//                     callback.onResult(Result.result((T) o));
//                 })
//                 .withErrorHandler(throwable -> callback.onResult(Result.error(throwable)))
//                 .withTimeoutHandler(() -> callback.onResult(Result.error(new TimeoutException()))).build();
// 
//     }
// 
//     /**
//      * Creates a QBit callback based on promise created.
//      *
//      * @param promiseConsumer promise consumer
//      * @param <T>             T
//      * @return QBit callback
//      */
//     public <T> Callback<T> callback(final Consumer<Promise<T>> promiseConsumer) {
//         Promise<T> promise = Promises.promise();
//         promiseConsumer.accept(promise);
//         return Reakt.convertPromise(promise);
//     }
// 
// }


// Path: qbit/core/src/main/java/io/advantageous/qbit/boon/service/impl/BoonInvocationHandlerForSendQueue.java
import io.advantageous.qbit.client.BeforeMethodSent;
import io.advantageous.qbit.message.MethodCall;
import io.advantageous.qbit.message.MethodCallBuilder;
import io.advantageous.qbit.queue.SendQueue;
import io.advantageous.qbit.reakt.Reakt;
import io.advantageous.qbit.util.Timer;
import io.advantageous.reakt.Callback;
import io.advantageous.reakt.CallbackHandler;
import io.advantageous.reakt.promise.Promise;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static io.advantageous.boon.core.Str.sputs;

            }
        }
        return false;
    }

    @Override
    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {

        switch (method.getName()) {
            case "clientProxyFlush":
            case "flush":
                sendQueue.flushSends();
                return null;
            case "stop":
                sendQueue.stop();
                return null;
            case "toString":
                return sputs("{Local Proxy", serviceName, "}");
            case "equals":
                return proxy == args[0];
            case "hashCode":
                return proxy.hashCode();

        }


        if (isPromise(method)) {

            final MethodCallBuilder methodCallBuilder = createMethodBuilder(method, args);

            return new InvokePromiseWithSendQueue(sendQueue, methodCallBuilder, beforeMethodSent);