vertx / io.vertx.servicediscovery.types / AbstractServiceReference

# AbstractServiceReference

`abstract class AbstractServiceReference<T : Any> : ServiceReference`

A class to simplify the implementation of service reference. It stores the service object once retrieved. This class handles the synchronization, so callbacks are called with the monitor lock to avoid concurrent accesses.

### Parameters

`` - the type of service object

Author
Clement Escoffier

### Constructors

<init> | `AbstractServiceReference(vertx: Vertx, discovery: ServiceDiscovery, record: Record)` Creates a new instance of AbstractServiceReference.

### Functions

cached | `open fun <X : Any> cached(): X` Returns the service object. If not retrieved or released, it returns `null`.
cachedAs | `open fun <X : Any> cachedAs(x: Class<X>): X` GGets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. Unlike `#cached()` this method let you configure the type of object you want to retrieve. This parameter must match the expected service type, and must pass the "polyglot" version of the class.
close | `open fun close(): Unit` Same as `#release()`, here to implement AutoCloseable.
get | `open fun <X : Any> get(): X` Gets the service object. If not retrieved, call `#retrieve()`, otherwise returned the cached value.
getAs | `open fun <X : Any> getAs(x: Class<X>): X` Gets the service object. It can be a proxy, a client or whatever object depending on the service type. Unlike `#get()` this method let you configure the type of object you want to retrieve. This parameter must match the expected service type, and must pass the "polyglot" version of the class.
isHolding | `open fun isHolding(object: Any): Boolean`
record | `open fun record(): Record`
release | `open fun release(): Unit` If the service object has been retrieved, calls `#onClose` and release the reference. Otherwise, does nothing.