Top Description Inners Methods
org.eclipse.jetty.io

public Interface Retainable

Known Direct Subinterfaces
org.eclipse.jetty.io.RetainableByteBuffer, org.eclipse.jetty.io.Content.Chunk
Known Direct Implementers
org.eclipse.jetty.io.Retainable.Wrapper, org.eclipse.jetty.io.Retainable.ReferenceCounter
Imports
java.util.Objects, java.util.concurrent.atomic.AtomicInteger

A reference counted resource, for example one that is borrowed from a pool, that may be retained an additional number of times, and released a correspondent number of times, over its lifecycle.

The resource is typically implicitly retained when it is first created. It may be retained more times (thus incrementing its reference count) and released (thus decrementing its reference count), until the reference count goes to zero.

Idiomatic usage

The general rules to use Retainable objects are the following:

  1. If the Retainable has been obtained by calling a method, and the caller code consumes it, then the caller code must call release().
  2. If the Retainable has been obtained by caller2 by calling a method, and caller2 returns it without consuming it to caller1, then caller2 must not call release(), since caller1 will.
  3. If the Retainable has been obtained as a method argument, the receiver code must either:
    1. Consume the Retainable synchronously within the method, in which case release() must not be called.
    2. Pass the Retainable to some other method, in which case release() must not be called.
    3. Store away the Retainable for later or asynchronous processing, for example storing it in containers such as java.util.Collections, or capturing it in a lambda that is passed to another thread, etc., in which case retain() must be called and a mechanism to call release() later or asynchronously for this additional retain() must be arranged.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Retainable.ReferenceCounter

A reference count implementation for a Retainable resource.

public static class
Retainable.Wrapper

A wrapper of Retainable instances.

Method Summary

Modifier and TypeMethod and Description
public default boolean

Returns:

true if calls to retain() are reference counted.
canRetain
()

Returns whether this resource is referenced counted by calls to retain() and release().

public default boolean

Returns:

true when the reference count goes to zero or if there was no reference count, false otherwise.
release
()

Releases this resource, potentially decrementing a reference count (if any).

public default void
retain()

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

Method Detail

canRetainback to summary
public default boolean canRetain()

Returns whether this resource is referenced counted by calls to retain() and release().

Implementations may decide that special resources are not not referenced counted (for example, static constants) so calling retain() is a no-operation, and calling release() on those special resources is a no-operation that always returns true.

Returns:boolean

true if calls to retain() are reference counted.

releaseback to summary
public default boolean release()

Releases this resource, potentially decrementing a reference count (if any).

Returns:boolean

true when the reference count goes to zero or if there was no reference count, false otherwise.

retainback to summary
public default void retain()

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

org.eclipse.jetty.io back to summary

public Class Retainable.ReferenceCounter

extends Object
implements Retainable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.Retainable

A reference count implementation for a Retainable resource.

The reference count is initialized to 1 when the resource is created, and therefore it is implicitly retained and needs a call to release().

Additional calls to retain() must be matched by correspondent calls to release().

When the reference count goes to zero, the resource may be pooled. When the resource is acquired from the pool, acquire() should be called to set the reference count to 1.

Field Summary

Modifier and TypeField and Description
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
protected
ReferenceCounter(int initialCount)

Method Summary

Modifier and TypeMethod and Description
public void
acquire()

Updates the reference count from 0 to 1.

public boolean
canRetain()

Overrides default org.eclipse.jetty.io.Retainable.canRetain.

Returns whether this resource is referenced counted by calls to retain() and release().

public int
get()

Returns: the current reference count

public boolean

Returns:

whether this buffer is retained
isRetained
()

Returns whether retain() has been called at least one more time than release().

public boolean
release()

Overrides default org.eclipse.jetty.io.Retainable.release.

Releases this resource, potentially decrementing a reference count (if any).

public void
retain()

Overrides default org.eclipse.jetty.io.Retainable.retain.

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

referencesback to summary
private final AtomicInteger references

Constructor Detail

ReferenceCounterback to summary
public ReferenceCounter()
ReferenceCounterback to summary
protected ReferenceCounter(int initialCount)

Method Detail

acquireback to summary
public void acquire()

Updates the reference count from 0 to 1.

This method should only be used when this resource is acquired from a pool.

canRetainback to summary
public boolean canRetain()

Overrides default org.eclipse.jetty.io.Retainable.canRetain.

Doc from org.eclipse.jetty.io.Retainable.canRetain.

Returns whether this resource is referenced counted by calls to retain() and release().

Implementations may decide that special resources are not not referenced counted (for example, static constants) so calling retain() is a no-operation, and calling release() on those special resources is a no-operation that always returns true.

Returns:boolean

true if calls to retain() are reference counted.

Annotations
@Override
getback to summary
public int get()
Returns:int

the current reference count

isRetainedback to summary
public boolean isRetained()

Returns whether retain() has been called at least one more time than release().

Returns:boolean

whether this buffer is retained

releaseback to summary
public boolean release()

Overrides default org.eclipse.jetty.io.Retainable.release.

Doc from org.eclipse.jetty.io.Retainable.release.

Releases this resource, potentially decrementing a reference count (if any).

Returns:boolean

true when the reference count goes to zero or if there was no reference count, false otherwise.

Annotations
@Override
retainback to summary
public void retain()

Overrides default org.eclipse.jetty.io.Retainable.retain.

Doc from org.eclipse.jetty.io.Retainable.retain.

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
tryRetainback to summary
public boolean tryRetain()
org.eclipse.jetty.io back to summary

public Class Retainable.Wrapper

extends Object
implements Retainable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.Retainable
Known Direct Subclasses
org.eclipse.jetty.io.RetainableByteBuffer.Wrapper

A wrapper of Retainable instances.

Field Summary

Modifier and TypeField and Description
private final Retainable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRetain()

Overrides default org.eclipse.jetty.io.Retainable.canRetain.

Returns whether this resource is referenced counted by calls to retain() and release().

public Retainable
public boolean
release()

Overrides default org.eclipse.jetty.io.Retainable.release.

Releases this resource, potentially decrementing a reference count (if any).

public void
retain()

Overrides default org.eclipse.jetty.io.Retainable.retain.

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

wrappedback to summary
private final Retainable wrapped

Constructor Detail

Wrapperback to summary
public Wrapper(Retainable wrapped)

Method Detail

canRetainback to summary
public boolean canRetain()

Overrides default org.eclipse.jetty.io.Retainable.canRetain.

Doc from org.eclipse.jetty.io.Retainable.canRetain.

Returns whether this resource is referenced counted by calls to retain() and release().

Implementations may decide that special resources are not not referenced counted (for example, static constants) so calling retain() is a no-operation, and calling release() on those special resources is a no-operation that always returns true.

Returns:boolean

true if calls to retain() are reference counted.

Annotations
@Override
getWrappedback to summary
public Retainable getWrapped()
releaseback to summary
public boolean release()

Overrides default org.eclipse.jetty.io.Retainable.release.

Doc from org.eclipse.jetty.io.Retainable.release.

Releases this resource, potentially decrementing a reference count (if any).

Returns:boolean

true when the reference count goes to zero or if there was no reference count, false otherwise.

Annotations
@Override
retainback to summary
public void retain()

Overrides default org.eclipse.jetty.io.Retainable.retain.

Doc from org.eclipse.jetty.io.Retainable.retain.

Retains this resource, potentially incrementing a reference count if there are resources that will be released.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override