Class/Object

com.github.sqlite4s

SQLiteJob

Related Docs: object SQLiteJob | package sqlite4s

Permalink

abstract class SQLiteJob[T] extends Future[T] with Logging

SQLiteJob is a unit of work accepted by SQLiteQueue. You can implement #job method and add the job to the queue with SQLiteQueue#execute method.

A job can optionally have a result. Type parameter <T> defines the type of the result, and the value of the result is returned by the job() method. If job finishes unsuccessfully or is cancelled, the result is always null. If you don't need the job to have a result, define it as SQLiteJob<Object> or SQLiteJob<Void> and return null from the job() method.

Job implements Future interface and can be used along with different types of future results.

Also, you can override methods #jobStarted, #jobFinished, #jobCancelled and #jobError to implement callbacks during the job's lifecycle.

SQLiteJob is a one-time object. Once the job is finished, it cannot be executed again.

Public methods of SQLiteJob are thread-safe unless specified otherwise. Protected methods are mostly called from the database thread and must be overridden carefully.

When programming a job, it's a good practice to keep transaction boundaries within single job. That is, if you BEGIN TRANSACTION in the job, make sure you COMMIT or ROLLBACK in the end. Otherwise, your transaction will remain unfinished, locks held, and you possible wouldn't know which job will execute next in the context of this unfinished transaction.

T

type of the result

See also

SQLiteQueue

Linear Supertypes
Logging, scribe.Logging, Future[T], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SQLiteJob
  2. Logging
  3. Logging
  4. Future
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SQLiteJob()

    Permalink

