tuwien.auto.calimero.buffer
Class CommandFilter

java.lang.Object
  extended by tuwien.auto.calimero.buffer.CommandFilter
All Implemented Interfaces:
Configuration.NetworkFilter, Configuration.RequestFilter

public class CommandFilter
extends java.lang.Object
implements Configuration.NetworkFilter, Configuration.RequestFilter

Predefined filter for filtering KNX messages of command based datapoints into the associated network buffer configuration and handling requests for this kind of messages.

Command based messages are buffered using a LDataObjectQueue (an object of this type is also expected when the request method or getNextIndication method is invoked).


Constructor Summary
CommandFilter()
          Creates a new command filter.
 
Method Summary
 void accept(CEMI frame, Configuration c)
          Applies command based filter rules on frame.
 LDataObjectQueue.QueueItem getNextIndication()
          Returns the next available indication.
 boolean hasNewIndication()
          Returns whether new indications are available.
 void init(Configuration c)
          Does all necessary filter initializations.
 CEMILData request(KNXAddress dst, Configuration c)
          Returns the next available indication for the specified KNX address.
 void setQueueListener(LDataObjectQueue.QueueListener l)
          Sets the specified listener to receive notification of queue events of buffered queue objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandFilter

public CommandFilter()
Creates a new command filter.

Method Detail

accept

public void accept(CEMI frame,
                   Configuration c)
Applies command based filter rules on frame.

Criteria for accept:

On acceptance, the frame is stored into the configuration cache using a LDataObjectQueue with consuming read behavior and a maximum queue size of 10 items.
For uniform handling an accepted frame is always buffered with the L-data indication message code.

Specified by:
accept in interface Configuration.NetworkFilter
Parameters:
frame - cEMI frame to accept for buffering
c - the configuration this filter belongs to

getNextIndication

public LDataObjectQueue.QueueItem getNextIndication()
Returns the next available indication.

The items with the cEMI frame indications are returned in FIFO order according the time they were supplied to the filter and buffered in the first place, i.e. an earlier accepted frame is returned before an frame accepted at some later time.
Every item is only returned once by this method, after that it is no longer marked as new and will not cause hasNewIndication() to return true for it.
If no indication is available, throws KNXIllegalStateException.

Nevertheless, the queued item might be retrieved directly through the used cache (which is obtained by Configuration.getCache()). Whether or not an returned item is completely consumed from the queue in the cache, i.e. removed from the cache object in the cache, is specified in the LDataObjectQueue containing the item at creation time (which is a task of the network filter).

Note, if the accessed queue in the cache was modified between the time the indication was added and this method call in such a way, that the original indication is not available anymore (for example by removal or emptied queue), that indication might be skipped or an empty QueueItem is returned.

Returns:
queue item containing cEMI frame indication

hasNewIndication

public boolean hasNewIndication()
Returns whether new indications are available.

Returns:
true if at least one indication is available, false otherwise

init

public void init(Configuration c)
Description copied from interface: Configuration.NetworkFilter
Does all necessary filter initializations.

This method is invoked by the owning configuration.

Specified by:
init in interface Configuration.NetworkFilter
Parameters:
c - the configuration this filter is set for

request

public CEMILData request(KNXAddress dst,
                         Configuration c)
Returns the next available indication for the specified KNX address.

See getNextIndication() for more details. In contrast to that method, this method does not throw.

Specified by:
request in interface Configuration.RequestFilter
Parameters:
dst - address to request data for
c - the configuration this filter belongs to
Returns:
the cEMI data on match in buffer, null otherwise

setQueueListener

public void setQueueListener(LDataObjectQueue.QueueListener l)
Sets the specified listener to receive notification of queue events of buffered queue objects.

The listener will replace any previously set listener.

Parameters:
l - the listener to set, use null for no listener