<commit_before>/*
 * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.spi.impl.operationservice.impl.operations;

import com.hazelcast.client.impl.operations.OperationFactoryWrapper;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spi.NodeEngine;
import com.hazelcast.spi.Operation;
import com.hazelcast.spi.OperationAccessor;
import com.hazelcast.spi.OperationFactory;
import com.hazelcast.spi.OperationResponseHandler;
import com.hazelcast.spi.OperationService;
import com.hazelcast.spi.impl.SpiDataSerializerHook;
import com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl;
import com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse;
import com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;

import static com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareFactoryAccessor.extractPartitionAware;

/**
 * Executes Operations on one or more partitions.
 * <p>
 * THe execution used to be synchronous; so the thread executing this PartitionIteratingOperation would block till all
 * the child requests are done. In 3.8 this is made asynchronous so that the thread isn't consumed and available for
 * other tasks. On each partition operation an {@link OperationResponseHandler} is set, that sends the result to the
 * caller when all responses have completed.
 */
public final class PartitionIteratingOperation extends Operation implements IdentifiedDataSerializable {
    private static final Object NULL = new Object() {
        @Override
        public String toString() {
            return "null";
        }
    };

    private static final PartitionResponse EMPTY_RESPONSE = new PartitionResponse(new int[0], new Object[0]);

    private OperationFactory operationFactory;
    private int[] partitions;

    public PartitionIteratingOperation() {
    }

    /**
     * @param operationFactory operation factory to use
     * @param partitions       partitions to invoke on
     */
    public PartitionIteratingOperation(OperationFactory operationFactory, int[] partitions) {
        this.operationFactory = operationFactory;
        this.partitions = partitions;
    }

    public OperationFactory getOperationFactory() {
        return operationFactory;
    }

    @Override
    public boolean returnsResponse() {
        // since this call is non blocking, we don't have a response. The response is send when the actual operations complete.
        return false;
    }

    @Override
    public void run() throws Exception {
        // partitions may be empty if the node has joined and didn't get any partitions yet
        // a generic operation may already execute on it.
        if (partitions.length == 0) {
            this.sendResponse(EMPTY_RESPONSE);<commit_msg>Fixed FindBugs issue in PartitionIteratingOperation<commit_after>/*
 * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.spi.impl.operationservice.impl.operations;

import com.hazelcast.client.impl.operations.OperationFactoryWrapper;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spi.NodeEngine;
import com.hazelcast.spi.Operation;
import com.hazelcast.spi.OperationAccessor;
import com.hazelcast.spi.OperationFactory;
import com.hazelcast.spi.OperationResponseHandler;
import com.hazelcast.spi.OperationService;
import com.hazelcast.spi.impl.SpiDataSerializerHook;
import com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl;
import com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse;
import com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;

import static com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareFactoryAccessor.extractPartitionAware;

/**
 * Executes Operations on one or more partitions.
 * <p>
 * THe execution used to be synchronous; so the thread executing this PartitionIteratingOperation would block till all
 * the child requests are done. In 3.8 this is made asynchronous so that the thread isn't consumed and available for
 * other tasks. On each partition operation an {@link OperationResponseHandler} is set, that sends the result to the
 * caller when all responses have completed.
 */
public final class PartitionIteratingOperation extends Operation implements IdentifiedDataSerializable {

    private static final Object NULL = new Object() {
        @Override
        public String toString() {
            return "null";
        }
    };

    private static final PartitionResponse EMPTY_RESPONSE = new PartitionResponse(new int[0], new Object[0]);

    private OperationFactory operationFactory;
    private int[] partitions;

    public PartitionIteratingOperation() {
    }

    /**
     * @param operationFactory operation factory to use
     * @param partitions       partitions to invoke on
     */
    @SuppressFBWarnings("EI_EXPOSE_REP2")
    public PartitionIteratingOperation(OperationFactory operationFactory, int[] partitions) {
        this.operationFactory = operationFactory;
        this.partitions = partitions;
    }

    public OperationFactory getOperationFactory() {
        return operationFactory;
    }

    @Override
    public boolean returnsResponse() {
        // since this call is non blocking, we don't have a response. The response is send when the actual operations complete.
        return false;
    }

    @Override
    public void run() throws Exception {
        // partitions may be empty if the node has joined and didn't get any partitions yet
        // a generic operation may already execute on it.
        if (partitions.length == 0) {
            this.sendResponse(EMPTY_RESPONSE);
{'fraction_non_alphanumeric': 0.07448664608777346, 'fraction_numerical': 0.004697356059589317, 'mean_word_length': 4.065941536369817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5941890', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1931, 'n_words': 646}