当前位置: 首页>>代码示例>>Java>>正文


Java DataObjectFactory类代码示例

本文整理汇总了Java中facebook4j.json.DataObjectFactory的典型用法代码示例。如果您正苦于以下问题:Java DataObjectFactory类的具体用法?Java DataObjectFactory怎么用?Java DataObjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataObjectFactory类属于facebook4j.json包,在下文中一共展示了DataObjectFactory类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: poll

import facebook4j.json.DataObjectFactory; //导入依赖的package包/类
@Override
protected int poll() throws Exception {
    // invoke the consumer method
    final Map<String, Object> args = getMethodArguments();
    try {
        // also check whether we need to get raw JSON
        String rawJSON = null;
        Object result;
        if (endpoint.getConfiguration().getJsonStoreEnabled() == null
            || !endpoint.getConfiguration().getJsonStoreEnabled()) {
            result = invokeMethod(endpoint.getConfiguration().getFacebook(),
                method, args);
        } else {
            final Facebook facebook = endpoint.getConfiguration().getFacebook();
            synchronized (facebook) {
                result = invokeMethod(facebook, method, args);
                rawJSON = DataObjectFactory.getRawJSON(result);
            }
        }

        // process result according to type
        if (result != null && (result instanceof Collection || result.getClass().isArray())) {
            // create an exchange for every element
            final Object array = getResultAsArray(result);
            final int length = Array.getLength(array);
            for (int i = 0; i < length; i++) {
                processResult(Array.get(array, i), rawJSON);
            }
            return length;
        } else {
            processResult(result, rawJSON);
            return 1; // number of messages polled
        }
    } catch (Throwable t) {
        throw ObjectHelper.wrapRuntimeCamelException(t);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:FacebookConsumer.java

示例2: process

import facebook4j.json.DataObjectFactory; //导入依赖的package包/类
@Override
public boolean process(final Exchange exchange, final AsyncCallback callback) {
    // properties for method arguments
    final Map<String, Object> properties = new HashMap<String, Object>();

    getExchangeProperties(exchange, properties);
    FacebookPropertiesHelper.configureReadingProperties(endpoint.getConfiguration(), properties);
    getEndpointProperties(endpoint.getConfiguration(), properties);

    // decide which method to invoke
    final FacebookMethodsType method = findMethod(exchange, properties);
    if (method == null) {
        // synchronous failure
        callback.done(true);
        return true;
    }

    // create a runnable invocation task to be submitted on a background thread pool
    // this way we avoid blocking the current thread for long running operations
    Runnable invocation = new Runnable() {
        @Override
        public void run() {
            try {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Invoking method {} with {}", method.getName(), properties.keySet());
                }

                // also check whether we need to get Raw JSON
                Object result;
                String rawJSON = null;
                if (endpoint.getConfiguration().getJsonStoreEnabled() == null
                    || !endpoint.getConfiguration().getJsonStoreEnabled()) {
                    result = FacebookMethodsTypeHelper.invokeMethod(
                        endpoint.getConfiguration().getFacebook(), method, properties);
                } else {
                    final Facebook facebook = endpoint.getConfiguration().getFacebook();
                    // lock out the underlying Facebook object from other threads
                    synchronized (facebook) {
                        result = FacebookMethodsTypeHelper.invokeMethod(
                            facebook, method, properties);
                        rawJSON = DataObjectFactory.getRawJSON(result);
                    }
                }

                // producer returns a single response, even for methods with List return types
                exchange.getOut().setBody(result);
                // copy headers
                exchange.getOut().setHeaders(exchange.getIn().getHeaders());
                if (rawJSON != null) {
                    exchange.getOut().setHeader(FacebookConstants.FACEBOOK_PROPERTY_PREFIX + "rawJSON",
                        rawJSON);
                }

            } catch (Throwable t) {
                exchange.setException(ObjectHelper.wrapRuntimeCamelException(t));
            } finally {
                callback.done(false);
            }
        }
    };

    getExecutorService(getEndpoint().getCamelContext()).submit(invocation);
    return false;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:65,代码来源:FacebookProducer.java


注:本文中的facebook4j.json.DataObjectFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。