net.logstash.logback.appender.WaitStrategyFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logstash-logback-encoder Show documentation
Show all versions of logstash-logback-encoder Show documentation
Provides logback encoders, layouts, and appenders to log in JSON and other formats supported by Jackson
/**
* 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.logstash.logback.appender;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.BusySpinWaitStrategy;
import com.lmax.disruptor.LiteBlockingWaitStrategy;
import com.lmax.disruptor.PhasedBackoffWaitStrategy;
import com.lmax.disruptor.SleepingWaitStrategy;
import com.lmax.disruptor.TimeoutBlockingWaitStrategy;
import com.lmax.disruptor.WaitStrategy;
import com.lmax.disruptor.YieldingWaitStrategy;
/**
* Creates {@link WaitStrategy} objects from strings.
*/
public class WaitStrategyFactory {
private static final char PARAM_END_CHAR = '}';
private static final char PARAM_START_CHAR = '{';
private static final char PARAM_SEPARATOR_CHAR = ',';
/**
* Creates a {@link WaitStrategy} from a string.
*
* The following strategies are supported:
*
*
* - blocking - {@link BlockingWaitStrategy}
* - busySpin - {@link BusySpinWaitStrategy}
* - liteBlocking - {@link LiteBlockingWaitStrategy}
* - sleeping - {@link SleepingWaitStrategy}
* - yielding - {@link YieldingWaitStrategy}
* - phasedBackoff{spinTimeout,yieldTimeout,timeUnit,fallackStrategy} - {@link PhasedBackoffWaitStrategy}
* - spinTimeout and yieldTimeout are long values.
* timeUnit is a string name of one of the {@link TimeUnit} values.
* fallbackStrategy is a wait strategy string (e.g. blocking).
*
* - timeoutBlocking{timeout,timeUnit} - {@link TimeoutBlockingWaitStrategy}
* - timeout is a long value.
* timeUnit is a string name of one of the {@link TimeUnit} values.
*
*
*
* @throws IllegalArgumentException if an unknown wait strategy type is given, or the parameters are unable to be parsed.
*/
public static WaitStrategy createWaitStrategyFromString(String waitStrategyType) {
if (waitStrategyType == null) {
return null;
}
waitStrategyType = waitStrategyType.trim().toLowerCase();
if (waitStrategyType.isEmpty()) {
return null;
}
if (waitStrategyType.equals("blocking")) {
return new BlockingWaitStrategy();
}
if (waitStrategyType.equals("busyspin")) {
return new BusySpinWaitStrategy();
}
if (waitStrategyType.equals("liteblocking")) {
return new LiteBlockingWaitStrategy();
}
if (waitStrategyType.equals("sleeping")) {
return new SleepingWaitStrategy();
}
if (waitStrategyType.equals("yielding")) {
return new YieldingWaitStrategy();
}
if (waitStrategyType.startsWith("phasedbackoff")) {
List