public abstract class QDFilter extends Object implements SubscriptionFilter, StableSubscriptionFilter, RecordFilter
SubscriptionFilter
and should be
preferably used instead of it. Unlike SubscriptionFilter
convention to use null when
there is no filter (anything is accepted), this class usage convention is to never use null.
The constant ANYTHING
is provided for this purpose.
accept
method do not change over time.Modifier and Type | Class and Description |
---|---|
static class |
QDFilter.Kind |
static class |
QDFilter.SyntaxPrecedence |
static class |
QDFilter.Updated
Represents the most recent (updated) version of the dynamic filter.
|
static interface |
QDFilter.UpdateListener
Filter update notification interface.
|
Modifier and Type | Field and Description |
---|---|
static QDFilter |
ANYTHING
Filter that accepts everything.
|
static QDFilter |
NOTHING
Filter that does not accept anything.
|
Modifier | Constructor and Description |
---|---|
protected |
QDFilter(DataScheme scheme) |
protected |
QDFilter(DataScheme scheme,
QDFilter source)
Use this constructor to create an updated instance of dynamic filter.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
accept(QDContract contract,
DataRecord record,
int cipher,
String symbol)
Returns true if this filter accepts a given record and symbol on the specified contract.
|
boolean |
accept(RecordCursor cur)
Returns true if record pointed to by this cursor is accepted.
|
boolean |
acceptRecord(DataRecord record,
int cipher,
String symbol)
Deprecated.
Use
accept(QDContract, DataRecord, int, String)
to filter taking contract into account. |
void |
addUpdateListener(QDFilter.UpdateListener listener)
Adds listener for
dynamic filter. |
static void |
checkShortName(String name)
Checks validity of the short-name for the filter.
|
protected void |
dynamicTrackingStart()
This method is called under
synchronized(getUpdated()) each time listeners list becomes non-empty. |
protected void |
dynamicTrackingStop()
This method is called under
synchronized(getUpdated()) each time listeners list becomes empty. |
protected void |
fireFilterUpdated(QDFilter updatedFilter)
Fires notification about filter update and clears the list of listeners.
|
static QDFilter |
fromFilter(SubscriptionFilter filter,
DataScheme scheme)
Converts a legacy
SubscriptionFilter implementation into QDFilter instance. |
String |
getDefaultName()
Composes default string representation of the filter.
|
QDFilter.Kind |
getKind()
Returns a kind of this filter that constrains and defines its overall behaviour.
|
DataScheme |
getScheme()
Returns scheme that this filter works for.
|
SymbolSet |
getSymbolSet()
Returns a set of symbols that corresponds to this filter.
|
QDFilter.SyntaxPrecedence |
getSyntaxPrecedence() |
QDFilter.Updated |
getUpdated()
Returns an object that tracks the most-recent version of the
dynamic filter. |
QDFilter |
getUpdatedFilter()
Returns new value of this filter if this is a
dynamic filter that has updated. |
boolean |
hasShortName()
Returns
true if this filter has project-specified short name of lower-case English letters. |
boolean |
isDynamic()
Returns
true if this filter is dynamic, that is it can update and send the corresponding
notification. |
boolean |
isFast()
Returns
true if this filter is fast, that is it can be quickly checked without blocking. |
boolean |
isStable()
Returns
true if this filter is stable, that is the decision of its
accept method never changes for a given set of
arguments even from restart to restart and from one JVM to another. |
QDFilter |
negate()
Returns negation of this filter.
|
protected QDFilter |
produceUpdatedFilter()
This method is called under
synchronized(this) when fireFilterUpdated
is called with null argument to synchronously produce updated instance of this filter. |
void |
removeUpdateListener(QDFilter.UpdateListener listener)
Removes listener for
dynamic filter. |
void |
setName(String name)
Sets a custom string representation for this filter.
|
void |
setNameOrDefault(String name)
Sets a custom string representation for this filter if its no longer than a default one.
|
void |
setShortName(String name)
Sets a short-name string representation for this filter.
|
QDFilter |
toStableFilter()
Returns a stable filter that is the same or more encompassing as this filter.
|
String |
toString()
Returns a string representation of this filter.
|
QDFilter |
unwrap()
Unwraps filter that wraps another filter for performance reasons only (functionally identical to its delegate).
|
public static final QDFilter ANYTHING
public static final QDFilter NOTHING
protected QDFilter(DataScheme scheme)
protected QDFilter(DataScheme scheme, QDFilter source)
public final DataScheme getScheme()
public QDFilter.Kind getKind()
public SymbolSet getSymbolSet()
null
when this filter does not have a symbol set.public abstract boolean accept(QDContract contract, DataRecord record, int cipher, String symbol)
contract
- The specified contract. Can be null when contract is unknown/unspecified/any.record
- The record.cipher
- The cipher.symbol
- The symbol.public String toString()
QDFilterFactory
.
To parse this string representation back into the instance of this class use
CompositeFilters.valueOf(String, DataScheme)
.
Do not override this method. Override getDefaultName()
instead.
public QDFilter.SyntaxPrecedence getSyntaxPrecedence()
public void setName(String name)
toString()
method.
It can be an arbitrarily complex expression, but this string representation should be parseable into this filter via QDFilterFactory
.
To parse this string representation back into the instance of this class use
CompositeFilters.valueOf(String, DataScheme)
.name
- a custom string representation for this filter.public void setShortName(String name)
checks
validity of the short name (must contain only lower-case English letters) and sets the name
just like setName(String)
, but with the difference that hasShortName()
will return true
.
Complex filter transformations (logical operations) try to retain this name.name
- a short-name string representation for this filter.public boolean hasShortName()
true
if this filter has project-specified short name of lower-case English letters.
Complex filter transformations (logical operations) try to retain this name.public void setNameOrDefault(String name)
QDFilterFactory
.
To parse this string representation back into the instance of this class use
CompositeFilters.valueOf(String, DataScheme)
.name
- a custom string representation for this filter.public String getDefaultName()
QDFilterFactory
.
To parse this string representation back into the instance of this class use
CompositeFilters.valueOf(String, DataScheme)
.
This method must be overriden in custom QDFilter
implementations.
This implementation returns null
.
public final boolean acceptRecord(DataRecord record, int cipher, String symbol)
accept(QDContract, DataRecord, int, String)
to filter taking contract into account.SubscriptionFilter
interface.acceptRecord
in interface SubscriptionFilter
public final boolean accept(RecordCursor cur)
RecordFilter
accept
in interface RecordFilter
public QDFilter negate()
new NotFilter
(this)
.public QDFilter toStableFilter()
ANYTHING
, which means that this filter is not stable
(it is dynamic) and the only stable extension of it constitutes everything.
Stable filters must return this
as a result of this method. The result of this method
satisfies the following constrains:
result.toStableFilter() == result
this.accept(...)
implies result.accept(...)
.
result.toString()
must parse back to the same filter via data scheme's
SubscriptionFilterFactory
.
This method shall never return null.
toStableFilter
in interface StableSubscriptionFilter
public boolean isStable()
true
if this filter is stable, that is the decision of its
accept
method never changes for a given set of
arguments even from restart to restart and from one JVM to another.
Returns false if filter is dynamic.
This implementation returns true
when toStableFilter() == this
.
All overriding implementations have equivalent behavior.
toStableFilter()
public boolean isFast()
true
if this filter is fast, that is it can be quickly checked without blocking.
There filters are checked under the collector's global lock when processing subscription messages.
On the contrast, slow filters are checked outside of global lock when processing subscription messages.
This implementation returns false
and is designed for override.
public QDFilter unwrap()
This implementation returns this
and is designed for override in wrapping filter implelentations.
public boolean isDynamic()
true
if this filter is dynamic, that is it can update and send the corresponding
notification. Use getUpdatedFilter()
to get the most recent instance of the dynamic filter.
This implementation returns false
and is designed for override.
public QDFilter.Updated getUpdated()
dynamic
filter.dynamic
filter.public QDFilter getUpdatedFilter()
dynamic
filter that has updated.
Returns this if this filter has not updated. This method always returns this when this filter is not dynamic.
This method returns the most recent new filter in series of updates that has happened so far.
Use addUpdateListener
method to get notification on updates.
This method is a more efficient shortcut for
getUpdated
().getFilter
()
.public final void addUpdateListener(QDFilter.UpdateListener listener)
dynamic
filter. When this filter
is not dynamic this method does nothing. The listener's
filterUpdated
method is invoked
at most once during lifetime of a filter on it update. If filter
was already updated when this method was invoked, then listener
is invoked immediately. You don't have to remove
invoked listeners, as they are removed automatically when fired.
Use
to get notification every time when listener updates (as opposed to just once).getUpdated
().addUpdateListener
(listener)
public void removeUpdateListener(QDFilter.UpdateListener listener)
dynamic
filter. When this filter
is not dynamic this method does nothing.protected void fireFilterUpdated(QDFilter updatedFilter)
this
argument or when filter was already updated.
Note, that the value of updatedFilter
must be produced by invoking a special
constructor QDFilter(DataScheme, QDFilter)
.updatedFilter
- the new instance of this filter. When updateFilter is null this method uses
produceUpdatedFilter()
under synchronized(this)
section
to synchronously get the actual value of updated filter.protected void dynamicTrackingStart()
synchronized(getUpdated())
each time listeners list becomes non-empty.
This implementation does nothing and is designed for override to allocate resources for tracking
changes of this dynamic filter. This method is never invoked for non-dynamic filters.
This method is invoked only when this instance is the most up-to-date version of dynamic filter.protected void dynamicTrackingStop()
synchronized(getUpdated())
each time listeners list becomes empty.
This implementation does nothing and is designed for override to free resources for tracking
changes of this dynamic filter. This method is never invoked for non-dynamic filters.
This method is invoked only after dynamicTrackingStart()
was invoked.protected QDFilter produceUpdatedFilter()
synchronized(this)
when fireFilterUpdated
is called with null
argument to synchronously produce updated instance of this filter.
Note, that the result of this method must be produced by invoking a special
constructor QDFilter(DataScheme, QDFilter)
.public static QDFilter fromFilter(SubscriptionFilter filter, DataScheme scheme)
SubscriptionFilter
implementation into QDFilter
instance.
This method never returns null. When filter
is null, the result is ANYTHING
.
StableSubscriptionFilter
implementations are also supported properly by this method.filter
- The legacy filter.scheme
- The data scheme that this filter works for.
It may be null if scheme is unknown/any.IllegalArgumentException
- when filter is a subclass of QDFilter
with a different scheme.public static void checkShortName(String name)
IllegalArgumentException
- if not valid.Copyright © 2002-2018 Devexperts LLC. All Rights Reserved.