Atavism Version 2018.1AGIS API

atavism.server.messages
Class PerceptionFilter

java.lang.Object
  extended by atavism.msgsys.Filter
      extended by atavism.server.messages.PerceptionFilter
All Implemented Interfaces:
IFilter, IMessageTypeFilter, Marshallable
Direct Known Subclasses:
ObjectTracker.TrackerFilter, SubObjectFilter

public class PerceptionFilter
extends Filter
implements Marshallable, IMessageTypeFilter

Match messages by message type and a list of target and subject OIDs. One of the message types should be used by class PerceptionMessage. This filter should be used in conjunction with a PerceptionTrigger.

Conceptually, the PerceptionFilter is a set of subject OIDs that match SubjectMessages and a set of target OIDs that match TargetMessages.

The subscriber maintains a set of target OIDs in the filter. Filter updates are used to keep the producing agent filters in-sync. The producers maintain a set of subject OIDs in the filter by inspecting all PerceptionMessages matched by the filter. The filter's subject OIDs are a union of all the OIDs perceivable by the filter's target OIDs. The filter's subject OIDs are updated via a PerceptionTrigger on the subscription. The producers only update their own copy of the PerceptionFilter. The subscriber should also inspect PerceptionMessages and use filter updates to keep the other subscribers in-sync (those that don't publish PerceptionMessages).

PerceptionFilter supports FilterUpdate with fields FIELD_TARGETS and FIELD_SUBJECTS. Operations FilterUpdate.OP_ADD and FilterUpdate.OP_REMOVE are supported. Use MessageAgent.applyFilterUpdate() to apply a filter update.


Nested Class Summary
protected  class PerceptionFilter.IntHolder
           
protected  class PerceptionFilter.SubjectInfo
           
static class PerceptionFilter.TypedSubject
           
 
Field Summary
static int FIELD_SUBJECTS
          Subjects field id for FilterUpdate
static int FIELD_TARGETS
          Targets field id for FilterUpdate
 
Constructor Summary
PerceptionFilter()
           
PerceptionFilter(java.util.Collection<MessageType> types)
          Match messages by message type.
 
Method Summary
 boolean addSubject(OID oid)
          Add a subject to the filter's subject OIDs.
 boolean addSubjectIfMissing(OID oid)
          Add a subject to the filter's subject OIDs if not already present.
 boolean addTarget(OID oid)
          Add a target to the filter's target OIDs.
 void addType(MessageType type)
          Add to the matching message types.
static void addUpdateTrigger(PerceptionUpdateTrigger updateTrigger)
           
 boolean applyFilterUpdate(FilterUpdate update, AgentHandle sender, SubscriptionHandle sub)
          (Internal use only) Called by the MessageAgent to apply a FilterUpdate.
 boolean getMatchAllSubjects()
          True if the local filter matches all subjects.
 boolean getMatchSubjects()
          True if the remote filter matches subjects added by the subscriber.
 java.util.Collection<MessageType> getMessageTypes()
          Get the matching message types.
 java.util.List<ObjectType> getSubjectObjectTypes()
          Get subject object type filter.
 boolean hasSubject(OID oid)
          True if subject is in the filter.
 boolean hasTarget(OID oid)
          True if subject is in the filter.
 void marshalObject(AOByteBuffer buf)
          Custom marshaller
 boolean matchMessageType(java.util.Collection<MessageType> types)
          True if the given types intersects the filter's message types.
 boolean matchRemaining(Message message)
          True if the message matches filter criteria.
 boolean removeSubject(OID oid)
          Remove a subject from the filter's subject OIDs.
 boolean removeTarget(OID oid)
          Remove a target from the filter's target OIDs.
 void setMatchAllSubjects(boolean match)
          Match all subject OIDs in the local filter.
 void setMatchSubjects(boolean match)
          Match subjects added by the subscriber.
 void setSubjectObjectTypes(java.util.Collection<ObjectType> subjectTypes)
          Set subject object types for which you want SubjectMessages.
 void setTypes(java.util.Collection<MessageType> types)
          Set the message types to match.
 java.lang.String toString()
           
protected  java.lang.String toStringInternal()
           
 java.lang.Object unmarshalObject(AOByteBuffer buf)
          Custom marshaller
 
Methods inherited from class atavism.msgsys.Filter
applyFilterUpdate, getReceiveFilterTable, getResponderReceiveFilterTable, getResponderSendFilterTable, getSendFilterTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface atavism.msgsys.IFilter
getReceiveFilterTable, getResponderReceiveFilterTable, getResponderSendFilterTable, getSendFilterTable
 

Field Detail

FIELD_TARGETS