Abstract Value Members

  1. abstract def job(connection: SQLiteConnection): T

    Permalink

    Performs work on the SQLite database.

    Performs work on the SQLite database.

    This method is called only once from the database thread, when the job is selected and executed by the queue. After job is completed, it is removed from the queue and next job is executed.

    If job method throws any exception, it's recorded, logged, but otherwise it does not affect other jobs (except for side-effects of unfinished SQL work). This may be changed by overriding job's or queue's related methods.

    connection

    an open connection to the database, not null

    returns

    the result, or null

    Attributes
    protected
    Annotations
    @throws( ... )
    Exceptions thrown

    Throwable on any problem

    See also

    SQLiteQueue#execute

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def cancel(): Unit

    Permalink

    Cancels this job.

    Cancels this job. Convenience method to call cancel(true).

    See also

    #cancel(boolean)

  6. def cancel(mayInterruptIfRunning: Boolean): Boolean

    Permalink

    Attempts to cancel execution of this job.

    Attempts to cancel execution of this job. This attempt will fail if the job has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this job has not started when cancel is called, this job should never run. If the job has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

    When an active job is being cancelled with mayInterruptIfRunning parameter, SQLiteConnection#interrupt method is called to cancel a potentially long-running SQL. If there's no SQL running, it will have no effect. The running job may check #isCancelled method and finish prematurely. There are no other means to cancel a running job.

    If the job is still pending, then #jobCancelled and #jobFinished callbacks are called during the execution of this method.

    mayInterruptIfRunning

    true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete

    returns

    false if the task could not be cancelled, typically because it has already completed normally; true otherwise

    Definition Classes
    SQLiteJob → Future
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def complete(): T

    Permalink

    Wait if necessary for the job to complete and return the result.

    Wait if necessary for the job to complete and return the result.

    This is a convenience method for calling #get() without having to catch exceptions.

    returns

    the result of the job, or null if it has been cancelled or has erred

  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def get(timeout: Long, unit: TimeUnit): T

    Permalink

    Waits if necessary for at most the given time for the job to complete, and then retrieves its result, if available.

    Waits if necessary for at most the given time for the job to complete, and then retrieves its result, if available.

    timeout

    the maximum time to wait

    unit

    the time unit of the timeout argument

    returns

    the result

    Definition Classes
    SQLiteJob → Future
    Annotations
    @throws( ... ) @throws( ... ) @throws( ... )
    Exceptions thrown

    ExecutionException if the job threw an exception

    InterruptedException if the current thread was interrupted while waiting

    TimeoutException if the wait timed out

    java.util.concurrent.CancellationException if the job was cancelled

  13. def get(): T

    Permalink

    Waits if necessary for the job to complete, and then retrieves its result.

    Waits if necessary for the job to complete, and then retrieves its result.

    Calling this method, as well as convenience method #complete, is a way to block the current thread and wait for the result.

    returns

    the result

    Definition Classes
    SQLiteJob → Future
    Annotations
    @throws( ... ) @throws( ... )
    Exceptions thrown

    ExecutionException if the job threw an exception

    InterruptedException if the current thread was interrupted while waiting

    java.util.concurrent.CancellationException if the job was cancelled

  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def getError(): Throwable

    Permalink

    Returns the error thrown by the job.

    Returns the error thrown by the job.

    returns

    the error thrown by the { @link #job} method, or null.

  16. final def getQueue(): SQLiteQueue

    Permalink

    Returns the instance of the queue that is currently running the job.

    Returns the instance of the queue that is currently running the job. May return null.

    returns

    the queue that is currently running this job, if available.

    Attributes
    protected
  17. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  18. def isCancelled(): Boolean

    Permalink

    Returns true if this job was cancelled before it completed normally.

    Returns true if this job was cancelled before it completed normally.

    returns

    true if this job was cancelled before it completed

    Definition Classes
    SQLiteJob → Future
  19. def isDone(): Boolean

    Permalink

    Returns true if this job completed.

    Returns true if this job completed.

    Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

    returns

    true if this task completed

    Definition Classes
    SQLiteJob → Future
  20. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  21. def jobCancelled(): Unit

    Permalink

    This method is called after job has been cancelled, either due to call to the #cancel method, or because queue has stopped, or for any other reason.

    This method is called after job has been cancelled, either due to call to the #cancel method, or because queue has stopped, or for any other reason.

    Attributes
    protected
    Annotations
    @throws( ... )
    Exceptions thrown

    Throwable on any problem

  22. def jobError(error: Throwable): Unit

    Permalink

    This method is called after #job method has thrown an exception.

    This method is called after #job method has thrown an exception. The exception is passed as a parameter.

    error

    exception thrown by the job

    Attributes
    protected
    Annotations
    @throws( ... )
    Exceptions thrown

    Throwable on any problem, or the rethrown exception

  23. def jobFinished(result: T): Unit

    Permalink

    This method is called when the job is no longer in the queue.

    This method is called when the job is no longer in the queue. Overriding this method is the best way to asynchronously process the result of the job.

    This method is called always, regardless of the job execution result, and even if the job is cancelled before execution. More strictly, it is called once between the time SQLiteQueue#execute is called and the time when this job is no longer in the queue nor being executed.

    The result of the job is passed as a parameter.

    result

    the result of the job, or null if the job was cancelled or has thrown exception

    Attributes
    protected
    Annotations
    @throws( ... )
    Exceptions thrown

    Throwable on any problem

  24. def jobStarted(connection: SQLiteConnection): Unit

    Permalink

    This method is called when the job is about to be executed, before call to #job method.

    This method is called when the job is about to be executed, before call to #job method.

    This method may not be called at all if a job is cancelled before execution starts.

    connection

    an open connection to the database, not null

    Attributes
    protected
    Annotations
    @throws( ... )
    Exceptions thrown

    Throwable on any problem

  25. def logger: Logger

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  26. def loggerName: String

    Permalink
    Attributes
    protected
    Definition Classes
    Logging
  27. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  31. def toString(): String

    Permalink
    Definition Classes
    SQLiteJob → AnyRef → Any
  32. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Logging

Inherited from scribe.Logging

Inherited from Future[T]

Inherited from AnyRef

Inherited from Any

Ungrouped