Package org.jcsp.util.filter
Class FilteredSharedChannelOutputWrapper
- java.lang.Object
-
- org.jcsp.lang.ChannelOutputWrapper
-
- org.jcsp.util.filter.FilteredChannelOutputWrapper
-
- org.jcsp.util.filter.FilteredSharedChannelOutputWrapper
-
- All Implemented Interfaces:
ChannelOutput
,Poisonable
,SharedChannelOutput
,FilteredChannelOutput
,FilteredSharedChannelOutput
,WriteFiltered
public class FilteredSharedChannelOutputWrapper extends FilteredChannelOutputWrapper implements FilteredSharedChannelOutput
This is wrapper for aSharedChannelOutput
that adds write filtering. Instances of this class can be safely used by multiple concurrent processes.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
synchObject
The synchronization object to protect the writers from each other when they read data or update the write filters.
-
Constructor Summary
Constructors Constructor Description FilteredSharedChannelOutputWrapper(SharedChannelOutput out)
Constructs a new wrapper for the given channel output end.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWriteFilter(Filter filter)
Installs a write filter defining a transformation to be applied by thewrite
method of the channel end.void
addWriteFilter(Filter filter, int index)
Installs a write filter defining a transformation to be applied by thewrite
method of the channel end at a specific index.Filter
getWriteFilter(int index)
Returns the write filter installed at the given index.int
getWriteFilterCount()
Returns the number of write filters currently installed.void
removeWriteFilter(int index)
Removes the write filter installed at the given index.void
removeWriteFilter(Filter filter)
Removes the first write filter (lowest index) matching the filter given as a parameter.void
write(java.lang.Object data)
Writes a value to the channel.-
Methods inherited from class org.jcsp.lang.ChannelOutputWrapper
poison
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jcsp.lang.Poisonable
poison
-
-
-
-
Constructor Detail
-
FilteredSharedChannelOutputWrapper
public FilteredSharedChannelOutputWrapper(SharedChannelOutput out)
Constructs a new wrapper for the given channel output end.- Parameters:
out
- the existing channel end.
-
-
Method Detail
-
write
public void write(java.lang.Object data)
Description copied from class:ChannelOutputWrapper
Writes a value to the channel.- Specified by:
write
in interfaceChannelOutput
- Overrides:
write
in classFilteredChannelOutputWrapper
- Parameters:
data
- the value to write.- See Also:
ChannelOutput
-
addWriteFilter
public void addWriteFilter(Filter filter)
Description copied from interface:WriteFiltered
Installs a write filter defining a transformation to be applied by thewrite
method of the channel end. The filter will be appended to the end of the current list, making it the last to be applied.- Specified by:
addWriteFilter
in interfaceWriteFiltered
- Overrides:
addWriteFilter
in classFilteredChannelOutputWrapper
- Parameters:
filter
- the filter to be installed; may not be null.
-
addWriteFilter
public void addWriteFilter(Filter filter, int index)
Description copied from interface:WriteFiltered
Installs a write filter defining a transformation to be applied by thewrite
method of the channel end at a specific index. If there is already a filter at that index position the existing filters are shifted to make room. If the index is greater than the number of filters already installed the filter is placed at the end.- Specified by:
addWriteFilter
in interfaceWriteFiltered
- Overrides:
addWriteFilter
in classFilteredChannelOutputWrapper
- Parameters:
filter
- the filter to be installed; may not be null.index
- the zero based index; may not be negative.
-
removeWriteFilter
public void removeWriteFilter(Filter filter)
Description copied from interface:WriteFiltered
Removes the first write filter (lowest index) matching the filter given as a parameter. The filter removed,r
, will satisfy the conditionr.equals (filter)
. The remaining filters are shifted to close the gap in the index allocation.- Specified by:
removeWriteFilter
in interfaceWriteFiltered
- Overrides:
removeWriteFilter
in classFilteredChannelOutputWrapper
- Parameters:
filter
- the filter to be removed; may not be null.
-
removeWriteFilter
public void removeWriteFilter(int index)
Description copied from interface:WriteFiltered
Removes the write filter installed at the given index. The remaining filters are shifted to close the gap in the index allocation.- Specified by:
removeWriteFilter
in interfaceWriteFiltered
- Overrides:
removeWriteFilter
in classFilteredChannelOutputWrapper
- Parameters:
index
- zero-based index of the filter to be removed.
-
getWriteFilter
public Filter getWriteFilter(int index)
Description copied from interface:WriteFiltered
Returns the write filter installed at the given index.- Specified by:
getWriteFilter
in interfaceWriteFiltered
- Overrides:
getWriteFilter
in classFilteredChannelOutputWrapper
- Parameters:
index
- zero-based index of the filter to return.- Returns:
- the filter at that position.
-
getWriteFilterCount
public int getWriteFilterCount()
Description copied from interface:WriteFiltered
Returns the number of write filters currently installed.- Specified by:
getWriteFilterCount
in interfaceWriteFiltered
- Overrides:
getWriteFilterCount
in classFilteredChannelOutputWrapper
-
-