<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.jackrabbit.oak.spi.whiteboard;

import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.apache.jackrabbit.oak.commons.jmx.JmxUtil;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

public class WhiteboardUtils {

    /**
     * JMX Domain name under which Oak related JMX MBeans are registered
     */
    public static final String JMX_OAK_DOMAIN = "org.apache.jackrabbit.oak";

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, long delayInSeconds) {
        return scheduleWithFixedDelay(whiteboard, runnable, delayInSeconds, false, false);
    }

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, long delayInSeconds, boolean runOnSingleClusterNode,
            boolean useDedicatedPool) {
        return scheduleWithFixedDelay(whiteboard, runnable, Collections.<String, Object>emptyMap(),
                delayInSeconds, runOnSingleClusterNode, useDedicatedPool);
    }

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, Map<String, Object> extraProps, long delayInSeconds, boolean runOnSingleClusterNode,
            boolean useDedicatedPool) {
        ImmutableMap.Builder<String, Object> builder = ImmutableMap.<String, Object>builder()
                .putAll(extraProps)
                .put("scheduler.period", delayInSeconds)
                .put("scheduler.concurrent", false);
        if (runOnSingleClusterNode) {
            //Make use of feature while running in Sling SLING-2979
            builder.put("scheduler.runOn", "SINGLE");
        }
        if (useDedicatedPool) {
            //Make use of dedicated threadpool SLING-5831
            builder.put("scheduler.threadPool", "oak");
        }
        return whiteboard.register(
                Runnable.class, runnable, builder.build());
    }

    public static <T> Registration registerMBean(
            Whiteboard whiteboard,
            Class<T> iface, T bean, String type, String name) {
        return registerMBean(whiteboard, iface, bean, type, name, Collections.<String, String>emptyMap());
    }

    public static <T> Registration registerMBean(
            Whiteboard whiteboard,
            Class<T> iface, T bean, String type, String name, Map<String, String> attrs) {
        try {

            Hashtable<String, String> table = new Hashtable<String, String>(attrs);
            table.put("type", JmxUtil.quoteValueIfRequired(type));
            table.put("name", JmxUtil.quoteValueIfRequired(name));
            return whiteboard.register(iface, bean, ImmutableMap.of(
                    "jmx.objectname",
                    new ObjectName(JMX_OAK_DOMAIN, table)));
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(e);
        }<commit_msg>OAK-6375: RevisionGCMbeans are not filtered correctly in the RepositoryManagement<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.jackrabbit.oak.spi.whiteboard;

import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.apache.jackrabbit.oak.commons.jmx.JmxUtil;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

public class WhiteboardUtils {

    /**
     * JMX Domain name under which Oak related JMX MBeans are registered
     */
    public static final String JMX_OAK_DOMAIN = "org.apache.jackrabbit.oak";

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, long delayInSeconds) {
        return scheduleWithFixedDelay(whiteboard, runnable, delayInSeconds, false, false);
    }

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, long delayInSeconds, boolean runOnSingleClusterNode,
            boolean useDedicatedPool) {
        return scheduleWithFixedDelay(whiteboard, runnable, Collections.<String, Object>emptyMap(),
                delayInSeconds, runOnSingleClusterNode, useDedicatedPool);
    }

    public static Registration scheduleWithFixedDelay(
            Whiteboard whiteboard, Runnable runnable, Map<String, Object> extraProps, long delayInSeconds, boolean runOnSingleClusterNode,
            boolean useDedicatedPool) {
        ImmutableMap.Builder<String, Object> builder = ImmutableMap.<String, Object>builder()
                .putAll(extraProps)
                .put("scheduler.period", delayInSeconds)
                .put("scheduler.concurrent", false);
        if (runOnSingleClusterNode) {
            //Make use of feature while running in Sling SLING-2979
            builder.put("scheduler.runOn", "SINGLE");
        }
        if (useDedicatedPool) {
            //Make use of dedicated threadpool SLING-5831
            builder.put("scheduler.threadPool", "oak");
        }
        return whiteboard.register(
                Runnable.class, runnable, builder.build());
    }

    public static <T> Registration registerMBean(
            Whiteboard whiteboard,
            Class<T> iface, T bean, String type, String name) {
        return registerMBean(whiteboard, iface, bean, type, name, Collections.<String, String>emptyMap());
    }

    public static <T> Registration registerMBean(
            Whiteboard whiteboard,
            Class<T> iface, T bean, String type, String name, Map<String, String> attrs) {
        try {

            Hashtable<String, String> table = new Hashtable<String, String>(attrs);
            table.put("type", JmxUtil.quoteValueIfRequired(type));
            table.put("name", JmxUtil.quoteValueIfRequired(name));

            ImmutableMap.Builder properties = ImmutableMap.builder();
            properties.put("jmx.objectname", new ObjectName(JMX_OAK_DOMAIN, table));
            properties.putAll(attrs);

            return whiteboard.register(iface, bean, properties.build());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(e);
        }
{'fraction_non_alphanumeric': 0.08327333813294936, 'fraction_numerical': 0.00335973122150228, 'mean_word_length': 3.241730279898219, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1895395', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2141, 'n_words': 656}