use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class TransportReplicationAction method handlePrimaryRequest.
protected void handlePrimaryRequest(final ConcreteShardRequest<Request> request, final TransportChannel channel, final Task task) {
Releasable releasable = checkPrimaryLimits(request.getRequest(), request.sentFromLocalReroute(), request.localRerouteInitiatedByNodeClient());
ActionListener<Response> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, transportPrimaryAction, request), releasable::close);
try {
new AsyncPrimaryAction(request, listener, (ReplicationTask) task).run();
} catch (RuntimeException e) {
listener.onFailure(e);
}
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class TransportReplicationAction method handleOperationRequest.
private void handleOperationRequest(final Request request, final TransportChannel channel, Task task) {
Releasable releasable = checkOperationLimits(request);
ActionListener<Response> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, actionName, request), releasable::close);
runReroutePhase(task, request, listener, false);
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class TransportReplicationAction method handleReplicaRequest.
protected void handleReplicaRequest(final ConcreteReplicaRequest<ReplicaRequest> replicaRequest, final TransportChannel channel, final Task task) {
Releasable releasable = checkReplicaLimits(replicaRequest.getRequest());
ActionListener<ReplicaResponse> listener = ActionListener.runBefore(new ChannelActionListener<>(channel, transportReplicaAction, replicaRequest), releasable::close);
try {
new AsyncReplicaAction(replicaRequest, listener, (ReplicationTask) task).run();
} catch (RuntimeException e) {
listener.onFailure(e);
}
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class TransportAction method execute.
/**
* Execute the transport action on the local node, returning the {@link Task} used to track its execution and accepting a
* {@link TaskListener} which listens for the completion of the action.
*/
public final Task execute(Request request, TaskListener<Response> listener) {
final Releasable unregisterChildNode = registerChildNode(request.getParentTask());
final Task task;
try {
task = taskManager.register("transport", actionName, request);
} catch (TaskCancelledException e) {
unregisterChildNode.close();
throw e;
}
execute(task, request, new ActionListener<Response>() {
@Override
public void onResponse(Response response) {
try {
Releasables.close(unregisterChildNode, () -> taskManager.unregister(task));
} finally {
listener.onResponse(task, response);
}
}
@Override
public void onFailure(Exception e) {
try {
Releasables.close(unregisterChildNode, () -> taskManager.unregister(task));
} finally {
listener.onFailure(task, e);
}
}
});
return task;
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class TcpReadWriteHandler method consumeReads.
@Override
public int consumeReads(InboundChannelBuffer channelBuffer) throws IOException {
Page[] pages = channelBuffer.sliceAndRetainPagesTo(channelBuffer.getIndex());
BytesReference[] references = new BytesReference[pages.length];
for (int i = 0; i < pages.length; ++i) {
references[i] = BytesReference.fromByteBuffer(pages[i].byteBuffer());
}
Releasable releasable = () -> IOUtils.closeWhileHandlingException(pages);
try (ReleasableBytesReference reference = new ReleasableBytesReference(CompositeBytesReference.of(references), releasable)) {
pipeline.handleBytes(channel, reference);
return reference.length();
}
}
Aggregations