Class ForwardingStorageComponent

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public abstract class ForwardingStorageComponent
    extends StorageComponent
    We provide a forwarding variant of the storage component for use cases such as trace decoration, or throttling.

    Extending this is better than extending StorageComponent directly because it reduces risk of accidentally masking new methods. For example, if you extended storage component and later a new feature for cache control was added, that feature would be blocked until the wrapper was re-compiled. Such would be worse in most cases than not having decoration on new methods.

    Since:
    2.16
    • Constructor Detail

      • ForwardingStorageComponent

        protected ForwardingStorageComponent()
        Constructor for use by subclasses.
    • Method Detail

      • delegate

        protected abstract StorageComponent delegate()
        The delegate is a method as opposed to a field, to allow for flexibility. For example, this allows you to choose to make a final or lazy field, or no field at all.
      • check

        public CheckResult check()
        Description copied from class: Component
        Answers the question: Are operations on this component likely to succeed?

        Implementations should initialize the component if necessary. It should test a remote connection, or consult a trusted source to derive the result. They should use least resources possible to establish a meaningful result, and be safe to call many times, even concurrently.

        Overrides:
        check in class Component
        See Also:
        CheckResult.OK
      • isOverCapacity

        public boolean isOverCapacity​(java.lang.Throwable e)
        Description copied from class: StorageComponent
        A storage request failed and was dropped due to a limit, resource unavailability, or a timeout. Implementations of throttling can use this signal to differentiate between failures, for example to reduce traffic.

        Callers of this method will submit an exception raised by Call.execute() or on the error callback of Call.enqueue(Callback).

        By default, this returns true if the input is a RejectedExecutionException. When originating exceptions, use this type to indicate a load related failure.

        It is generally preferred to specialize this method to handle relevant exceptions for the particular storage rather than wrapping them in RejectedExecutionException at call sites. Extra wrapping can make errors harder to read, for example, by making it harder to "google" a solution for a well known error message for the storage client, instead thinking the error is in Zipkin code itself.

        See also

        While implementation is flexible, one known use is Netflix concurrency limits

        Overrides:
        isOverCapacity in class StorageComponent
      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: Component
        Closes any network resources created implicitly by the component.

        For example, if this created a connection, it would close it. If it was provided one, this would close any sessions, but leave the connection open.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Component
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object