當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。