if (getLifecycleState() == LifecycleState.START // does not support reconfig when running
|| getLifecycleState() == LifecycleState.ERROR)
stop();
if (totalStored == null) {
totalStored = new Semaphore(0);
}
if (channelCounter == null) {
channelCounter = new ChannelCounter(getName());
}
// 1) Memory Capacity
Integer newMemoryCapacity;
try {
newMemoryCapacity = context.getInteger(MEMORY_CAPACITY
, defaultMemoryCapacity);
if (newMemoryCapacity == null) {
newMemoryCapacity = defaultMemoryCapacity;
}
if (newMemoryCapacity < 0) {
throw new NumberFormatException(MEMORY_CAPACITY + " must be >= 0");
}
} catch(NumberFormatException e) {
newMemoryCapacity = defaultMemoryCapacity;
LOGGER.warn("Invalid " + MEMORY_CAPACITY + " specified, initializing " +
getName() + " channel to default value of {}", defaultMemoryCapacity);
}
try {
resizePrimaryQueue(newMemoryCapacity);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// overflowTimeout - wait time before switching to overflow when mem is full
try {
Integer newOverflowTimeout =
context.getInteger(OVERFLOW_TIMEOUT, defaultOverflowTimeout);
overflowTimeout = (newOverflowTimeout != null) ? newOverflowTimeout
: defaultOverflowTimeout;
} catch(NumberFormatException e) {
LOGGER.warn("Incorrect value for " + getName() + "'s " + OVERFLOW_TIMEOUT
+ " setting. Using default value {}", defaultOverflowTimeout);
overflowTimeout = defaultOverflowTimeout;
}
try {
Integer newThreshold = context.getInteger(OVERFLOW_DEACTIVATION_THRESHOLD);
overflowDeactivationThreshold = (newThreshold != null) ?
newThreshold/100.0
: defaultOverflowDeactivationThreshold / 100.0;
} catch(NumberFormatException e) {
LOGGER.warn("Incorrect value for " + getName() + "'s " +
OVERFLOW_DEACTIVATION_THRESHOLD + ". Using default value {} %",
defaultOverflowDeactivationThreshold);
overflowDeactivationThreshold = defaultOverflowDeactivationThreshold / 100.0;
}
// 3) Memory consumption control
try {
byteCapacityBufferPercentage =
context.getInteger(BYTE_CAPACITY_BUFFER_PERCENTAGE
, defaultByteCapacityBufferPercentage);
} catch(NumberFormatException e) {
LOGGER.warn("Error parsing " + BYTE_CAPACITY_BUFFER_PERCENTAGE + " for "
+ getName() + ". Using default="
+ defaultByteCapacityBufferPercentage + ". " + e.getMessage());
byteCapacityBufferPercentage = defaultByteCapacityBufferPercentage;
}
try {
avgEventSize = context.getInteger(AVG_EVENT_SIZE, defaultAvgEventSize);
} catch ( NumberFormatException e) {
LOGGER.warn("Error parsing " + AVG_EVENT_SIZE + " for " + getName()
+ ". Using default = " + defaultAvgEventSize + ". "
+ e.getMessage());
avgEventSize = defaultAvgEventSize;
}
try {
byteCapacity = (int) ((context.getLong(BYTE_CAPACITY, defaultByteCapacity) * (1 - byteCapacityBufferPercentage * .01 )) / avgEventSize);
if (byteCapacity < 1) {
byteCapacity = Integer.MAX_VALUE;
}
} catch(NumberFormatException e) {
LOGGER.warn("Error parsing " + BYTE_CAPACITY + " setting for " + getName()
+ ". Using default = " + defaultByteCapacity + ". "
+ e.getMessage());
byteCapacity = (int)
( (defaultByteCapacity * (1 - byteCapacityBufferPercentage * .01 ))
/ avgEventSize);
}
if (bytesRemaining == null) {
bytesRemaining = new Semaphore(byteCapacity);
lastByteCapacity = byteCapacity;
} else {
if (byteCapacity > lastByteCapacity) {
bytesRemaining.release(byteCapacity - lastByteCapacity);
lastByteCapacity = byteCapacity;