Package com.linkedin.venice.utils
Class SharedObjectFactory<T>
java.lang.Object
com.linkedin.venice.utils.SharedObjectFactory<T>
- Type Parameters:
T- Class whose objects need to release resources cleanly.
A factory class to create shared objects that need to release resources cleanly. This class uses reference counting
to ensure that resources are released safely.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet a shared object that has the specified .intgetReferenceCount(String identifier) Return the current reference count of the object identified by the .booleanA method to notify to the factory that the user of the object no longer needs it.intsize()
-
Constructor Details
-
SharedObjectFactory
public SharedObjectFactory()
-
-
Method Details
-
get
Get a shared object that has the specified . If an object with the doesn't exist, a new one is created using the . When this function is called, the reference count of the shared object is incremented by 1.- Parameters:
identifier- A string that uniquely identifies the object being sharedconstructor- A {@link Supplier> to construct a new instance of the objectdestroyer- AConsumerto clean-up any state when the object is no longer needed- Returns:
- A shared object
-
release
A method to notify to the factory that the user of the object no longer needs it. This method decreases the reference count of the shared object by 1. If the reference count becomes 0, the destroyer is invoked and the object is removed from the shared objects.- Parameters:
identifier- A string that uniquely identifies the object being shared- Returns:
trueif the shared object is no longer being used;falseotherwise
-
size
public int size()- Returns:
- The number of shared objects that are being managed
-
getReferenceCount
Return the current reference count of the object identified by the . If the factory isn't managing an object with the identifier, returns 0- Parameters:
identifier- A string that uniquely identifies the object being shared- Returns:
- the current reference count of the object identified by the . If the factory isn't managing an object with the identifier, returns 0
-