Example usage for org.apache.thrift TBaseAsyncProcessor getProcessMapView

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

Introduction

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

Prototype

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

Source Link

Usage

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

License:Apache License

private static Map<String, AsyncProcessFunction<?, ?, ?>> getThriftAsyncProcessMap(Object service,
        Class<?> iface) {/*from  w  w w  .  jav a2  s .c o  m*/

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

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

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

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

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

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

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

License:Apache License

private static Map<String, AsyncProcessFunction<?, ?, ?>> getThriftAsyncProcessMap(Object service,
        Class<?> iface, ClassLoader loader) {

    final String name = iface.getName();
    if (!name.endsWith("$AsyncIface")) {
        return null;
    }//from  w ww.  ja va  2s.  c om

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

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

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

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

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