io.jstach.rainbowgum.disruptor.DisruptorLogBuilder Maven / Gradle / Ivy
package io.jstach.rainbowgum.disruptor;
import io.jstach.rainbowgum.LogProperties;
import io.jstach.rainbowgum.LogProperty;
import io.jstach.rainbowgum.LogProperty.Property;
/**
* Builder to create {@link io.jstach.rainbowgum.LogPublisher.PublisherFactory }.
*
* Properties retrieved from LogProperties
*
* Property Pattern
* Type
* Required
* Default
* Description
*
*
* {@value PROPERTY_bufferSize }
* Integer
* true
* {@value io.jstach.rainbowgum.disruptor.DisruptorConfigurator#DEFAULT_BUFFER_SIZE }
*
*
*
*/
public final class DisruptorLogBuilder implements io.jstach.rainbowgum.LogBuilder {
/**
* The properties to be retrieved from config will have
* this prefix.
*/
static final String PROPERTY_PREFIX = "logging.publisher.{name}.";
/**
* {@value #PROPERTY_bufferSize } = java.lang.Integer
*/
static final String PROPERTY_bufferSize = PROPERTY_PREFIX + "bufferSize";
private final String propertyPrefix;
final Property property_bufferSize;
private final java.lang.String name;
private java.lang.Integer bufferSize = io.jstach.rainbowgum.disruptor.DisruptorConfigurator.DEFAULT_BUFFER_SIZE;
/**
* Create a builder for {@code io.jstach.rainbowgum.LogPublisher.PublisherFactory }.
* @param name will fill {name}
in logging.publisher.{name}.
.
*/
public DisruptorLogBuilder(
java.lang.String name
) {
java.util.Map prefixParameters = java.util.Map.of(
"name", name
);
this.propertyPrefix = LogProperties.interpolateKey(PROPERTY_PREFIX, prefixParameters);
this.name = name;
property_bufferSize = Property.builder()
.ofInt()
.build(LogProperties.interpolateKey(PROPERTY_bufferSize, prefixParameters));
}
/**
* Sets required bufferSize.
*
* Default is {@value io.jstach.rainbowgum.disruptor.DisruptorConfigurator#DEFAULT_BUFFER_SIZE }.
* @param bufferSize {@value #PROPERTY_bufferSize } = java.lang.Integer
* @return this builder.
*/
public DisruptorLogBuilder bufferSize(java.lang.Integer bufferSize) {
this.bufferSize = bufferSize;
return this;
}
/**
* Creates {@code io.jstach.rainbowgum.LogPublisher.PublisherFactory } from this builder.
* @return {@code io.jstach.rainbowgum.LogPublisher.PublisherFactory }.
*/
public io.jstach.rainbowgum.LogPublisher.PublisherFactory build() {
return io.jstach.rainbowgum.disruptor.DisruptorConfigurator.of(
this.name
, property_bufferSize.require(this.bufferSize)
);
}
@Override
public DisruptorLogBuilder fromProperties(LogProperties properties) {
var __v = LogProperty.Validator.of(this.getClass());
var _bufferSize = property_bufferSize.get(properties).or(this.bufferSize);
__v.add(_bufferSize);
__v.validate();
this.bufferSize = _bufferSize.value();
return this;
}
/**
* Turns the builder into java.util.Properties like Map skipping values that are null.
* @param consumer apply is called where first arg is key and second is value.
*/
public void toProperties(java.util.function.BiConsumer consumer) {
var _bufferSize = this.bufferSize;
if (_bufferSize != null) {
consumer.accept(property_bufferSize.key(), property_bufferSize.propertyString(_bufferSize));
}
}
/**
* The interpolated property prefix: {@value #PROPERTY_PREFIX}.
* @return resolved prefix which should end with a ".
".
*/
@Override
public String propertyPrefix() {
return this.propertyPrefix;
}
}