Package

com.twitter

util

Permalink

package util

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. util
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractClosable extends Closable

    Permalink

    Abstract Closable class for Java compatibility.

  2. abstract class AbstractCloseAwaitably extends AbstractClosable with Awaitable[BoxedUnit]

    Permalink
  3. abstract class AbstractEvent[T] extends Event[T]

    Permalink

    Abstract Event class for Java compatibility.

  4. abstract class AbstractMonitor extends Monitor

    Permalink

    An API for creating Monitor instances in Java.

  5. abstract class AbstractVar[T] extends Var[T]

    Permalink

    Abstract Var class for Java compatibility.

  6. abstract class AbstractWitness[T] extends Witness[T]

    Permalink

    Abstract Witness class for Java compatibility.

  7. final class Activities extends AnyRef

    Permalink
  8. case class Activity[+T](run: Var[State[T]]) extends Product with Serializable

    Permalink

    An Activity is a handle to a concurrently running process, producing T-typed values.

    An Activity is a handle to a concurrently running process, producing T-typed values. An activity is in one of three states:

    • Pending: output is pending;
    • Ok: an output is available; and
    • Failed: the process failed with an exception.

    An activity may transition between any state at any time.

    (The observant reader will notice that this is really a monad transformer for an Op monad over Var where Op is like a Try with an additional pending state.)

  9. trait Awaitable[+T] extends AnyRef

    Permalink

    Wait for the result of some action.

    Wait for the result of some action. Awaitable is not used directly, but through the Await object.

  10. class Batcher[In, Out] extends (In) ⇒ Future[Out]

    Permalink

    Provides an interface for working with a batched com.twitter.util.Future

  11. class BoundedStack[A] extends Seq[A]

    Permalink

    A "stack" with a bounded size.

    A "stack" with a bounded size. If you push a new element on the top when the stack is full, the oldest element gets dropped off the bottom.

  12. trait Cancellable extends AnyRef

    Permalink

    Defines a trait that makes the underlying object *cancellable*.

    Defines a trait that makes the underlying object *cancellable*. Cancellable objects may be linked to each other (one way) in order to propagate cancellation.

    Note that the underlying object may or may not _respond_ to the cancellation request. That is, calling 'cancel()' does not guarantee the cancellation of the computation; rather it is a hint that the provider of the computation may choose to ignore.

  13. class CancellableSink extends Cancellable

    Permalink
  14. trait Closable extends AnyRef

    Permalink

    Closable is a mixin trait to describe a closable resource.

    Closable is a mixin trait to describe a closable resource.

    Note: There is a Java-friendly API for this trait: com.twitter.util.AbstractClosable.

  15. final class Closables extends AnyRef

    Permalink
  16. trait CloseAwaitably extends CloseAwaitably0[Unit]

    Permalink

    A mixin to make an com.twitter.util.Awaitable out of a com.twitter.util.Closable.

    A mixin to make an com.twitter.util.Awaitable out of a com.twitter.util.Closable.

    Use closeAwaitably in the definition of close:

    class MyClosable extends Closable with CloseAwaitably {
      def close(deadline: Time) = closeAwaitably {
        // close the resource
      }
    }

    Note: There is a Java-friendly API for this trait: com.twitter.util.AbstractCloseAwaitably.

  17. trait Codec[T, S] extends Encoder[T, S] with Decoder[T, S]

    Permalink

    A base trait for all Codecs that translate a type T into a serialized form S

  18. abstract class Command[-T1] extends (T1) ⇒ Unit

    Permalink
  19. class ConstFuture[A] extends Future[A]

    Permalink

    A Future that is already completed.

    A Future that is already completed.

    These are cheap in construction compared to Promises.

  20. class CountDownLatch extends AnyRef

    Permalink
  21. class Credentials extends AnyRef

    Permalink

    Java interface to Credentials.

  22. trait Decoder[T, S] extends AnyRef

    Permalink

    A base trait for decoders for type T from a serialized form S

  23. trait DecoderCompanion extends AnyRef

    Permalink
  24. trait Diff[CC[_], T] extends AnyRef

    Permalink

    A Diff stores the necessary instructions required to bring two version of a data structure into agreement.

  25. trait Diffable[CC[_]] extends AnyRef

    Permalink

    A type class that tells how to compute a Diff between two versions of a collection CC[T].

  26. trait Disposable[+T] extends AnyRef

    Permalink

    com.twitter.util.Disposable represents a live resource that must be disposed after use.

    Resource Management

    com.twitter.util.Disposable represents a live resource that must be disposed after use. com.twitter.util.Managed is a factory for creating and composing such resources. Managed resources are composed together so their lifetimes are synchronized.

    The following example shows how to build and use composite managed resources:

    // Create managed Tracer
    def mkManagedTracer() = new Managed[Tracer] {
      def make() = new Disposable[Tracer] {
        val underlying = new Tracer()
        def get = underlying
        def dispose(deadline: Time) = underlying.close() // assumes Tracer uses relese() to manage lifetime
      }
    }
    
    // Create managed Server using Tracer as dependency
    def mkManagedServer(t: Tracer) = new Managed[Server] {
      def make() = new Disposable[Server] {
        val underlying = new Server(t) // Server requires tracer to be created
        def get = underlying
        def dispose(deadline: Time) = underlying.close() // assumes Server uses close() to manage lifetime
      }
    }
    
    // Create composite resource
    val compRes: Managed[Server] = for {
      a <- mkManagedTracer()
      b <- mkManagedServer(a)
    } yield b
    
    // Use composite resource in safe fashion. It's guaranteed that both resources
    // will be properly closed/released when done using them.
    compRes foreach { b =>
      // use b (which is type Server in this case)
    } // dispose called on both resources

    Disposable/Managed Semantics

    com.twitter.util.Disposable: get can be called multiple times and should return same instance; dispose can be called only once and should release resource that get is returning; calling get after dispose is undefined.

    com.twitter.util.Managed: multiple calls to make could return a) new instance or b) ref counted instance of the underlying resource or c) same instance when resource doesn't need to be actually disposed, etc.

    Disposable is a container for a resource that must be explicitly disposed when no longer needed. After this, the resource is no longer available.

  27. class DoubleTrouble extends Exception

    Permalink
  28. sealed class Duration extends TimeLike[Duration] with Serializable

    Permalink

    A Duration represents the span between two points in time.

    A Duration represents the span between two points in time. It represents this with a signed long, and thus the largest representable duration is:

    106751.days+23.hours+47.minutes+16.seconds +854.milliseconds+775.microseconds+807.nanoseconds

    Durations may be constructed via its companion object, Duration.fromNanoseconds, Duration.fromSeconds, etc. or by using the time conversions:

    import com.twitter.conversions.time._
    
    3.days+4.nanoseconds

    In addition to the timespans in the range of Long.MinValue to Long.MaxValue nanoseconds, durations have two distinguished values: Duration.Top and Duration.Bottom. These have special semantics: Top is greater than every other duration, save for itself; Bottom is smaller than any duration except for itself — they act like positive and negative infinity, and their arithmetic follows. This is useful for representing durations that are truly infinite; for example the absence of a timeout.

  29. trait Encoder[T, S] extends (T) ⇒ S

    Permalink

    A base trait for encoders of type T into a serialized form S

  30. trait EncoderCompanion extends AnyRef

    Permalink
  31. trait Event[+T] extends AnyRef

    Permalink

    Events are instantaneous values, defined only at particular instants in time (cf.

    Events are instantaneous values, defined only at particular instants in time (cf. Vars, which are defined at all times). It is possible to view Events as the discrete counterpart to Var's continuous nature.

    Events are observed by registering Witnesses to which the Event's values are notified.

    Note: There is a Java-friendly API for this trait: com.twitter.util.AbstractEvent.

  32. final class Events extends AnyRef

    Permalink
  33. abstract class ExceptionalFunction[-T1, +R] extends Function[T1, R]

    Permalink
  34. abstract class ExceptionalFunction0[+R] extends Function0[R]

    Permalink
  35. class ExecutorServiceFuturePool extends FuturePool

    Permalink

    A FuturePool implementation backed by an java.util.concurrent.ExecutorService.

    A FuturePool implementation backed by an java.util.concurrent.ExecutorService.

    If a piece of work has started, it cannot be cancelled and will not propagate cancellation unless interruptible is true. If you want to propagate cancellation, use an InterruptibleExecutorServiceFuturePool.

  36. trait Extractable[T] extends AnyRef

    Permalink
  37. abstract class FactoryPool[A] extends Pool[A]

    Permalink
  38. abstract class Function[-T1, +R] extends PartialFunction[T1, R]

    Permalink

    This class is for Java friendliness.

    This class is for Java friendliness. Any Scala method that takes Function1[A, B] can now take a Function[A, B]. Because Function1 is a trait, it is very difficult to instantiate directly in Java.

  39. abstract class Function0[+R] extends () ⇒ R

    Permalink
  40. abstract class Function2[-T1, -T2, +R] extends (T1, T2) ⇒ R

    Permalink
  41. abstract class Function3[-T1, -T2, -T3, +R] extends (T1, T2, T3) ⇒ R

    Permalink
  42. abstract class Future[+A] extends Awaitable[A]

    Permalink

    Represents an asynchronous value.

    Represents an asynchronous value.

    See the user guide on concurrent programming with Futures to better understand how they work and can be used.

    A Future[T] can be in one of three states:

    • Pending, the computation has not yet completed
    • Satisfied successfully, with a result of type T (a Return)
    • Satisfied by a failure, with a Throwable result (a Throw)

    This definition of Future does not assume any concrete implementation; in particular, it does not couple the user to a specific executor or event loop.

    See also

    Futures for Java-friendly APIs.

    The user guide on concurrent programming with Futures.

  43. class FutureCancelledException extends Exception

    Permalink
  44. trait FutureEventListener[T] extends AnyRef

    Permalink

    A Java friendly API for handling side-effects for a Future.

    A Java friendly API for handling side-effects for a Future.

    If you want a Java API to sequence the work you can use a FutureTransformer.

    See also

    FutureTransformer for a Java API for transforming the results of Futures.

    Future.addEventListener for using it with a Future.

    Future.respond which is the equivalent Scala API for further details.

  45. class FutureNonLocalReturnControl extends Exception

    Permalink
  46. trait FuturePool extends AnyRef

    Permalink

    A FuturePool executes tasks asynchronously, typically using a pool of worker threads.

  47. class FuturePools extends AnyRef

    Permalink
  48. class FutureTask[A] extends Promise[A] with Runnable

    Permalink
  49. abstract class FutureTransformer[-A, +B] extends AnyRef

    Permalink

    An alternative interface for performing Future transformations; that is, converting a Future[A] to a Future[B].

    An alternative interface for performing Future transformations; that is, converting a Future[A] to a Future[B]. This interface is designed to be friendly to Java users since it does not require creating many small Function objects. It is used in conjunction with transformedBy.

    You must override one of {map, flatMap}. If you override both map and flatMap, flatMap takes precedence. If you fail to override one of {map, flatMap}, an AbstractMethodError will be thrown at Runtime.

    Note: to end a result with a failure, we encourage you to use either flatMap or rescue and return a failed Future, instead of throwing an exception. A failed future can be used by returning Future.exception(throwable) instead of throwing an exception.

    See also

    FutureEventListener for a Java API for side-effects.

    Future.transformedBy for using it with a Future.

    Future.transform which is the equivalent Scala API for further details.

  50. class InterruptibleExecutorServiceFuturePool extends ExecutorServiceFuturePool

    Permalink

    A FuturePool backed by a java.util.concurrent.ExecutorService that supports cancellation.

  51. trait JavaSingleton extends AnyRef

    Permalink

    A mixin to allow scala objects to be used from java.

  52. class JavaTimer extends Timer

    Permalink

    A Timer that is implemented via a java.util.Timer.

    A Timer that is implemented via a java.util.Timer.

    This timer has millisecond granularity.

    If your code has a reasonably high throughput of task scheduling and can trade off some precision of when tasks run, Finagle has a higher throughput hashed-wheel implementation.

    Note

    Due to the implementation using a single Thread, be wary of scheduling tasks that take a long time to execute (e.g. blocking IO) as this blocks other tasks from running at their scheduled time.

  53. class LastWriteWinsQueue[A] extends Queue[A]

    Permalink

    An implementation of java.util.Queue that has LIFO order and a maximum capacity of 1 When the Queue is full, a push replaces the item.

  54. final class Local[T] extends AnyRef

    Permalink

    A Local is a ThreadLocal whose scope is flexible.

    A Local is a ThreadLocal whose scope is flexible. The state of all Locals may be saved or restored onto the current thread by the user. This is useful for threading Locals through execution contexts.

    Promises pass locals through control dependencies, not through data dependencies. This means that Locals have exactly the same semantics as ThreadLocals, if you think of continue (the asynchronous sequence operator) as semicolon (the synchronous sequence operator).

    Because it's not meaningful to inherit control from two places, Locals don't have to worry about having to merge two Contexts.

    Note: the implementation is optimized for situations in which save and restore optimizations are dominant.

  55. trait Managed[+T] extends AnyRef

    Permalink

    Managed[T] is a resource of type T which lifetime is explicitly managed.

    Managed[T] is a resource of type T which lifetime is explicitly managed. It is created with make(). Composite resources, which lifetimes are managed together, are created by the use of flatMap, ensuring proper construction and teardown of the comprised resources.

  56. class MockTimer extends Timer

    Permalink

    Exceedingly useful for writing well-behaved tests that need control over a Timer.

    Exceedingly useful for writing well-behaved tests that need control over a Timer. This is due to it playing well with the Time manipulation methods such as Time.withTimeAt, Time.withCurrentTimeFrozen, and so on.

    See also

    See the cookbook for examples.

  57. trait Monitor extends AnyRef

    Permalink

    A Monitor is a composable exception handler.

    A Monitor is a composable exception handler. It is independent of position, divorced from the notion of a call stack. Monitors do not recover values from a failed computations: It handles only true exceptions that may require cleanup.

    See also

    AbstractMonitor for an API friendly to creating instances from Java.

  58. case class MonitorException(handlingExc: Throwable, monitorExc: Throwable) extends Exception with Product with Serializable

    Permalink

    Wraps an exception that happens when handling another exception in a monitor.

  59. class NoFuture extends Future[Nothing]

    Permalink

    A Future which can never be satisfied and is thus always in the pending state.

    A Future which can never be satisfied and is thus always in the pending state.

    See also

    Future.never for an instance of it.

  60. class NullTimer extends Timer

    Permalink

    A NullTimer is not a timer at all: it invokes all tasks immediately and inline.

  61. trait Pool[A] extends AnyRef

    Permalink
  62. class Promise[A] extends Future[A] with Responder[A] with Updatable[Try[A]]

    Permalink

    A writeable com.twitter.util.Future that supports merging.

    A writeable com.twitter.util.Future that supports merging. Callbacks (responders) of Promises are scheduled with com.twitter.concurrent.Scheduler.

    Implementation details

    A Promise is in one of six states: Waiting, Interruptible, Interrupted, Transforming, Done and Linked where Interruptible, Interrupted, and Transforming are variants of Waiting to deal with future interrupts. Promises are concurrency-safe, using lock-free operations throughout. Callback dispatch is scheduled with com.twitter.concurrent.Scheduler.

    Waiters are stored as a com.twitter.util.Promise.K. Ks (mnemonic: continuation) specifies a depth. This is used to implement Promise chaining: a callback with depth d is invoked only after all callbacks with depth < d have already been invoked.

    Promise.become merges two promises: they are declared equivalent. become merges the states of the two promises, and links one to the other. Thus promises support the analog to tail-call elimination: no space leak is incurred from flatMap in the tail position since intermediate promises are merged into the root promise.

    A number of optimizations are employed to conserve space: we pay particular heed to the JVM's object representation, in particular for OpenJDK (HotSpot) version 7 running on 64-bit architectures with compressed OOPS. See comments on com.twitter.util.Promise.State for details.

  63. abstract class ProxyTimer extends Timer

    Permalink

    A Timer that proxies methods to self.

  64. class ReadWriteVar[T] extends UpdatableVar[T]

    Permalink

    Java adaptation of Var[T] with Updatable[T] with Extractable[T].

  65. trait ReferenceCountedTimer extends Timer

    Permalink
  66. class ReferenceCountingTimer extends ProxyTimer with ReferenceCountedTimer

    Permalink
  67. final case class Return[+R](r: R) extends Try[R] with Product with Serializable

    Permalink
  68. class RichU64ByteArray extends AnyRef

    Permalink
  69. class RichU64Long extends AnyRef

    Permalink
  70. class RichU64String extends AnyRef

    Permalink

    RichU64String parses string as a 64-bit unsigned hexadecimal long, outputting a signed Long or a byte array.

    RichU64String parses string as a 64-bit unsigned hexadecimal long, outputting a signed Long or a byte array. Valid input is 1-16 hexadecimal digits (0-9, a-z, A-Z).

    Exceptions thrown

    NumberFormatException if string is not a non-negative hexadecimal string

  71. class ScheduledThreadPoolTimer extends Timer

    Permalink
  72. trait SignalHandler extends AnyRef

    Permalink
  73. class SimplePool[A] extends Pool[A]

    Permalink
  74. abstract class SlowProbeProxyTimer extends ProxyTimer

    Permalink

    An abstract ProxyTimer that provides callback methods which are called when a task takes longer than the specified maximum runtime or if a task is observed to be taking longer than the specified maximum runtime.

    An abstract ProxyTimer that provides callback methods which are called when a task takes longer than the specified maximum runtime or if a task is observed to be taking longer than the specified maximum runtime.

    Note

    This makes assumptions that the underlying Timer will execute tasks sequentially in order to catch slow running tasks during execution. If the underlying Timer executes tasks in parallel the callback slowTaskExecuting will become unreliable. However, the slowTaskCompleted callback will remain reliable but must be a thread-safe implementation.

    ,

    Observation of slow task execution is performed when scheduling more work to avoid the overhead of another thread or timer checking on tasks. This results in lower overhead but means that slow running tasks may not be observed while executing. However, they will trigger a callback to the slowTaskCompleted regardless of whether additional work is scheduled.

  75. trait StateMachine extends AnyRef

    Permalink
  76. trait Stopwatch extends AnyRef

    Permalink

    A stopwatch may be used to measure elapsed time.

  77. class StorageUnit extends Ordered[StorageUnit]

    Permalink

    Representation of storage units.

    Representation of storage units.

    Use either StorageUnit.fromX or implicit conversions from Long and Int to construct instances.

    import com.twitter.conversions.storage._
    import com.twitter.util.StorageUnit
    
    val size: StorageUnit = 10.kilobytes
    Note

    Operations can cause overflows of the Long used to represent the number of bytes.

    ,

    While all the methods in this abstraction are prefixed according to the International System of Units (kilo-, mega-, etc), they actually operate on the 1024 scale (not 1000).

  78. class SunSignalHandler extends SignalHandler

    Permalink
  79. trait TempFolder extends AnyRef

    Permalink

    Test mixin that creates a temporary thread-local folder for a block of code to execute in.

    Test mixin that creates a temporary thread-local folder for a block of code to execute in. The folder is recursively deleted after the test.

    Note, the com.twitter.util.io package would be a better home for this trait.

    Note that multiple uses of TempFolder cannot be nested, because the temporary directory is effectively a thread-local global.

  80. class ThreadStoppingTimer extends ProxyTimer

    Permalink
  81. final case class Throw[+R](e: Throwable) extends Try[R] with Product with Serializable

    Permalink
  82. sealed class Time extends TimeLike[Time] with Serializable

    Permalink

    An absolute point in time, represented as the number of nanoseconds since the Unix epoch.

    An absolute point in time, represented as the number of nanoseconds since the Unix epoch.

    See also

    TimeFormat for converting to and from String representations.

    Stopwatch for measuring elapsed time.

    Duration for intervals between two points in time.

  83. trait TimeControl extends AnyRef

    Permalink
  84. class TimeFormat extends AnyRef

    Permalink

    A thread-safe wrapper around a SimpleDateFormat object.

    A thread-safe wrapper around a SimpleDateFormat object.

    The default timezone is UTC.

  85. trait TimeLike[This <: TimeLike[This]] extends Ordered[This]

    Permalink

    A common trait for time-like values.

    A common trait for time-like values. It requires a companion TimeLikeOps module. TimeLikes are finite, but they must always have two sentinels: Top and Bottom. These act like positive and negative infinities: Arithmetic involving them preserves their values, and so on.

    TimeLikes are Long-valued nanoseconds, but have different interpretations: Durations measure the number of nanoseconds between two points in time, while Time measure the number of nanoseconds since the Unix epoch (1 January 1970 00:00:00 UTC).

    TimeLike behave like boxed java Double values with respect to infinity and undefined values. In particular, this means that a TimeLike's Undefined value is comparable to other values. In turn this means it can be used as keys in maps, etc.

    Overflows are also handled like doubles.

  86. trait TimeLikeOps[This <: TimeLike[This]] extends AnyRef

    Permalink

  87. class TimeoutException extends java.util.concurrent.TimeoutException

    Permalink
  88. trait Timer extends AnyRef

    Permalink

    Timers are used to schedule tasks in the future.

    Timers are used to schedule tasks in the future. They support both one-shot and recurring tasks.

    Timers propagate Local state, including the Monitor, from when the task is scheduled to when it is run.

    Note

    Scheduling tasks with Timers should rarely be done directly; for example, when programming with Futures, prefer using Future.sleep.

    See also

    MockTimer for use in tests that require determinism.

  89. trait TimerTask extends Closable

    Permalink

    TimerTasks represent pending tasks scheduled by a Timer.

  90. abstract class TokenBucket extends AnyRef

    Permalink

    A token bucket is used to control the relative rates of two processes: one fills the bucket, another empties it.

  91. sealed abstract class Try[+R] extends AnyRef

    Permalink

    This class represents a computation that can succeed or fail.

    This class represents a computation that can succeed or fail. It has two concrete implementations, Return (for success) and Throw (for failure)

  92. trait Updatable[-T] extends AnyRef

    Permalink

    Denotes an updatable container.

  93. trait Var[+T] extends AnyRef

    Permalink

    Trait Var represents a variable.

    Trait Var represents a variable. It is a reference cell which is composable: dependent Vars (derived through flatMap) are recomputed automatically when independent variables change -- they implement a form of self-adjusting computation.

    Vars are observed, notifying users whenever the variable changes.

    Note

    There are no well-defined error semantics for Var. Vars are computed lazily, and the updating thread will receive any exceptions thrown while computing derived Vars. Note: There is a Java-friendly API for this trait: com.twitter.util.AbstractVar.

    ,

    Vars do not always perform the minimum amount of re-computation.

  94. final class Vars extends AnyRef

    Permalink
  95. trait Witness[-N] extends AnyRef

    Permalink

    A witness is the recipient of Event.

    A witness is the recipient of Event.

    Note: There is a Java-friendly API for this trait: com.twitter.util.AbstractWitness.

  96. class WitnessedEvent[T] extends Event[T] with Witness[T]

    Permalink

    A Java analog of Event[A]().

  97. final class Witnesses extends AnyRef

    Permalink
  98. trait Config[T] extends () ⇒ T

    Permalink

    A config object contains vars for configuring an object of type T, and an apply() method which turns this config into an object of type T.

    A config object contains vars for configuring an object of type T, and an apply() method which turns this config into an object of type T.

    The trait also contains a few useful implicits.

    You can define fields that are required but that don't have a default value with: class BotConfig extends Config[Bot] { var botName = required[String] var botPort = required[Int] .... }

    Optional fields can be defined with: var something = optional[Duration]

    Fields that are dependent on other fields and have a default value computed from an expression should be marked as computed:

    var level = required[Int] var nextLevel = computed { level + 1 }

    Annotations
    @deprecated
    Deprecated

    (Since version ) use a Plain Old Scala Object

Value Members

  1. object Activity extends Serializable

    Permalink

    Note: There is a Java-friendly API for this object: com.twitter.util.Activities.

  2. object Await

    Permalink

    Synchronously await the result of some action by blocking the current thread.

    Synchronously await the result of some action by blocking the current thread.

    The two main uses of Await are (a) you have synchronous code that needs to wait on some action performed by asynchronous code, or (b) you have synchronous code that needs to wait on some action performed on a thread pool or otherwise a different thread.

    A common type of Awaitable is the com.twitter.util.Future.

    In the context of an event loop (such as when you are on a Finagle thread), never synchronously wait for completion - favoring asynchronous methods such as combinators or callbacks registered on a Future.

  3. object Awaitable

    Permalink
  4. object Base64Long

    Permalink

    Efficient conversion between Longs and base 64 encoded strings.

    Efficient conversion between Longs and base 64 encoded strings.

    This is intended for use in e.g. cache keys.

  5. object BinaryCodec

    Permalink
  6. object Cancellable

    Permalink
  7. object Closable

    Permalink

    Note: There is a Java-friendly API for this object: com.twitter.util.Closables.

  8. object Codec extends EncoderCompanion with DecoderCompanion

    Permalink
  9. object Credentials

    Permalink

    Simple helper to read authentication credentials from a text file.

    Simple helper to read authentication credentials from a text file.

    The file's format is assumed to be trivialized yaml, containing lines of the form key: value. Keys can be any word character or '-' and values can be any character except new lines.

  10. object Decoder extends DecoderCompanion

    Permalink
  11. object Diffable

    Permalink

    Diffable defines common type class instances for Diffable.

  12. object Disposable

    Permalink
  13. object Duration extends TimeLikeOps[Duration] with Serializable

    Permalink
  14. object Encoder extends EncoderCompanion

    Permalink
  15. object Event

    Permalink

    Note: There is a Java-friendly API for this object: com.twitter.util.Events.

  16. object Function

    Permalink
  17. object Future

    Permalink

    See also

    The user guide on concurrent programming with Futures.

    Futures for Java-friendly APIs.

  18. object FuturePool

    Permalink

    Note: There is a Java-friendly API for this object: com.twitter.util.FuturePools.

  19. object FutureTask

    Permalink
  20. object Futures

    Permalink

    Twitter Future utility methods for ease of use from java

  21. object HandleSignal

    Permalink
  22. object Local

    Permalink
  23. object Managed

    Permalink
  24. object Memoize

    Permalink
  25. object Monitor extends Monitor

    Permalink

    Defines the (Future)-Local monitor as well as some monitor utilities.

    Defines the (Future)-Local monitor as well as some monitor utilities.

    Java users should use the Monitors class.

  26. object NetUtil

    Permalink
  27. object NilStopwatch extends Stopwatch

    Permalink

    A trivial implementation of Stopwatch for use as a null object.

    A trivial implementation of Stopwatch for use as a null object.

    All calls to Stopwatch.start() return an Stopwatch.Elapsed instance that always returns Duration.Bottom for its elapsed time.

    See also

    NilStopwatch.get for accessing this instance from Java.

  28. object NullMonitor extends Monitor

    Permalink

    A monitor that always fails to handle an exception.

    A monitor that always fails to handle an exception. Combining this with any other Monitor will simply return the other Monitor effectively removing NullMonitor from the chain.

  29. object NullTimerTask extends TimerTask

    Permalink
  30. object Promise

    Permalink
  31. object RandomSocket

    Permalink

    A generator of random local java.net.InetSocketAddress objects with ephemeral ports.

  32. object Return extends Serializable

    Permalink
  33. object RootMonitor extends Monitor

    Permalink
  34. object SignalHandlerFactory

    Permalink
  35. object StateMachine

    Permalink
  36. object Stopwatch extends Stopwatch

    Permalink

    The system Stopwatch measures elapsed time using System.nanoTime.

    The system Stopwatch measures elapsed time using System.nanoTime.

    Note that it works well with unit tests by respecting time manipulation on Time.

    See also

    Stopwatches for Java APIs.

  37. object Stopwatches

    Permalink

    Java APIs for Stopwatch.

  38. object StorageUnit

    Permalink
  39. val StorageUnitConversions: storage.type

    Permalink
  40. object SunSignalHandler

    Permalink
  41. object Throw extends Serializable

    Permalink
  42. object Throwables

    Permalink
  43. object Time extends TimeLikeOps[Time] with Serializable

    Permalink

    By using Time.now in your program instead of System.currentTimeMillis unit tests are able to adjust the current time to verify timeouts and other time-dependent behavior, without calling sleep, and providing deterministic tests.

    By using Time.now in your program instead of System.currentTimeMillis unit tests are able to adjust the current time to verify timeouts and other time-dependent behavior, without calling sleep, and providing deterministic tests.

    The current time can be manipulated via Time.withTimeAt, Time.withCurrentTimeFrozen, Time.withTimeFunction and Time.sleep.

    While now is not a "global" it is however properly propagated through to other code via the standard usage of Locals throughout util. Specifically, code using Futures, FuturePools, and MockTimers will have their code see the manipulated values.

    val time = Time.fromMilliseconds(123456L)
    Time.withTimeAt(time) { timeControl =>
      assert(Time.now == time)
    
      // you can control time via the `TimeControl` instance.
      timeControl.advance(2.seconds)
      FuturePool.unboundedPool {
        assert(Time.now == time + 2.seconds)
      }
    }
    See also

    TimeFormat for converting to and from String representations.

    Stopwatch for measuring elapsed time.

    Duration for intervals between two points in time.

  44. val TimeConversions: time.type

    Permalink
  45. object Timer

    Permalink
  46. object TokenBucket

    Permalink
  47. object Try

    Permalink

    The Try type represents a computation that may either result in an exception or return a success value.

    The Try type represents a computation that may either result in an exception or return a success value. It is analogous to the Either type but encodes common idioms for handling exceptional cases (such as rescue/ensure which is analogous to try/finally).

  48. object TwitterDateFormat

    Permalink

    A java.text.SimpleDateFormat that avoids confusion between YYYY and yyyy.

    A java.text.SimpleDateFormat that avoids confusion between YYYY and yyyy. One should never use YYYY (week year) unless the format also includes the week of year.

  49. object U64

    Permalink
  50. object Unsafe

    Permalink
  51. object Updatable

    Permalink
  52. object Var

    Permalink

    Note: There is a Java-friendly API for this object: com.twitter.util.Vars.

  53. object Witness

    Permalink

    Note: There is Java-friendly API for this object: com.twitter.util.Witnesses.

  54. package javainterop

    Permalink

Deprecated Value Members

  1. object Config

    Permalink

    You can import Config._ if you want the auto-conversions in a class that does not inherit from trait Config.

    You can import Config._ if you want the auto-conversions in a class that does not inherit from trait Config.

    Annotations
    @deprecated
    Deprecated

    (Since version ) use a Plain Old Scala Object

  2. object NonFatal

    Permalink

    A classifier of non-fatal Exceptions.

    A classifier of non-fatal Exceptions.

    Developers should prefer using scala.util.control.NonFatal from the Scala standard library.

    Annotations
    @deprecated
    Deprecated

    (Since version 2016-11-21) Use scala.util.control.NonFatal instead

    Note

    Scala added NonFatal to the standard library in Scala 2.10, while Twitter's util needed to provide this for users who were still on Scala 2.9 at the time.

    See also

    Scala's NonFatal for usage notes.

Inherited from AnyRef

Inherited from Any

Ungrouped