public abstract class AbstractOperation extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable, Clearable, ModifiableParametric
Algorithm
for more information.
To ease the task of building interfaces, each operation should provide
an annotation AbstractOperation.OperationName
to specify a user-friendly name of
the operation. Also the constructors should be annotated by AbstractOperation.OperationConstructor
to specify descriptors for its arguments. See Convert.stringToType(java.lang.String, java.lang.Class<E>, java.util.Map<java.lang.String, ? extends java.lang.Object>)
for
the list of types that can be used in operation constructors.QueryOperation
,
Algorithm
,
Serialized FormModifier and Type | Class and Description |
---|---|
static interface |
AbstractOperation.OperationConstructor
Annotation for operation constructors.
|
static interface |
AbstractOperation.OperationName
Annotation that specifies operation user-friendly name.
|
Modifier and Type | Field and Description |
---|---|
java.lang.Object |
suppData
Supplemental data object associated with this operation instance
|
static IndexComparator<java.util.UUID,AbstractOperation> |
uuidOperationComparator
Comparator to be used in buckets and storages to index & compare operations according to operation UUID.
|
Constructor and Description |
---|
AbstractOperation() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.StringBuilder |
appendArguments(java.lang.StringBuilder str)
Appends the constructor arguments of this query to the specified string.
|
protected void |
appendErrorCode(java.lang.StringBuilder str)
Appends the error code of this query to the specified string.
|
void |
clearSurplusData()
Clear non-messif data stored in operation.
|
AbstractOperation |
clone()
Create a duplicate of this operation.
|
boolean |
containsParameter(java.lang.String name)
Returns whether a parameter with the given
name exists in this parametric object. |
static <E extends AbstractOperation> |
createOperation(java.lang.Class<E> operationClass,
java.lang.Object... arguments)
Creates a new operation of the specified class.
|
abstract void |
endOperation()
End operation successfully.
|
void |
endOperation(ErrorCode errValue)
End operation with a specific error code.
|
boolean |
equals(java.lang.Object obj)
Indicates whether another operation is equal to this operation.
|
static <T extends AbstractOperation> |
getAnnotatedConstructor(java.lang.Class<? extends T> operationClass)
Searches the given
operationClass for an annotated constructor. |
static <T extends AbstractOperation> |
getAnnotatedConstructor(java.lang.Class<? extends T> operationClass,
int argumentsCount)
Searches the given
operationClass for an annotated constructor
that has the given argumentsCount . |
java.lang.Object |
getArgument(int index)
Returns argument that was passed while constructing instance.
|
int |
getArgumentCount()
Returns number of arguments that were passed while constructing this instance.
|
java.lang.String |
getArgumentString(int index)
Returns the string representation of an argument that was passed while constructing instance.
|
static java.lang.String[] |
getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass)
Returns constructor argument descriptions for the provided operation class.
|
static java.lang.String[] |
getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass,
int nArguments)
Returns constructor argument descriptions for the provided operation class with given number of arguments.
|
static java.lang.Class<?>[] |
getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass)
Returns constructor argument types for the provided operation class.
|
static java.lang.Class<?>[] |
getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass,
int nArguments)
Returns constructor arguments for the provided operation class for an annotated constructor with given number of arguments.
|
static java.lang.String |
getConstructorDescription(java.lang.Class<? extends AbstractOperation> operationClass)
Returns full constructor description for the provided operation class.
|
ErrorCode |
getErrorCode()
Returns the result code of this operation.
|
java.lang.String |
getName()
Returns the name of this operation.
|
static java.lang.String |
getName(java.lang.Class<? extends AbstractOperation> operationClass)
Returns the name of operation represented by the provided class.
|
java.util.UUID |
getOperationID()
Returns the current operation ID.
|
java.io.Serializable |
getParameter(java.lang.String name)
Returns an additional parameter with the given
name . |
<T> T |
getParameter(java.lang.String name,
java.lang.Class<? extends T> parameterClass)
Returns an additional parameter with the given
name . |
<T> T |
getParameter(java.lang.String name,
java.lang.Class<? extends T> parameterClass,
T defaultValue)
Returns an additional parameter with the given
name . |
int |
getParameterCount()
Returns the number of additional parameters.
|
java.util.Map<java.lang.String,? extends java.io.Serializable> |
getParameterMap()
Returns the map of all additional parameters.
|
java.util.Collection<java.lang.String> |
getParameterNames()
Returns a set of additional parameter names present in this object.
|
java.io.Serializable |
getRequiredParameter(java.lang.String name)
Returns an additional parameter with the given
name . |
<T> T |
getRequiredParameter(java.lang.String name,
java.lang.Class<? extends T> parameterClass)
Returns an additional parameter with the given
name . |
int |
hashCode()
Returns a hash code value based on this operation ID.
|
boolean |
isErrorCode(ErrorCode... errorCodes)
Returns whether ther result code of this operation is one of the given
errorCodes . |
boolean |
isFinished()
Returns true if this operation has finished its processing - either successfully or unsuccessfully.
|
java.io.Serializable |
removeParameter(java.lang.String name)
Removes additional
name parameter from this operation. |
java.io.Serializable |
setParameter(java.lang.String name,
java.lang.Object value)
Set an additional parameter with the given
name to the given value . |
java.lang.String |
toString()
Returns a string representation of this operation.
|
void |
updateFrom(AbstractOperation operation)
Update the error code of this operation from another operation.
|
abstract boolean |
wasSuccessful()
Returns true if this operation has finished successfuly.
|
public java.lang.Object suppData
public static final IndexComparator<java.util.UUID,AbstractOperation> uuidOperationComparator
public java.util.UUID getOperationID()
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to comparetrue
if this object is the same as the obj
argument; false
otherwisepublic int getParameterCount()
Parametric
getParameterCount
in interface Parametric
public java.util.Collection<java.lang.String> getParameterNames()
Parametric
getParameterNames
in interface Parametric
public boolean containsParameter(java.lang.String name)
Parametric
name
exists in this parametric object.containsParameter
in interface Parametric
name
- the name of the additional parameter to getname
or false if it does notpublic java.io.Serializable getParameter(java.lang.String name)
Parametric
name
.getParameter
in interface Parametric
name
- the name of the additional parameter to getname
or null if it is not setpublic java.io.Serializable getRequiredParameter(java.lang.String name) throws java.lang.IllegalArgumentException
Parametric
name
.
If the parameter with the given name
is not set, an exception is thrown.getRequiredParameter
in interface Parametric
name
- the name of the additional parameter to getname
java.lang.IllegalArgumentException
- if the parameter with the given name
is not setpublic <T> T getRequiredParameter(java.lang.String name, java.lang.Class<? extends T> parameterClass) throws java.lang.IllegalArgumentException, java.lang.ClassCastException
Parametric
name
.
If the parameter with the given name
is not set or is not an
instance of parameterClass
, an exception is thrown.getRequiredParameter
in interface Parametric
T
- the class of the parametername
- the name of the additional parameter to getparameterClass
- the class of the parameter to getjava.lang.IllegalArgumentException
- if the parameter with the given name
is not setjava.lang.ClassCastException
- if the parameter with the given name
is not an instance of parameterClass
public <T> T getParameter(java.lang.String name, java.lang.Class<? extends T> parameterClass, T defaultValue)
Parametric
name
.
If the parameter is not set or is not an instance of parameterClass
,
the defaultValue
is returned instead.getParameter
in interface Parametric
T
- the class of the parametername
- the name of the additional parameter to getparameterClass
- the class of the parameter to getdefaultValue
- the default value to use if the parameter is nullpublic <T> T getParameter(java.lang.String name, java.lang.Class<? extends T> parameterClass)
Parametric
name
.
If the parameter name
exists but it is not an instance of
parameterClass
, null is returned.getParameter
in interface Parametric
T
- the class of the parametername
- the name of the additional parameter to getparameterClass
- the class of the parameter to getname
or null if it is not setpublic java.util.Map<java.lang.String,? extends java.io.Serializable> getParameterMap()
Parametric
getParameterMap
in interface Parametric
public java.io.Serializable setParameter(java.lang.String name, java.lang.Object value)
ModifiableParametric
name
to the given value
.
Note that the previous value is replaced with the new one.setParameter
in interface ModifiableParametric
name
- the name of the additional parameter to setvalue
- the new value for the parametername
or null if it was not setjava.lang.ClassCastException
- if the given value is not Serializable
public java.io.Serializable removeParameter(java.lang.String name)
name
parameter from this operation.removeParameter
in interface ModifiableParametric
name
- the name of the additional parameter to removename
that was removed or null if it was not setpublic abstract boolean wasSuccessful()
public ErrorCode getErrorCode()
public boolean isErrorCode(ErrorCode... errorCodes)
errorCodes
.errorCodes
- the result codes to checkpublic boolean isFinished()
not set
,
false is returned.public void endOperation(ErrorCode errValue) throws java.lang.IllegalArgumentException
errValue
- the error code to setjava.lang.IllegalArgumentException
- if the specified error value is null or ErrorCode.NOT_SET
public abstract void endOperation()
public AbstractOperation clone() throws java.lang.CloneNotSupportedException
suppData
) is not cloned (but the reference is kept).
Note also that the answer of the query operations is not cloned but
a new collection is created.
The additional parameters are cloned - the map, not the values of the parameters.clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if the operation instance cannot be clonedpublic void updateFrom(AbstractOperation operation) throws java.lang.ClassCastException
operation
- the source operation from which to get the updatejava.lang.ClassCastException
- if the specified operation is incompatible with this operationpublic void clearSurplusData()
parameters
that are Clearable
are cleared
and the other non-primitive
parameters are removed from the parameters.clearSurplusData
in interface Clearable
protected java.lang.StringBuilder appendArguments(java.lang.StringBuilder str)
str
- the string to add the arguments toStringBuilder
to allow chainingprotected void appendErrorCode(java.lang.StringBuilder str)
was successful
, the "was successful" string is added.
Otherwise, a string "failed: " with the error code name is added.
Leading space is added.str
- the string to add the error code topublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String getName(java.lang.Class<? extends AbstractOperation> operationClass)
operationClass
- the operation class for which to get the namepublic java.lang.String getName()
public static <T extends AbstractOperation> java.lang.reflect.Constructor<T> getAnnotatedConstructor(java.lang.Class<? extends T> operationClass) throws java.lang.NoSuchMethodException
operationClass
for an annotated constructor.
The constructor with the smallest number of arguments is returned.T
- the operation classoperationClass
- the operation class to search the constructor forjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static <T extends AbstractOperation> java.lang.reflect.Constructor<T> getAnnotatedConstructor(java.lang.Class<? extends T> operationClass, int argumentsCount) throws java.lang.NoSuchMethodException
operationClass
for an annotated constructor
that has the given argumentsCount
.T
- the operation classoperationClass
- the operation class to search the constructor forargumentsCount
- number of arguments that the constructor must havejava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String[] getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the descriptions forjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String[] getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass, int nArguments) throws java.lang.NoSuchMethodException
operationClass
- class to get the descriptions fornArguments
- the number of arguments of the constructorjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.Class<?>[] getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types forjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.Class<?>[] getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass, int nArguments) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types fornArguments
- the number of arguments of the constructorjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String getConstructorDescription(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types forjava.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static <E extends AbstractOperation> E createOperation(java.lang.Class<E> operationClass, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
E
- the class of the operation that should be createdoperationClass
- the class of the operation that should be createdarguments
- arguments supplied to the constructor; they should match the types of getConstructorArguments(operationClass)java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
java.lang.IllegalArgumentException
- if the argument count or their types don't match the specified operation class constructorjava.lang.reflect.InvocationTargetException
- if there was an exception in the operation's constructorpublic java.lang.Object getArgument(int index) throws java.lang.IndexOutOfBoundsException, java.lang.UnsupportedOperationException
index
- zero-based index of an argument passed to constructorjava.lang.IndexOutOfBoundsException
- if index parameter is out of rangejava.lang.UnsupportedOperationException
- if this operation doesn't support construction argument retrievalpublic java.lang.String getArgumentString(int index) throws java.lang.IndexOutOfBoundsException, java.lang.UnsupportedOperationException
index
- zero-based index of an argument passed to constructorjava.lang.IndexOutOfBoundsException
- if index parameter is out of rangejava.lang.UnsupportedOperationException
- if this operation doesn't support construction argument retrievalpublic int getArgumentCount()