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.
/*
* 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.logging.log4j.core.util;
import aQute.bnd.annotation.Cardinality;
import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceConsumer;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.AbstractLifeCycle;
import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.ConfigurationScheduler;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.ServiceLoaderUtil;
/**
* Manages {@link FileWatcher}s.
*
* @see FileWatcher
* @see ConfigurationScheduler
*/
@ServiceConsumer(value = WatchEventService.class, resolution = Resolution.OPTIONAL, cardinality = Cardinality.MULTIPLE)
public class WatchManager extends AbstractLifeCycle {
private final class ConfigurationMonitor {
private final Watcher watcher;
private volatile long lastModifiedMillis;
public ConfigurationMonitor(final long lastModifiedMillis, final Watcher watcher) {
this.watcher = watcher;
this.lastModifiedMillis = lastModifiedMillis;
}
public Watcher getWatcher() {
return watcher;
}
private void setLastModifiedMillis(final long lastModifiedMillis) {
this.lastModifiedMillis = lastModifiedMillis;
}
@Override
public String toString() {
return "ConfigurationMonitor [watcher=" + watcher + ", lastModifiedMillis=" + lastModifiedMillis + "]";
}
}
private static class LocalUUID {
private static final long LOW_MASK = 0xffffffffL;
private static final long MID_MASK = 0xffff00000000L;
private static final long HIGH_MASK = 0xfff000000000000L;
private static final int NODE_SIZE = 8;
private static final int SHIFT_2 = 16;
private static final int SHIFT_4 = 32;
private static final int SHIFT_6 = 48;
private static final int HUNDRED_NANOS_PER_MILLI = 10000;
private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
private static final AtomicInteger COUNT = new AtomicInteger(0);
private static final long TYPE1 = 0x1000L;
private static final byte VARIANT = (byte) 0x80;
private static final int SEQUENCE_MASK = 0x3FFF;
public static UUID get() {
final long time =
((System.currentTimeMillis() * HUNDRED_NANOS_PER_MILLI) + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)
+ (COUNT.incrementAndGet() % HUNDRED_NANOS_PER_MILLI);
final long timeLow = (time & LOW_MASK) << SHIFT_4;
final long timeMid = (time & MID_MASK) >> SHIFT_2;
final long timeHi = (time & HIGH_MASK) >> SHIFT_6;
final long most = timeLow | timeMid | TYPE1 | timeHi;
return new UUID(most, COUNT.incrementAndGet());
}
}
private final class WatchRunnable implements Runnable {
// Use a hard class reference here in case a refactoring changes the class name.
private final String SIMPLE_NAME = WatchRunnable.class.getSimpleName();
@Override
public void run() {
logger.trace("{} run triggered.", SIMPLE_NAME);
for (final Map.Entry