public static final int FIELD_TARGETS
Targets field id for FilterUpdate

See Also:
Constant Field Values

FIELD_SUBJECTS

public static final int FIELD_SUBJECTS
Subjects field id for FilterUpdate

See Also:
Constant Field Values
Constructor Detail

PerceptionFilter

public PerceptionFilter()

PerceptionFilter

public PerceptionFilter(java.util.Collection<MessageType> types)
Match messages by message type.

Method Detail

setTypes

public void setTypes(java.util.Collection<MessageType> types)
Set the message types to match.

Specified by:
setTypes in interface IMessageTypeFilter

addType

public void addType(MessageType type)
Add to the matching message types.

Specified by:
addType in interface IMessageTypeFilter

getMessageTypes

public java.util.Collection<MessageType> getMessageTypes()
Get the matching message types.

Specified by:
getMessageTypes in interface IFilter
Specified by:
getMessageTypes in interface IMessageTypeFilter
Specified by:
getMessageTypes in class Filter

getMatchAllSubjects

public boolean getMatchAllSubjects()
True if the local filter matches all subjects.


setMatchAllSubjects

public void setMatchAllSubjects(boolean match)
Match all subject OIDs in the local filter. This setting only affects the local message agent and is not replicated to the producers.


getMatchSubjects

public boolean getMatchSubjects()
True if the remote filter matches subjects added by the subscriber.


setMatchSubjects

public void setMatchSubjects(boolean match)
Match subjects added by the subscriber.


addSubject

public boolean addSubject(OID oid)
Add a subject to the filter's subject OIDs. Subjects are reference counted.


addSubjectIfMissing

public boolean addSubjectIfMissing(OID oid)
Add a subject to the filter's subject OIDs if not already present.


hasSubject

public boolean hasSubject(OID oid)
True if subject is in the filter.


removeSubject

public boolean removeSubject(OID oid)
Remove a subject from the filter's subject OIDs. Subjects are reference counted.


addTarget

public boolean addTarget(OID oid)
Add a target to the filter's target OIDs. Targets are reference counted. Caller should send a FilterUpdate if addTarget() returns true.

Returns:
True if oid is a new target.

hasTarget

public boolean hasTarget(OID oid)
True if subject is in the filter.


setSubjectObjectTypes

public void setSubjectObjectTypes(java.util.Collection<ObjectType> subjectTypes)
Set subject object types for which you want SubjectMessages. For SubjectMessages, filter will match when the subject's ObjectType is in subjectTypes. This option only works when PerceptionFilter is combined with PerceptionTrigger.


getSubjectObjectTypes

public java.util.List<ObjectType> getSubjectObjectTypes()
Get subject object type filter.

See Also:
setSubjectObjectTypes(java.util.Collection)

removeTarget

public boolean removeTarget(OID oid)
Remove a target from the filter's target OIDs. Targets are reference counted. Caller should send a FilterUpdate if removeTarget() returns true.

Returns:
True if oid reference count drops to zero.

matchMessageType

public boolean matchMessageType(java.util.Collection<MessageType> types)
True if the given types intersects the filter's message types.

Specified by:
matchMessageType in interface IFilter
Specified by:
matchMessageType in class Filter

matchRemaining

public boolean matchRemaining(Message message)
True if the message matches filter criteria.

Matches TargetMessage target OID in the filter's target set.

Matches SubjectMessage subject OID in the filter's target or subject set.

Matches PerceptionMessage target OIDs in the filter's target set.

Specified by:
matchRemaining in interface IFilter
Specified by:
matchRemaining in class Filter

applyFilterUpdate

public boolean applyFilterUpdate(FilterUpdate update,
                                 AgentHandle sender,
                                 SubscriptionHandle sub)
(Internal use only) Called by the MessageAgent to apply a FilterUpdate.

Specified by:
applyFilterUpdate in interface IFilter
Overrides:
applyFilterUpdate in class Filter
See Also:
MessageAgent.applyFilterUpdate(long, atavism.msgsys.FilterUpdate)

addUpdateTrigger

public static void addUpdateTrigger(PerceptionUpdateTrigger updateTrigger)

marshalObject

public void marshalObject(AOByteBuffer buf)
Custom marshaller

Specified by:
marshalObject in interface Marshallable
Parameters:
buf - The byte buffer

unmarshalObject

public java.lang.Object unmarshalObject(AOByteBuffer buf)
Custom marshaller

Specified by:
unmarshalObject in interface Marshallable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toStringInternal

protected java.lang.String toStringInternal()
Overrides:
toStringInternal in class Filter


Copyright © 2018 Dragonsan Studios Sp. z o.o.