public class DurationFilter
extends java.lang.Object
implements java.util.logging.Filter
By default each DurationFilter
is initialized using the following
LogManager configuration properties where <filter-name>
refers to the
fully qualified class name of the handler. If properties are not defined, or
contain invalid values, then the specified default values are used.
1000
)
java.time
package is available then
an ISO-8601 duration format of PnDTnHnMn.nS
can be used as the value.
The suffixes of "D", "H", "M" and "S" are for days, hours, minutes and
seconds. The suffixes must occur in order. The seconds can be specified with
a fractional component to declare milliseconds. (defaults to PT15M
)
For example, the settings to limit MailHandler
with a default
capacity to only send a maximum of two email messages every six minutes would
be as follows:
com.sun.mail.util.logging.MailHandler.filter = com.sun.mail.util.logging.DurationFilter
com.sun.mail.util.logging.MailHandler.capacity = 1000
com.sun.mail.util.logging.DurationFilter.records = 2L * 1000L
com.sun.mail.util.logging.DurationFilter.duration = PT6M
Modifier and Type | Field and Description |
---|---|
private long |
count
The number of records seen for the current duration.
|
private long |
duration
The duration in milliseconds used to determine the rate.
|
private long |
peak
The most recent record time seen for the current duration.
|
private long |
records
The number of expected records per duration.
|
private long |
start
The start time for the current duration.
|
Constructor and Description |
---|
DurationFilter()
Creates the filter using the default properties.
|
DurationFilter(long records,
long duration)
Creates the filter using the given properties.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
accept(long millis)
Determines if the record is loggable by time.
|
private static long |
checkDuration(long duration)
Converts the duration to a valid duration.
|
private static long |
checkRecords(long records)
Converts record count to a valid record count.
|
protected DurationFilter |
clone()
Creates a copy of this filter that retains the filter settings but does
not include the current filter state.
|
boolean |
equals(java.lang.Object obj)
Determines if this filter is equal to another filter.
|
int |
hashCode()
Returns a hash code value for this filter.
|
private long |
initLong(java.lang.String suffix)
Reads a long value or multiplication expression from the LogManager.
|
boolean |
isIdle()
Determines if this filter is able to accept the maximum number of log
records for this instant in time.
|
boolean |
isLoggable()
Determines if this filter will accept log records for this instant in
time.
|
boolean |
isLoggable(java.util.logging.LogRecord record)
Check if the given log record should be published.
|
private boolean |
isTimeEntry(java.lang.String suffix,
java.lang.String value)
Determines if the given suffix can be a time unit and the value is
encoded as an ISO ISO-8601 duration format.
|
private static long |
multiplyExact(long x,
long y)
Multiply and check for overflow.
|
private boolean |
test(long limit,
long millis)
Checks if this filter is not saturated or bellow a maximum rate.
|
private static java.lang.String[] |
tokenizeLongs(java.lang.String value)
Parse any long value or multiplication expressions into tokens.
|
java.lang.String |
toString()
Returns a string representation of this filter.
|
private final long records
private final long duration
private long count
private long peak
private long start
public DurationFilter()
public DurationFilter(long records, long duration)
records
- the number of records per duration.duration
- the number of milliseconds to suppress log records from
being published.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the given object.public boolean isIdle()
public int hashCode()
hashCode
in class java.lang.Object
public boolean isLoggable(java.util.logging.LogRecord record)
isLoggable
in interface java.util.logging.Filter
record
- the log record to check.java.lang.NullPointerException
- if given record is null.public boolean isLoggable()
public java.lang.String toString()
toString
in class java.lang.Object
protected DurationFilter clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if this filter is not allowed to be
cloned.private boolean test(long limit, long millis)
limit
- the number of records allowed to be under the rate.millis
- the current time in milliseconds.private boolean accept(long millis)
millis
- the log record milliseconds.private long initLong(java.lang.String suffix)
suffix
- a dot character followed by the key name.java.lang.NullPointerException
- if suffix is null.private boolean isTimeEntry(java.lang.String suffix, java.lang.String value)
suffix
- the suffix property.value
- the value of the property.java.lang.IndexOutOfBoundsException
- if value is empty.java.lang.NullPointerException
- if either argument is null.private static java.lang.String[] tokenizeLongs(java.lang.String value)
value
- the expression or value.java.lang.NullPointerException
- if the given value is null.java.lang.NumberFormatException
- if the expression is invalid.private static long multiplyExact(long x, long y)
java.lang.Math.multiplyExact
when JavaMail requires JDK 8.x
- the first value.y
- the second value.java.lang.ArithmeticException
- if overflow is detected.private static long checkRecords(long records)
records
- the record count.private static long checkDuration(long duration)
duration
- the duration to check.