Class TransactionalResource

java.lang.Object
dev.getelements.elements.rt.transact.TransactionalResource
All Implemented Interfaces:
Resource, AutoCloseable

public final class TransactionalResource extends Object implements Resource
  • Constructor Details

    • TransactionalResource

      public TransactionalResource(Resource delegate)
  • Method Details

    • getId

      public ResourceId 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.
      Specified by:
      getId in interface Resource
      Returns:
      the resource's ID
    • getAttributes

      public MutableAttributes getAttributes()
      Description copied from interface: Resource
      Gets the Attributes associated with this Resource
      Specified by:
      getAttributes in interface Resource
      Returns:
      this instance's Attributes
    • getMethodDispatcher

      public MethodDispatcher getMethodDispatcher(String name)
      Description copied from interface: Resource
      Returns an instance of MethodDispatcher, which is used to invoke methods against this Resource. The reurned MethodDispatcher will defer actually invoking the method until the final call in the chain ResultAcceptor.dispatch(Consumer, Consumer).
      Specified by:
      getMethodDispatcher in interface Resource
      Parameters:
      name - the name of the method
      Returns:
      the MethodDispatcher, never null
    • resume

      public void resume(TaskId taskId, Object... results)
      Description copied from interface: Resource
      Resumes the supplied task with the TaskId and the list of results.
      Specified by:
      resume in interface Resource
      Parameters:
      taskId - the TaskId of the associated task
      results - zero or more results supplied to the resumed task
    • resumeFromNetwork

      public void resumeFromNetwork(TaskId taskId, Object result)
      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 interface Resource
      Parameters:
      taskId - the TaskId if the running task
      result - the resulting object from the call
    • resumeWithError

      public void resumeWithError(TaskId taskId, Throwable throwable)
      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 interface Resource
      Parameters:
      taskId -
      throwable -
    • resumeFromScheduler

      public void resumeFromScheduler(TaskId taskId, double elapsedTime)
      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 interface Resource
      Parameters:
      taskId - the TaskId if the running task
      elapsedTime - the amount of time elapsed since the task was last activated
    • serialize

      public void serialize(OutputStream os) throws IOException
      Description copied from interface: Resource
      Dumps the entire contents of this Resource to the supplied OutputStream where it can be reconstituted later using the Resource.deserialize(InputStream) method.
      Specified by:
      serialize in interface Resource
      Parameters:
      os - the OutputStream used to receive the serialized Resource
      Throws:
      IOException - if something failed during serialization
    • deserialize

      public void deserialize(InputStream is) throws IOException
      Description copied from interface: Resource
      Restores the entire state of this Resource from the supplied InputStream. This assumes the InputStream was produced by a call to Resource.serialize(OutputStream).
      Specified by:
      deserialize in interface Resource
      Parameters:
      is - the InputStream from which to read the serialized resource
      Throws:
      IOException - if something failed during deserialization
    • serialize

      public void serialize(WritableByteChannel wbc) throws IOException
      Description copied from interface: Resource
      Dumps the entire contents of this Resource to the supplied WritableByteChannel where it can be reconstituted later using the Resource.deserialize(InputStream) method.
      Specified by:
      serialize in interface Resource
      Parameters:
      wbc - the OutputStream used to receive the serialized Resource
      Throws:
      IOException - if something failed during serialization
    • deserialize

      public void deserialize(ReadableByteChannel is) throws IOException
      Description copied from interface: Resource
      Restores the entire state of this Resource from the supplied InputStream. This assumes the InputStream was produced by a call to Resource.serialize(OutputStream).
      Specified by:
      deserialize in interface Resource
      Parameters:
      is - the InputStream 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 interface Resource
      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.
      Specified by:
      isVerbose in interface Resource
      Returns:
      true if verbose mode is enabled.
    • getTasks

      public Set<TaskId> getTasks()
      Description copied from interface: Resource
      Gets a Set<TaskId> representing active tasks at the current state.
      Specified by:
      getTasks in interface Resource
      Returns:
      the running tasks as a Set
    • getLogger

      public org.slf4j.Logger getLogger()
      Description copied from interface: Resource
      Gets the Logger used by this Resource.
      Specified by:
      getLogger in interface Resource
      Returns:
      the logger
    • 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 a ResourceDestroyedException immediately. This is simlar to Resource.close() in that it frees up memory associated with this Resource. However, its key difference is that it also propagates exceptions which indicate that it has reached a final state. In contrast to Resource.unload() which indicates that the Resource my be reconstituted later to continue performing work.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Resource
    • 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 new Resource would be made and the contents of this deserialized back into this one.
      Specified by:
      unload in interface Resource
    • acquire

      public TransactionalResource acquire()
    • release

      public int release()
    • getDelegate

      public Resource getDelegate()
    • isFullyReleased

      public boolean isFullyReleased()