Package com.droidkit.actors.typed

Source Code of com.droidkit.actors.typed.TypedCreator

package com.droidkit.actors.typed;

import com.droidkit.actors.ActorRef;
import com.droidkit.actors.concurrency.Future;
import com.droidkit.actors.typed.messages.TypedRequest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
* Created by ex3ndr on 06.09.14.
*/
public class TypedCreator {
    public static <T> T typed(final ActorRef ref, Class<T> tClass) {
        return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class[]{tClass}, new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        ClientFuture future = null;
                        if (method.getReturnType().equals(Future.class)) {
                            future = new ClientFuture();
                        }
                        ref.send(new TypedRequest(future, method, args));
                        return future;
                    }
                });
    }
}
TOP

Related Classes of com.droidkit.actors.typed.TypedCreator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.