# Class: ServiceReference

## vertx-service-discovery-js/service_reference~ ServiceReference

#### new ServiceReference()

Source:
  - vertx-service-discovery-js/service_reference.js, line 29

### Methods

#### cached() → {Object}

Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet.

Source:
  - vertx-service-discovery-js/service_reference.js, line 103

##### Returns:

the object, `null` if not yet retrieved

Type
  Object

#### cachedAs(x) → {Object}

Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. Unlike ServiceReference#cached, this method return the warpped object to the desired (given) type.

##### Parameters:

Name | Type | Description
--- | --- | ---
`x` | todo | the type of object

Source:
  - vertx-service-discovery-js/service_reference.js, line 89

##### Returns:

the object, `null` if not yet retrieved

Type
  Object

#### get() → {Object}

Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the service type and the server itself. This method returns the Java version and primary facet of the object, use ServiceReference#getAs to retrieve the polyglot instance of the object or another facet..

Source:
  - vertx-service-discovery-js/service_reference.js, line 59

##### Returns:

the object to access the service

Type
  Object

#### getAs(x) → {Object}

Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the service type and the server itself. This method wraps the service object into the desired type.

##### Parameters:

Name | Type | Description
--- | --- | ---
`x` | todo | the type of object

Source:
  - vertx-service-discovery-js/service_reference.js, line 74

##### Returns:

the object to access the service wrapped to the given type

Type
  Object

#### isHolding(object) → {boolean}

Checks whether or not the service reference has the given service object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`object` | Object | the service object, must not be `null`

Source:
  - vertx-service-discovery-js/service_reference.js, line 131

##### Returns:

`true` if the service reference service object is equal to the given object, `false` otherwise.

Type
  boolean

#### record() → {Object}

Source:
  - vertx-service-discovery-js/service_reference.js, line 40

##### Returns:

the service record.

Type
  Object

#### release()

Releases the reference. Once released, the consumer must not use the reference anymore. This method must be idempotent and defensive, as multiple call may happen.

Source:
  - vertx-service-discovery-js/service_reference.js, line 117