Class Result<T>
- java.lang.Object
-
- com.oracle.coherence.concurrent.executor.Result<T>
-
- Type Parameters:
T
- the type of result produced by theTask
- All Implemented Interfaces:
ExternalizableLite
,PortableObject
,Serializable
public class Result<T> extends Object implements ExternalizableLite, PortableObject
An immutable container representing an intermediate or final result produced by executing aTask
, typically by an individualExecutor
, including no result, a specific value or aThrowable
.If a value or
Throwable
is present, isPresent() will returntrue
and get() will return the value or throw theThrowable
.- Since:
- 21.12
- Author:
- bo
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_fPresent
Is the result present?protected Throwable
m_throwable
The throwable (when error occurred).protected T
m_value
The value (when provided).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
T
get()
Obtains the value throwable theResult
.int
hashCode()
boolean
isPresent()
boolean
isThrowable()
boolean
isValue()
Determines if the value is available (includingnull
).static <T> Result<T>
none()
Constructs anResult
representing no value.static <T> Result<T>
of(T value)
Constructs anResult
with a specific value.T
orElse(T value)
Obtains the value of theResult
if present, otherwise returns the specified value.void
readExternal(PofReader in)
Restore the contents of a user type instance by reading its state using the specified PofReader object.void
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from the passed DataInput object.static Result
throwable(Throwable throwable)
String
toString()
void
writeExternal(PofWriter out)
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into the passed DataOutput object.
-
-
-
Constructor Detail
-
Result
public Result()
Constructs anResult
that has no value.
-
-
Method Detail
-
isValue
public boolean isValue()
Determines if the value is available (includingnull
).
-
isThrowable
public boolean isThrowable()
-
get
public T get() throws Throwable
Obtains the value throwable theResult
.- Returns:
- the value throwable the
Result
- Throws:
NoSuchElementException
- when theResult
value is notisPresent()
Throwable
- when theResult
was any otherThrowable
-
orElse
public T orElse(T value)
Obtains the value of theResult
if present, otherwise returns the specified value.- Parameters:
value
- the value to return if theisPresent()
fails- Returns:
- the
get()
whenisPresent()
, otherwise the specified value
-
readExternal
public void readExternal(DataInput in) throws IOException
Description copied from interface:ExternalizableLite
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- Parameters:
in
- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException
- if an I/O exception occursNotActiveException
- if the object is not in its initial state, and therefore cannot be deserialized into
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
Description copied from interface:ExternalizableLite
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
readExternal
public void readExternal(PofReader in) throws IOException
Description copied from interface:PortableObject
Restore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternal
in interfacePortableObject
- Parameters:
in
- the PofReader from which to read the object's state- Throws:
IOException
- if an I/O error occurs
-
writeExternal
public void writeExternal(PofWriter out) throws IOException
Description copied from interface:PortableObject
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternal
in interfacePortableObject
- Parameters:
out
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
-