Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* 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 net.openhft.chronicle.threads;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.threads.EventHandler;
import net.openhft.chronicle.core.threads.EventLoop;
import net.openhft.chronicle.core.threads.HandlerPriority;
import net.openhft.chronicle.threads.internal.EventLoopStateRenderer;
import net.openhft.chronicle.threads.internal.EventLoopThreadHolder;
import net.openhft.chronicle.threads.internal.ThreadMonitorHarness;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.LongSupplier;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.lang.String.format;
import static net.openhft.chronicle.core.io.Closeable.closeQuietly;
/**
* Composes child event loops to support all {@link HandlerPriority} priorities. This class will delegate
* any {@link EventHandler} that is installed on it (via {@link #addHandler(EventHandler)}) to a child
* event loop appropriately. See also other implementations of {@link EventLoop} in this library.
*
* Supports event loop monitoring - controlled by system property {@code MONITOR_INTERVAL_MS} and documented in README.adoc
*/
public class EventGroup
extends AbstractLifecycleEventLoop
implements EventLoop {
public static final int CONC_THREADS = Jvm.getInteger("eventGroup.conc.threads",
Jvm.getInteger("CONC_THREADS", Math.max(1, Runtime.getRuntime().availableProcessors() / 4)));
private static final long REPLICATION_MONITOR_INTERVAL_MS = Jvm.getLong("REPLICATION_MONITOR_INTERVAL_MS", 500L);
private static final long MONITOR_INTERVAL_MS = Jvm.getLong("MONITOR_INTERVAL_MS", 100L);
static final Integer REPLICATION_EVENT_PAUSE_TIME = Jvm.getInteger("replicationEventPauseTime", 20);
private static final boolean ENABLE_LOOP_BLOCK_MONITOR = !Jvm.getBoolean("disableLoopBlockMonitor");
private static final long WAIT_TO_START_MS = Jvm.getInteger("eventGroup.wait.to.start.ms", 2_000);
private final AtomicInteger counter = new AtomicInteger();
@NotNull
private final MonitorEventLoop monitor;
private final CoreEventLoop core;
private final BlockingEventLoop blocking;
@NotNull
private final Pauser pauser;
@NotNull
private final Supplier concPauserSupplier;
private final String concBinding;
private final String bindingReplication;
private final Set priorities;
@NotNull
private final List concThreads = new CopyOnWriteArrayList<>();
private final boolean daemon;
private final Pauser replicationPauser;
private VanillaEventLoop replication;
@Deprecated(/* Instead use EventGroupBuilder. TODO: make package-private and undeprecate in x.28, as only EventGroupBuilder should be using */)
@SuppressWarnings({"this-escape", "deprecation"})
public EventGroup(final boolean daemon,
@NotNull final Pauser pauser,
final Pauser replicationPauser,
final String binding,
final String bindingReplication,
@NotNull final String name,
final int concThreadsNum,
final String concBinding,
@NotNull final Supplier concPauserSupplier,
final Set priorities,
@NotNull final Supplier blockingPauserSupplier) {
super(name);
this.daemon = daemon;
this.pauser = pauser;
this.replicationPauser = replicationPauser;
this.concBinding = concBinding;
this.concPauserSupplier = concPauserSupplier;
this.bindingReplication = bindingReplication;
this.priorities = EnumSet.copyOf(priorities);
List