Class TransactionalResource
java.lang.Object
dev.getelements.elements.rt.transact.TransactionalResource
- All Implemented Interfaces:
Resource
,AutoCloseable
-
Field Summary
Fields inherited from interface dev.getelements.elements.rt.Resource
DEFAULT_IO_BUFFER_SIZE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquire()
void
close()
Closes and destroys this Resource.void
Restores the entire state of thisResource
from the suppliedInputStream
.void
Restores the entire state of thisResource
from the suppliedInputStream
.Gets theAttributes
associated with thisResource
getId()
Returns the immutable and globally-unique ID of this resource.org.slf4j.Logger
Gets theLogger
used by thisResource
.getMethodDispatcher
(String name) Returns an instance ofMethodDispatcher
, which is used to invoke methods against thisResource
.getTasks()
boolean
boolean
Returns true if the resource is set to enable verbose mode.int
release()
void
Resumes the supplied task with theTaskId
and the list of results.void
resumeFromNetwork
(TaskId taskId, Object result) Resumes a suspended task, accepting the task id.void
resumeFromScheduler
(TaskId taskId, double elapsedTime) Resumes a suspended task, accepting the task id.void
resumeWithError
(TaskId taskId, Throwable throwable) Resumes a suspended task, accepting the task id.void
Dumps the entire contents of thisResource
to the suppliedOutputStream
where it can be reconstituted later using theResource.deserialize(InputStream)
method.void
Dumps the entire contents of thisResource
to the suppliedWritableByteChannel
where it can be reconstituted later using theResource.deserialize(InputStream)
method.void
setVerbose
(boolean verbose) Sets the verbose mode.void
unload()
Closes and destroys this Resource.
-
Constructor Details
-
TransactionalResource
-
-
Method Details
-
getId
Description copied from interface:Resource
Returns the immutable and globally-unique ID of this resource. Though a resource may exist at any path, this is the resource's ID. All resources are assigned a unique ID upon creation. The ID must remain unique for the life of the resource. -
getAttributes
Description copied from interface:Resource
Gets theAttributes
associated with thisResource
- Specified by:
getAttributes
in interfaceResource
- Returns:
- this instance's
Attributes
-
getMethodDispatcher
Description copied from interface:Resource
Returns an instance ofMethodDispatcher
, which is used to invoke methods against thisResource
. The reurnedMethodDispatcher
will defer actually invoking the method until the final call in the chainResultAcceptor.dispatch(Consumer, Consumer)
.- Specified by:
getMethodDispatcher
in interfaceResource
- Parameters:
name
- the name of the method- Returns:
- the
MethodDispatcher
, never null
-
resume
Description copied from interface:Resource
Resumes the supplied task with theTaskId
and the list of results. -
resumeFromNetwork
Description copied from interface:Resource
Resumes a suspended task, accepting the task id. The task will be resumed as soon as possible. This is used when the network resumes the call. This is assumed that the resume was successful. The response to the, invocation whatever it may be, was successful.- Specified by:
resumeFromNetwork
in interfaceResource
- Parameters:
taskId
- theTaskId
if the running taskresult
- the resulting object from the call
-
resumeWithError
Description copied from interface:Resource
Resumes a suspended task, accepting the task id. The task will be resumed as soon as possible. This is used when suspended coroutine encountered an error. The coroutine will be resume with the error that caused the underlying failure.- Specified by:
resumeWithError
in interfaceResource
- Parameters:
taskId
-throwable
-
-
resumeFromScheduler
Description copied from interface:Resource
Resumes a suspended task, accepting the task id. The task will be resumed as soon as possible. This method must succeed at the scheduling process, or else throw an exception. Note that this does not guarantee successful execution of the task, but rather successful scheduling.- Specified by:
resumeFromScheduler
in interfaceResource
- Parameters:
taskId
- theTaskId
if the running taskelapsedTime
- the amount of time elapsed since the task was last activated
-
serialize
Description copied from interface:Resource
Dumps the entire contents of thisResource
to the suppliedOutputStream
where it can be reconstituted later using theResource.deserialize(InputStream)
method.- Specified by:
serialize
in interfaceResource
- Parameters:
os
- theOutputStream
used to receive the serializedResource
- Throws:
IOException
- if something failed during serialization
-
deserialize
Description copied from interface:Resource
Restores the entire state of thisResource
from the suppliedInputStream
. This assumes theInputStream
was produced by a call toResource.serialize(OutputStream)
.- Specified by:
deserialize
in interfaceResource
- Parameters:
is
- theInputStream
from which to read the serialized resource- Throws:
IOException
- if something failed during deserialization
-
serialize
Description copied from interface:Resource
Dumps the entire contents of thisResource
to the suppliedWritableByteChannel
where it can be reconstituted later using theResource.deserialize(InputStream)
method.- Specified by:
serialize
in interfaceResource
- Parameters:
wbc
- theOutputStream
used to receive the serializedResource
- Throws:
IOException
- if something failed during serialization
-
deserialize
Description copied from interface:Resource
Restores the entire state of thisResource
from the suppliedInputStream
. This assumes theInputStream
was produced by a call toResource.serialize(OutputStream)
.- Specified by:
deserialize
in interfaceResource
- Parameters:
is
- theInputStream
from which to read the serialized resource- Throws:
IOException
- if something failed during deserialization
-
setVerbose
public void setVerbose(boolean verbose) Description copied from interface:Resource
Sets the verbose mode. This will enable enhanced logging for debug purposes.- Specified by:
setVerbose
in interfaceResource
- Parameters:
verbose
- true if verbose, false otherwise
-
isVerbose
public boolean isVerbose()Description copied from interface:Resource
Returns true if the resource is set to enable verbose mode. -
getTasks
Description copied from interface:Resource
-
getLogger
public org.slf4j.Logger getLogger()Description copied from interface:Resource
Gets theLogger
used by thisResource
. -
close
public void close()Description copied from interface:Resource
Closes and destroys this Resource. A resource, once destroyed, cannot be used again. Any tasks pending on the resource will be completed with aResourceDestroyedException
immediately. This is simlar toResource.close()
in that it frees up memory associated with thisResource
. However, its key difference is that it also propagates exceptions which indicate that it has reached a final state. In contrast toResource.unload()
which indicates that theResource
my be reconstituted later to continue performing work.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceResource
-
unload
public void unload()Description copied from interface:Resource
Closes and destroys this Resource. A resource, once destroyed, cannot be used again. Any tasks pending on ths resource will not be destroyed or unregistered. It is possible that later a newResource
would be made and the contents of this deserialized back into this one. -
acquire
-
release
public int release() -
getDelegate
-
isFullyReleased
public boolean isFullyReleased()
-