java.lang.Object
org.eclipse.angus.mail.util.logging.DurationFilter
- All Implemented Interfaces:
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.timepackage is available then an ISO-8601 duration format ofPnDTnHnMn.nScan 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:
org.eclipse.angus.mail.util.logging.MailHandler.filter = org.eclipse.angus.mail.util.logging.DurationFilter
org.eclipse.angus.mail.util.logging.MailHandler.capacity = 1000
org.eclipse.angus.mail.util.logging.DurationFilter.records = 2L * 1000L
org.eclipse.angus.mail.util.logging.DurationFilter.duration = PT6M
- Since:
- JavaMail 1.5.5
-
Constructor Summary
ConstructorsConstructorDescriptionCreates the filter using the default properties.DurationFilter(long records, long duration) Creates the filter using the given properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected DurationFilterclone()Creates a copy of this filter that retains the filter settings but does not include the current filter state.booleanDetermines if this filter is equal to another filter.longGets the duration in milliseconds used to determine the log record rate.longGets the max number of records per duration.inthashCode()Returns a hash code value for this filter.booleanisIdle()Determines if this filter is able to accept the maximum number of log records for this instant in time.booleanDetermines if this filter will accept log records for this instant in time.booleanisLoggable(LogRecord record) Check if the given log record should be published.voidsetDurationMillis(long duration) Sets the duration in milliseconds used to determine the log record rate.voidsetRecords(long records) Sets the max number of records per duration.toString()Returns a string representation of this filter.
-
Constructor Details
-
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 Details
-
equals
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
Check if the given log record should be published. This method will modify the internal state of this filter.- Specified by:
isLoggablein 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.
-
getRecords
public long getRecords()Gets the max number of records per duration.- Returns:
- the max number of records per duration.
- Throws:
SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- Angus Mail 2.0.3
-
setRecords
public void setRecords(long records) Sets the max number of records per duration.- Parameters:
records- the max number of records per duration.- Throws:
SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- Angus Mail 2.0.3
-
setDurationMillis
public void setDurationMillis(long duration) Sets the duration in milliseconds used to determine the log record rate.- Parameters:
duration- in milliseconds to determine the log record rate.- Throws:
SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- Angus Mail 2.0.3
-
getDurationMillis
public long getDurationMillis()Gets the duration in milliseconds used to determine the log record rate.- Returns:
- duration in milliseconds used to determine the log record rate.
- Throws:
SecurityException- if a security manager exists and the caller does not haveLoggingPermission("control").- Since:
- Angus Mail 2.0.3
-
toString
Returns a string representation of this filter. The result is a best-effort estimate and should be considered out of date as soon as it is produced. -
clone
Creates a copy of this filter that retains the filter settings but does not include the current filter state. The newly create clone acts as if it has never seen any records.- Overrides:
clonein classObject- Returns:
- a copy of this filter.
- Throws:
CloneNotSupportedException- if this filter is not allowed to be cloned.
-