Class ConditionalPut
ConditionalPut is an IEntryProcessor that sets Valueif the specified condition is satisfied.
Inherited Members
Namespace: Tangosol.Util.Processor
Assembly: Coherence.dll
Syntax
public class ConditionalPut : AbstractProcessor, IEntryProcessor, IPortableObject
Remarks
While the ConditionalPut processing could be implemented via direct key-based IQueryCache operations, it is more efficient and enforces concurrency control without explicit locking.
| IInvocableCache | IConcurrentCache |
|---|---|
| filter = PresentFilter.Instance; cache.Invoke(key, new ConditionalPut(filter, value)); | cache.Replace(key, value); |
| filter = new NotFilter(PresentFilter.Instance); cache.Invoke(key, new ConditionalPut(filter, value)); | cache.PutIfAbsent(key, value); |
| filter = new EqualsFilter(IdentityExtractor.Instance, valueOld); cache.Invoke(key, new ConditionalPut(filter, valueNew)); | cache.Replace(key, valueOld, valueNew); |
Obviously, using more specific, fine-tuned filters (rather than ones based on the IdentityExtractor may provide additional flexibility and efficiency allowing the put operation to be performed conditionally on values of specific attributes (or even calculations) instead of the entire object.
Constructors
ConditionalPut()
Default constructor.
Declaration
public ConditionalPut()
ConditionalPut(IFilter, object)
Construct a ConditionalPut that updates an entry with a new value if and only if the filter applied to the entry evaluates to true.
Declaration
public ConditionalPut(IFilter filter, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| IFilter | filter | The filter to evaluate an entry. |
| object | value | A value to update an entry with. |
Remarks
The result of the Process(IInvocableCacheEntry) invocation does not return any result.
ConditionalPut(IFilter, object, bool)
Construct a ConditionalPut that updates an entry with a new value if and only if the filter applied to the entry evaluates to true.
Declaration
public ConditionalPut(IFilter filter, object value, bool ret)
Parameters
| Type | Name | Description |
|---|---|---|
| IFilter | filter | The filter to evaluate an entry. |
| object | value | A value to update an entry with. |
| bool | ret | Specifies whether or not the processor should return the current value in case it has not been updated. |
Remarks
This processor optionally returns the current value as a result of the invocation if it has not been updated (the filter evaluated to false).
Fields
m_filter
The underlying filter.
Declaration
protected IFilter m_filter
Field Value
| Type | Description |
|---|---|
| IFilter |
m_return
Specifies whether or not a return value is required.
Declaration
protected bool m_return
Field Value
| Type | Description |
|---|---|
| bool |
m_value
Specifies the new value to update an entry with.
Declaration
protected object m_value
Field Value
| Type | Description |
|---|---|
| object |
Methods
Equals(object)
Compare the ConditionalPut with another object to determine equality.
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o | The object to compare with. |
Returns
| Type | Description |
|---|---|
| bool | true iff this ConditionalPut and the passed object are equivalent ConditionalPut. |
Overrides
GetHashCode()
Determine a hash value for the ConditionalPut object according to the general GetHashCode() contract.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | An integer hash value for this ConditionalPut object. |
Overrides
Process(IInvocableCacheEntry)
Process an IInvocableCacheEntry.
Declaration
public override object Process(IInvocableCacheEntry entry)
Parameters
| Type | Name | Description |
|---|---|---|
| IInvocableCacheEntry | entry | The IInvocableCacheEntry to process. |
Returns
| Type | Description |
|---|---|
| object | The result of the processing, if any. |
Overrides
ProcessAll(ICollection)
Process a collection of IInvocableCacheEntry objects.
Declaration
public override IDictionary ProcessAll(ICollection entries)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | entries | A read-only collection of IInvocableCacheEntry objects to process. |
Returns
| Type | Description |
|---|---|
| IDictionary | A dictionary containing the results of the processing, up to one entry for each IInvocableCacheEntry that was processed, keyed by the keys of the dictionary that were processed, with a corresponding value being the result of the processing for each key. |
Overrides
ReadExternal(IPofReader)
Restore the contents of a user type instance by reading its state using the specified IPofReader object.
Declaration
public virtual void ReadExternal(IPofReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| IPofReader | reader | The IPofReader from which to read the object's state. |
Exceptions
| Type | Condition |
|---|---|
| IOException | If an I/O error occurs. |
ToString()
Return a human-readable description for this ConditionalPut.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A String description of the ConditionalPut. |
Overrides
WriteExternal(IPofWriter)
Save the contents of a POF user type instance by writing its state using the specified IPofWriter object.
Declaration
public virtual void WriteExternal(IPofWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| IPofWriter | writer | The IPofWriter to which to write the object's state. |
Exceptions
| Type | Condition |
|---|---|
| IOException | If an I/O error occurs. |