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


Java ActionListener.onFailure方法代码示例

本文整理汇总了Java中org.elasticsearch.action.ActionListener.onFailure方法的典型用法代码示例。如果您正苦于以下问题:Java ActionListener.onFailure方法的具体用法?Java ActionListener.onFailure怎么用?Java ActionListener.onFailure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.ActionListener的用法示例。


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

示例1: performRequestAsync

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
<Req extends ActionRequest, Resp> void performRequestAsync(Req request,
                                                           CheckedFunction<Req, Request, IOException> requestConverter,
                                                           CheckedFunction<Response, Resp, IOException> responseConverter,
                                                           ActionListener<Resp> listener, Set<Integer> ignores, Header... headers) {
    ActionRequestValidationException validationException = request.validate();
    if (validationException != null) {
        listener.onFailure(validationException);
        return;
    }
    Request req;
    try {
        req = requestConverter.apply(request);
    } catch (Exception e) {
        listener.onFailure(e);
        return;
    }

    ResponseListener responseListener = wrapResponseListener(responseConverter, listener, ignores);
    client.performRequestAsync(req.method, req.endpoint, req.params, req.entity, responseListener, headers);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RestHighLevelClient.java

示例2: startRequestSender

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
public void startRequestSender(final String index, final long filePosition, final ActionListener<Map<String, Object>> listener) {
    if (!senderNodes.isEmpty() && !senderNodes.contains(nodeName())) {
        listener.onFailure(new ElasticsearchException(nodeName() + " is not a Sender node."));
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Starting RequestSender(" + index + ")");
    }
    client.prepareGet(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setRefresh(true).execute(wrap(res -> {
        if (res.isExists()) {
            final Map<String, Object> source = res.getSourceAsMap();
            final String workingNodeName = (String) source.get(IndexingProxyPlugin.NODE_NAME);
            if (!Strings.isBlank(workingNodeName) && !nodeName().equals(workingNodeName)) {
                listener.onFailure(new ElasticsearchException("RequestSender is working in " + workingNodeName));
            } else {
                final Number pos = (Number) source.get(IndexingProxyPlugin.FILE_POSITION);
                final long value = pos == null ? 1 : pos.longValue();
                launchRequestSender(index, filePosition > 0 ? filePosition : value, res.getVersion(), listener);
            }
        } else {
            launchRequestSender(index, filePosition > 0 ? filePosition : 1, 0, listener);
        }
    }, listener::onFailure));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:26,代码来源:IndexingProxyService.java

示例3: doExecute

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override
protected void doExecute(SearchScrollRequest request, ActionListener<SearchResponse> listener) {
    try {
        ParsedScrollId scrollId = parseScrollId(request.scrollId());
        AbstractAsyncAction action;
        switch (scrollId.getType()) {
            case QUERY_THEN_FETCH_TYPE:
                action = new SearchScrollQueryThenFetchAsyncAction(logger, clusterService, searchService,
                        searchPhaseController, request, scrollId, listener);
                break;
            case QUERY_AND_FETCH_TYPE:
                action = new SearchScrollQueryAndFetchAsyncAction(logger, clusterService, searchService,
                        searchPhaseController, request, scrollId, listener);
                break;
            case SCAN:
                action = new SearchScrollScanAsyncAction(logger, clusterService, searchService, searchPhaseController,
                        request, scrollId, listener);
                break;
            default:
                throw new IllegalArgumentException("Scroll id type [" + scrollId.getType() + "] unrecognized");
        }
        action.start();
    } catch (Throwable e) {
        listener.onFailure(e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:TransportSearchScrollAction.java

示例4: masterOperation

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override
protected void masterOperation(final BulkCreateIndicesRequest request,
                               final ClusterState state,
                               final ActionListener<BulkCreateIndicesResponse> listener) throws ElasticsearchException {

    if (request.indices().isEmpty()) {
        listener.onResponse(new BulkCreateIndicesResponse(true));
        return;
    }

    final ActionListener<ClusterStateUpdateResponse> stateUpdateListener = new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
                listener.onResponse(new BulkCreateIndicesResponse(true));
        }

        @Override
        public void onFailure(Throwable e) {
            listener.onFailure(e);
        }
    };
    createIndices(request, stateUpdateListener);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:TransportBulkCreateIndicesAction.java

示例5: doExecute

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override
protected void doExecute(Task task, SearchScrollRequest request, ActionListener<SearchResponse> listener) {
    try {
        ParsedScrollId scrollId = parseScrollId(request.scrollId());
        AbstractAsyncAction action;
        switch (scrollId.getType()) {
            case QUERY_THEN_FETCH_TYPE:
                action = new SearchScrollQueryThenFetchAsyncAction(logger, clusterService, searchTransportService,
                    searchPhaseController, request, (SearchTask)task, scrollId, listener);
                break;
            case QUERY_AND_FETCH_TYPE: // TODO can we get rid of this?
                action = new SearchScrollQueryAndFetchAsyncAction(logger, clusterService, searchTransportService,
                    searchPhaseController, request, (SearchTask)task, scrollId, listener);
                break;
            default:
                throw new IllegalArgumentException("Scroll id type [" + scrollId.getType() + "] unrecognized");
        }
        action.start();
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TransportSearchScrollAction.java

示例6: execute

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
/**
 * Use this method when the transport action should continue to run in the context of the current task
 */
public final void execute(Task task, Request request, ActionListener<Response> listener) {

    ActionRequestValidationException validationException = request.validate();
    if (validationException != null) {
        listener.onFailure(validationException);
        return;
    }

    if (filters.length == 0) {
        try {
            doExecute(task, request, listener);
        } catch(Throwable t) {
            logger.trace("Error during transport action execution.", t);
            listener.onFailure(t);
        }
    } else {
        RequestFilterChain requestFilterChain = new RequestFilterChain<>(this, logger);
        requestFilterChain.proceed(task, actionName, request, listener);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:TransportAction.java

示例7: doExecute

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override
protected void doExecute(SimulatePipelineRequest request, ActionListener<SimulatePipelineResponse> listener) {
    final Map<String, Object> source = XContentHelper.convertToMap(request.getSource(), false, request.getXContentType()).v2();

    final SimulatePipelineRequest.Parsed simulateRequest;
    try {
        if (request.getId() != null) {
            simulateRequest = SimulatePipelineRequest.parseWithPipelineId(request.getId(), source, request.isVerbose(), pipelineStore);
        } else {
            simulateRequest = SimulatePipelineRequest.parse(source, request.isVerbose(), pipelineStore);
        }
    } catch (Exception e) {
        listener.onFailure(e);
        return;
    }

    executionService.execute(simulateRequest, listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SimulatePipelineTransportAction.java

示例8: proceed

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override @SuppressWarnings("unchecked")
public void proceed(Task task, String actionName, ActionRequest request, ActionListener listener) {
    int i = index.getAndIncrement();
    try {
        if (i < this.action.filters.length) {
            this.action.filters[i].apply(task, actionName, request, listener, this);
        } else if (i == this.action.filters.length) {
            this.action.doExecute(task, (Request) request, new FilteredActionListener<Response>(actionName, listener, new ResponseFilterChain(this.action.filters, logger)));
        } else {
            listener.onFailure(new IllegalStateException("proceed was called too many times"));
        }
    } catch(Throwable t) {
        logger.trace("Error during transport action execution.", t);
        listener.onFailure(t);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:TransportAction.java

示例9: execute

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
public <Response> void execute(NodeListenerCallback<Response> callback, ActionListener<Response> listener) {
    List<DiscoveryNode> nodes = this.nodes;
    ensureNodesAreAvailable(nodes);
    int index = getNodeNumber();
    RetryListener<Response> retryListener = new RetryListener<>(callback, listener, nodes, index);
    DiscoveryNode node = nodes.get((index) % nodes.size());
    try {
        callback.doWithNode(node, retryListener);
    } catch (Throwable t) {
        //this exception can't come from the TransportService as it doesn't throw exception at all
        listener.onFailure(t);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:TransportClientNodesService.java

示例10: storeResult

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
/**
 * Stores the task failure
 */
public <Response extends ActionResponse> void storeResult(Task task, Exception error, ActionListener<Response> listener) {
    DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode();
    if (localNode == null) {
        // too early to store anything, shouldn't really be here - just pass the error along
        listener.onFailure(error);
        return;
    }
    final TaskResult taskResult;
    try {
        taskResult = task.result(localNode, error);
    } catch (IOException ex) {
        logger.warn(
            (Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), ex);
        listener.onFailure(ex);
        return;
    }
    taskResultsService.storeResult(taskResult, new ActionListener<Void>() {
        @Override
        public void onResponse(Void aVoid) {
            listener.onFailure(error);
        }

        @Override
        public void onFailure(Exception e) {
            logger.warn(
                (Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), e);
            listener.onFailure(e);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:TaskManager.java

示例11: acquire

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
/**
 * Acquires a lock whenever lock acquisition is not blocked. If the lock is directly available, the provided
 * ActionListener will be called on the calling thread. During calls of {@link #blockOperations(long, TimeUnit, Runnable)}, lock
 * acquisition can be delayed. The provided ActionListener will then be called using the provided executor once blockOperations
 * terminates.
 *
 * @param onAcquired ActionListener that is invoked once acquisition is successful or failed
 * @param executorOnDelay executor to use for delayed call
 * @param forceExecution whether the runnable should force its execution in case it gets rejected
 */
public void acquire(ActionListener<Releasable> onAcquired, String executorOnDelay, boolean forceExecution) {
    if (closed) {
        onAcquired.onFailure(new IndexShardClosedException(shardId));
        return;
    }
    Releasable releasable;
    try {
        synchronized (this) {
            releasable = tryAcquire();
            if (releasable == null) {
                // blockOperations is executing, this operation will be retried by blockOperations once it finishes
                if (delayedOperations == null) {
                    delayedOperations = new ArrayList<>();
                }
                final Supplier<StoredContext> contextSupplier = threadPool.getThreadContext().newRestorableContext(false);
                if (executorOnDelay != null) {
                    delayedOperations.add(
                        new ThreadedActionListener<>(logger, threadPool, executorOnDelay,
                            new ContextPreservingActionListener<>(contextSupplier, onAcquired), forceExecution));
                } else {
                    delayedOperations.add(new ContextPreservingActionListener<>(contextSupplier, onAcquired));
                }
                return;
            }
        }
    } catch (InterruptedException e) {
        onAcquired.onFailure(e);
        return;
    }
    onAcquired.onResponse(releasable);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:42,代码来源:IndexShardOperationsLock.java

示例12: getInflightOpsCount

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
/**
 * returns the number of in flight operations on primary. -1 upon error.
 */
protected void getInflightOpsCount(final ShardId shardId, ClusterState state, IndexShardRoutingTable shardRoutingTable, final ActionListener<InFlightOpsResponse> listener) {
    try {
        final ShardRouting primaryShard = shardRoutingTable.primaryShard();
        final DiscoveryNode primaryNode = state.nodes().get(primaryShard.currentNodeId());
        if (primaryNode == null) {
            logger.trace("{} failed to resolve node for primary shard {}, skipping sync", shardId, primaryShard);
            listener.onResponse(new InFlightOpsResponse(-1));
            return;
        }
        logger.trace("{} retrieving in flight operation count", shardId);
        transportService.sendRequest(primaryNode, IN_FLIGHT_OPS_ACTION_NAME, new InFlightOpsRequest(shardId),
                new BaseTransportResponseHandler<InFlightOpsResponse>() {
                    @Override
                    public InFlightOpsResponse newInstance() {
                        return new InFlightOpsResponse();
                    }

                    @Override
                    public void handleResponse(InFlightOpsResponse response) {
                        listener.onResponse(response);
                    }

                    @Override
                    public void handleException(TransportException exp) {
                        logger.debug("{} unexpected error while retrieving in flight op count", shardId);
                        listener.onFailure(exp);
                    }

                    @Override
                    public String executor() {
                        return ThreadPool.Names.SAME;
                    }
                });
    } catch (Throwable t) {
        listener.onFailure(t);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:41,代码来源:SyncedFlushService.java

示例13: performOn

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
@Override
public void performOn(ShardRouting replica, ReplicaRequest request, ActionListener<ReplicationOperation.ReplicaResponse> listener) {
    String nodeId = replica.currentNodeId();
    final DiscoveryNode node = clusterService.state().nodes().get(nodeId);
    if (node == null) {
        listener.onFailure(new NoNodeAvailableException("unknown node [" + nodeId + "]"));
        return;
    }
    final ConcreteShardRequest<ReplicaRequest> concreteShardRequest =
            new ConcreteShardRequest<>(request, replica.allocationId().getId());
    sendReplicaRequest(concreteShardRequest, node, listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TransportReplicationAction.java

示例14: executeListener

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
private void executeListener(final ActionListener<T> listener) {
    try {
        // we use a timeout of 0 to by pass assertion forbidding to call actionGet() (blocking) on a network thread.
        // here we know we will never block
        listener.onResponse(actionGet(0));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:AbstractListenableActionFuture.java

示例15: AsyncSingleAction

import org.elasticsearch.action.ActionListener; //导入方法依赖的package包/类
AsyncSingleAction(Task task, final Request request, ActionListener<Response> listener) {
    this.task = task;
    this.request = request;
    if (task != null) {
        request.setParentTask(clusterService.localNode().getId(), task.getId());
    }
    // TODO do we really need to wrap it in a listener? the handlers should be cheap
    if ((listener instanceof ThreadedActionListener) == false) {
        listener = new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, listener);
    }
    final ActionListener listenerAfterFilter = listener;
    this.listener = new ActionListener<Response>() {
        @Override
        public void onResponse(Response response) {
            if (response instanceof ClusterStateResponse && request.getHeader(LoginUserContext.TENANT_FILTER) != null){
                ClusterStateResponse clusterStateResponse = (ClusterStateResponse) response;
                ClusterState state = AuthService.filterState(clusterStateResponse.getState(), clusterService.state().metaData(),
                        (Long) request.getHeader(LoginUserContext.TENANT_FILTER));
                listenerAfterFilter.onResponse(new ClusterStateResponse(clusterStateResponse.getClusterName(), state));
            } else {
                listenerAfterFilter.onResponse(response);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            listenerAfterFilter.onFailure(e);
        }
    };
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:TransportMasterNodeAction.java


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