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


Java ActionListener类代码示例

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


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

示例1: rethrottleTestCase

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
/**
 * Test rethrottling.
 * @param runningSlices the number of slices still running
 * @param simulator simulate a response from the sub-request to rethrottle the child requests
 * @param verifier verify the resulting response
 */
private void rethrottleTestCase(int runningSlices, Consumer<ActionListener<ListTasksResponse>> simulator,
        Consumer<ActionListener<TaskInfo>> verifier) {
    Client client = mock(Client.class);
    String localNodeId = randomAsciiOfLength(5);
    float newRequestsPerSecond = randomValueOtherThanMany(f -> f <= 0, () -> randomFloat());
    @SuppressWarnings("unchecked")
    ActionListener<TaskInfo> listener = mock(ActionListener.class);

    TransportRethrottleAction.rethrottle(localNodeId, client, task, newRequestsPerSecond, listener);

    // Capture the sub request and the listener so we can verify they are sane
    ArgumentCaptor<RethrottleRequest> subRequest = ArgumentCaptor.forClass(RethrottleRequest.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) // Magical generics incantation.....
    ArgumentCaptor<ActionListener<ListTasksResponse>> subListener = ArgumentCaptor.forClass((Class) ActionListener.class);
    if (runningSlices > 0) {
        verify(client).execute(eq(RethrottleAction.INSTANCE), subRequest.capture(), subListener.capture());

        assertEquals(new TaskId(localNodeId, task.getId()), subRequest.getValue().getParentTaskId());
        assertEquals(newRequestsPerSecond / runningSlices, subRequest.getValue().getRequestsPerSecond(), 0.00001f);

        simulator.accept(subListener.getValue());
    }
    verifier.accept(listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:TransportRethrottleActionTests.java

示例2: masterOperation

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
protected void masterOperation(final UpgradeSettingsRequest request, final ClusterState state, final ActionListener<UpgradeSettingsResponse> listener) {
    UpgradeSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpgradeSettingsClusterStateUpdateRequest()
            .ackTimeout(request.timeout())
            .versions(request.versions())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.upgradeIndexSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new UpgradeSettingsResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to upgrade minimum compatibility version settings on indices [{}]", request.versions().keySet()), t);
            listener.onFailure(t);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:TransportUpgradeSettingsAction.java

示例3: apply

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, String action,
        Request request, ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) {
    if (false == action.equals(SearchAction.NAME)) {
        chain.proceed(task, action, request, listener);
        return;
    }
    if (context.getHeader(EXAMPLE_HEADER) != null) {
        throw new IllegalArgumentException("Hurray! Sent the header!");
    }
    String auth = context.getHeader(AUTHORIZATION_HEADER);
    if (auth == null) {
        ElasticsearchSecurityException e = new ElasticsearchSecurityException("Authentication required",
                RestStatus.UNAUTHORIZED);
        e.addHeader("WWW-Authenticate", "Basic realm=auth-realm");
        throw e;
    }
    if (false == REQUIRED_AUTH.equals(auth)) {
        throw new ElasticsearchSecurityException("Bad Authorization", RestStatus.FORBIDDEN);
    }
    chain.proceed(task, action, request, listener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ReindexFromRemoteWithAuthTests.java

示例4: renew

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
public <Response extends ActionResponse> void renew(final ActionListener<Response> listener) {
    client.prepareGet(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, FILE_ID).setRefresh(true).execute(wrap(res -> {
        if (res.isExists()) {
            final Map<String, Object> source = res.getSourceAsMap();
            final String nodeName = (String) source.get(IndexingProxyPlugin.NODE_NAME);
            if (nodeName().equals(nodeName)) {
                renewOnLocal(listener);
            } else {
                renewOnRemote(nodeName, listener);
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("No file_id. Skipped renew action.");
            }
            listener.onResponse(null);
        }
    }, listener::onFailure));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:19,代码来源:IndexingProxyService.java

示例5: 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

示例6: updateStats

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
private void updateStats() {
    transportSQLAction.get().execute(
            REQUEST,
            new ActionListener<SQLResponse>() {

                @Override
                public void onResponse(SQLResponse sqlResponse) {
                    tableStats = statsFromResponse(sqlResponse);
                }

                @Override
                public void onFailure(Throwable e) {
                    logger.error("error retrieving table stats", e);
                }
            });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:TableStatsService.java

示例7: done

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
protected void done() {
    super.done();
    synchronized (this) {
        executedListeners = true;
    }
    Object listeners = this.listeners;
    if (listeners != null) {
        if (listeners instanceof List) {
            List list = (List) listeners;
            for (Object listener : list) {
                executeListener((ActionListener<T>) listener);
            }
        } else {
            executeListener((ActionListener<T>) listeners);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AbstractListenableActionFuture.java

示例8: onShardInactive

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
public void onShardInactive(final IndexShard indexShard) {
    // we only want to call sync flush once, so only trigger it when we are on a primary
    if (indexShard.routingEntry().primary()) {
        attemptSyncedFlush(indexShard.shardId(), new ActionListener<ShardsSyncedFlushResult>() {
            @Override
            public void onResponse(ShardsSyncedFlushResult syncedFlushResult) {
                logger.trace("{} sync flush on inactive shard returned successfully for sync_id: {}", syncedFlushResult.getShardId(), syncedFlushResult.syncId());
            }

            @Override
            public void onFailure(Exception e) {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} sync flush on inactive shard failed", indexShard.shardId()), e);
            }
        });
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SyncedFlushService.java

示例9: getClusterState

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
private static CompletableFuture<ClusterState> getClusterState(final Client client) {
    CompletableFuture<ClusterState> result = new CompletableFuture<>();
    ClusterStateRequest request = new ClusterStateRequest().routingTable(false).nodes(false);

    client.admin().cluster().state(request, new ActionListener<ClusterStateResponse>() {
        @Override
        public void onResponse(ClusterStateResponse response) {
            result.complete(response.getState());
        }

        @Override
        public void onFailure(Exception e) {
            result.completeExceptionally(e);
        }
    });
    return result;
}
 
开发者ID:jsuchenia,项目名称:elasticsearch-prometheus-metrics,代码行数:18,代码来源:PrometheusExporterPlugin.java

示例10: SearchScrollQueryAndFetchAsyncAction

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
SearchScrollQueryAndFetchAsyncAction(Logger logger, ClusterService clusterService, SearchTransportService searchTransportService,
                                     SearchPhaseController searchPhaseController, SearchScrollRequest request, SearchTask task,
                                     ParsedScrollId scrollId, ActionListener<SearchResponse> listener) {
    this.logger = logger;
    this.searchPhaseController = searchPhaseController;
    this.searchTransportService = searchTransportService;
    this.request = request;
    this.task = task;
    this.listener = listener;
    this.scrollId = scrollId;
    this.nodes = clusterService.state().nodes();
    this.successfulOps = new AtomicInteger(scrollId.getContext().length);
    this.counter = new AtomicInteger(scrollId.getContext().length);

    this.queryFetchResults = new AtomicArray<>(scrollId.getContext().length);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SearchScrollQueryAndFetchAsyncAction.java

示例11: unindex

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
public void unindex(String appid, ParaObject po) {
	if (po == null || StringUtils.isBlank(po.getId()) || StringUtils.isBlank(appid)) {
		return;
	}
	try {
		DeleteRequestBuilder drb = client().prepareDelete(getIndexName(appid), getType(), po.getId());
		ActionListener<DeleteResponse> responseHandler = ElasticSearchUtils.getIndexResponseHandler();
		if (isAsyncEnabled()) {
			drb.execute(responseHandler);
		} else {
			responseHandler.onResponse(drb.execute().actionGet());
		}
		logger.debug("Search.unindex() {}", po.getId());
	} catch (Exception e) {
		logger.warn(null, e);
	}
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:19,代码来源:ElasticSearch.java

示例12: finishAndNotifyListener

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ActionWriteResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ActionWriteResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:TransportBroadcastReplicationAction.java

示例13: checkIfIndexExists

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
private void checkIfIndexExists(final ActionListener<ActionResponse> listener) {
    client.admin().indices().prepareExists(IndexingProxyPlugin.INDEX_NAME).execute(wrap(response -> {
        if (response.isExists()) {
            if (logger.isDebugEnabled()) {
                logger.debug(IndexingProxyPlugin.INDEX_NAME + " exists.");
            }
            listener.onResponse(response);
        } else {
            createIndex(listener);
        }
    }, e -> {
        if (e instanceof IndexNotFoundException) {
            createIndex(listener);
        } else {
            listener.onFailure(e);
        }
    }));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:19,代码来源:IndexingProxyService.java

示例14: executePhase

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
void executePhase(final int shardIndex, DiscoveryNode node, final long searchId) {
    searchService.sendExecuteScan(node, TransportSearchHelper.internalScrollSearchRequest(searchId, request), new
            ActionListener<ScrollQueryFetchSearchResult>() {
        @Override
        public void onResponse(ScrollQueryFetchSearchResult result) {
            QueryFetchSearchResult shardResult = result.result();
            Objects.requireNonNull(shardResult, "QueryFetchSearchResult can't be null");
            queryFetchResults.setOnce(shardIndex, shardResult);
            if (counter.decrementAndGet() == 0) {
                finishHim();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            onPhaseFailure(t, searchId, shardIndex);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:SearchScrollScanAsyncAction.java

示例15: doExecute

import org.elasticsearch.action.ActionListener; //导入依赖的package包/类
@Override
protected void doExecute(MultiSearchTemplateRequest request, ActionListener<MultiSearchTemplateResponse> listener) {
    final AtomicArray<MultiSearchTemplateResponse.Item> responses = new AtomicArray<>(request.requests().size());
    final AtomicInteger counter = new AtomicInteger(responses.length());

    for (int i = 0; i < responses.length(); i++) {
        final int index = i;
        searchTemplateAction.execute(request.requests().get(i), new ActionListener<SearchTemplateResponse>() {
            @Override
            public void onResponse(SearchTemplateResponse searchTemplateResponse) {
                responses.set(index, new MultiSearchTemplateResponse.Item(searchTemplateResponse, null));
                if (counter.decrementAndGet() == 0) {
                    finishHim();
                }
            }

            @Override
            public void onFailure(Exception e) {
                responses.set(index, new MultiSearchTemplateResponse.Item(null, e));
                if (counter.decrementAndGet() == 0) {
                    finishHim();
                }
            }

            private void finishHim() {
                MultiSearchTemplateResponse.Item[] items = responses.toArray(new MultiSearchTemplateResponse.Item[responses.length()]);
                listener.onResponse(new MultiSearchTemplateResponse(items));
            }
        });
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:TransportMultiSearchTemplateAction.java


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