Example usage for org.apache.thrift TBaseProcessor getProcessMapView

List of usage examples for org.apache.thrift TBaseProcessor getProcessMapView

Introduction

In this page you can find the example usage for org.apache.thrift TBaseProcessor getProcessMapView.

Prototype

public Map<String, ProcessFunction<I, ? extends TBase>> getProcessMapView() 

Source Link

Usage

From source file:com.linecorp.armeria.internal.thrift.ThriftServiceMetadata.java

License:Apache License

private static Map<String, ProcessFunction<?, ?>> getThriftProcessMap(Object service, Class<?> iface) {

    final String name = iface.getName();
    if (!name.endsWith("$Iface")) {
        return null;
    }/* w ww .  j  a  va 2s  .c o  m*/

    final String processorName = name.substring(0, name.length() - 5) + "Processor";
    try {
        final Class<?> processorClass = Class.forName(processorName, false, iface.getClassLoader());
        if (!TBaseProcessor.class.isAssignableFrom(processorClass)) {
            return null;
        }

        final Constructor<?> processorConstructor = processorClass.getConstructor(iface);

        @SuppressWarnings("rawtypes")
        final TBaseProcessor processor = (TBaseProcessor) processorConstructor.newInstance(service);

        @SuppressWarnings("unchecked")
        Map<String, ProcessFunction<?, ?>> processMap = (Map<String, ProcessFunction<?, ?>>) processor
                .getProcessMapView();

        return processMap;
    } catch (Exception e) {
        logger.debug("Failed to retrieve the process map from: {}", iface, e);
        return null;
    }
}

From source file:com.linecorp.armeria.server.thrift.ThriftServiceCodec.java

License:Apache License

private static Map<String, ProcessFunction<?, ?>> getThriftProcessMap(Object service, Class<?> iface,
        ClassLoader loader) {//from w  ww.  ja  v  a 2s  .  co  m

    final String name = iface.getName();
    if (!name.endsWith("$Iface")) {
        return null;
    }

    final String processorName = name.substring(0, name.length() - 5) + "Processor";
    try {
        final Class<?> processorClass = Class.forName(processorName, false, loader);
        if (!TBaseProcessor.class.isAssignableFrom(processorClass)) {
            return null;
        }

        final Constructor<?> processorConstructor = processorClass.getConstructor(iface);

        @SuppressWarnings("rawtypes")
        final TBaseProcessor processor = (TBaseProcessor) processorConstructor.newInstance(service);

        @SuppressWarnings("unchecked")
        Map<String, ProcessFunction<?, ?>> processMap = (Map<String, ProcessFunction<?, ?>>) processor
                .getProcessMapView();

        return processMap;
    } catch (Exception e) {
        logger.debug("Failed to retrieve the process map from: {}", iface, e);
        return null;
    }
}

From source file:io.nettythrift.core.ThriftServerDef.java

License:Apache License

@SuppressWarnings("unchecked")
public ThriftServerDef(String name, int serverPort, int maxFrameSize, int maxConnections,
        int queuedResponseLimit, NettyProcessorFactory nettyProcessorFactory, ChannelInitializer codecInstaller,
        @SuppressWarnings("rawtypes") TBaseProcessor processor, ExecutorService executor,
        long clientIdleTimeout, ProtocolFactorySelectorFactory protocolFactorySelectorFactory,
        HttpResourceHandler httpResourceHandler, boolean voidMethodDirectReturn,
        HttpHandlerFactory httpHandlerFactory) {
    super();// w  ww.ja v  a 2 s. c om
    this.name = name;
    this.serverPort = serverPort;
    this.maxFrameSize = maxFrameSize;
    this.maxConnections = maxConnections;
    this.queuedResponseLimit = queuedResponseLimit;
    this.processMap = processor.getProcessMapView();
    this.executor = executor;
    this.clientIdleTimeout = clientIdleTimeout;
    this.httpResourceHandler = httpResourceHandler;
    this.voidMethodDirectReturn = voidMethodDirectReturn;
    this.httpHandlerFactory = httpHandlerFactory == null ? new DefaultHttpHandlerFactory() : httpHandlerFactory;
    if (nettyProcessorFactory == null) {
        nettyProcessorFactory = new DefaultNettyProcessorFactory();
    }
    if (codecInstaller == null) {
        codecInstaller = new DefaultChannelInitializer<SocketChannel>(this);
    }
    this.nettyProcessor = nettyProcessorFactory.create(this);
    this.codecInstaller = codecInstaller;
    Object iface = null;
    try {
        Field f = TBaseProcessor.class.getDeclaredField("iface");
        f.setAccessible(true);
        iface = f.get(processor);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Class<?>[] ifcs = iface.getClass().getInterfaces();
    Class<?> ifaceClass = null;
    for (Class<?> c : ifcs) {
        if (c.getEnclosingClass() != null && c.getSimpleName().equals("Iface")) {
            ifaceClass = c;
            break;
        }
    }
    int[] voidMethodHashes = null;
    if (ifaceClass != null) {
        Method[] ms = ifaceClass.getMethods();
        int len = 0;
        int[] hashes = new int[ms.length];
        for (Method m : ms) {
            if (m.getReturnType() == void.class) {
                hashes[len++] = m.getName().hashCode();
            }
        }
        if (len > 0) {
            if (len < ms.length) {
                voidMethodHashes = new int[len];
                System.arraycopy(hashes, 0, voidMethodHashes, 0, len);
            } else {
                voidMethodHashes = hashes;
            }
            Arrays.sort(voidMethodHashes);
        }
    }
    this.voidMethodHashes = voidMethodHashes;
    this.iface = iface;
    protocolFactorySelector = protocolFactorySelectorFactory.createProtocolFactorySelector(ifaceClass);
}

From source file:net.phoenix.thrift.server.ZookeeperRegisterHandler.java

License:Apache License

/**
 * The functions provided by target processor;
 *
 * @return/*from  w  w  w . j a va2 s.  c  o  m*/
 */
private String[] getFunctions() {
    String[] functions;
    if (this.processor instanceof TBaseProcessor) {
        @SuppressWarnings("rawtypes")
        TBaseProcessor processor = (TBaseProcessor) this.processor;
        int count = 0;
        functions = new String[processor.getProcessMapView().size()];
        for (Object key : processor.getProcessMapView().keySet()) {
            functions[count] = key.toString();
            count++;
        }
    } else {
        Method method[] = this.processor.getClass().getDeclaredMethods();
        functions = new String[method.length];
        for (int i = 0; i < method.length; i++) {
            functions[i] = method[i].getName();
        }
    }
    return functions;
}

From source file:org.apache.accumulo.server.rpc.RpcWrapper.java

License:Apache License

public static <I> I service(final I instance, final TBaseProcessor<I> processor) {
    final Map<String, ProcessFunction<I, ?>> processorView = processor.getProcessMapView();
    final Set<String> onewayMethods = getOnewayMethods(processorView);
    log.debug("Found oneway Thrift methods: " + onewayMethods);

    InvocationHandler handler = getInvocationHandler(instance, onewayMethods);

    @SuppressWarnings("unchecked")
    I proxiedInstance = (I) Proxy.newProxyInstance(instance.getClass().getClassLoader(),
            instance.getClass().getInterfaces(), handler);
    return proxiedInstance;
}