Package com.sun.mail.util.logging
Class DurationFilter
- java.lang.Object
-
- com.sun.mail.util.logging.DurationFilter
-
- All Implemented Interfaces:
Filter
public class DurationFilter extends Object implements Filter
A filter used to limit log records based on a maximum generation rate. The duration specified is used to compute the record rate and the amount of time the filter will reject records once the rate has been exceeded. Once the rate is exceeded records are not allowed until the duration has elapsed.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.- <filter-name>.records the max number of records per duration.
A numeric long integer or a multiplication expression can be used as the
value. (defaults to
1000
) - <filter-name>.duration the number of milliseconds to suppress
log records from being published. This is also used as duration to determine
the log record rate. A numeric long integer or a multiplication expression
can be used as the value. If the
java.time
package is available then an ISO-8601 duration format ofPnDTnHnMn.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 toPT15M
)
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
- Since:
- JavaMail 1.5.5
-
-
Constructor Summary
Constructors Constructor Description DurationFilter()
Creates the filter using the default properties.DurationFilter(long records, long duration)
Creates the filter using the given properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Determines if this filter is equal to another filter.int
hashCode()
Returns a hash code value for this filter.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(LogRecord record)
Check if the given log record should be published.String
toString()
Returns a string representation of this filter.
-
-
-
Constructor Detail
-
DurationFilter
public DurationFilter()
Creates the filter using the default properties.
-
DurationFilter
public DurationFilter(long records, long duration)
Creates the filter using the given properties. Default values are used if any of the given values are outside the allowed range.- Parameters:
records
- the number of records per duration.duration
- the number of milliseconds to suppress log records from being published.
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Determines if this filter is equal to another filter.
-
isIdle
public boolean isIdle()
Determines if this filter is able to accept the maximum number of log records for this instant in time. The result is a best-effort estimate and should be considered out of date as soon as it is produced. This method is designed for use in monitoring the state of this filter.- Returns:
- true if the filter is idle; false otherwise.
-
hashCode
public int hashCode()
Returns a hash code value for this filter.
-
isLoggable
public boolean isLoggable(LogRecord record)
Check if the given log record should be published. This method will modify the internal state of this filter.- Specified by:
isLoggable
in interfaceFilter
- Parameters:
record
- the log record to check.- Returns:
- true if allowed; false otherwise.
- Throws:
NullPointerException
- if given record is null.
-
isLoggable
public boolean isLoggable()
Determines if this filter will accept log records for this instant in time. The result is a best-effort estimate and should be considered out of date as soon as it is produced. This method is designed for use in monitoring the state of this filter.- Returns:
- true if the filter is not saturated; false otherwise.
-
-