# Service

`com.jsmacrosce.jsmacros.core.service.EventService`

**Since:** 1.6.4

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Event payload for a running service, including shared arguments and stop callbacks.

## Constructors

### new EventService {#com.jsmacrosce.jsmacros.core.service.EventService_constructor-Core-String-}

```js
new EventService(Core<?, ?> runner, String name)
```

Initializes this event with its service runner and name; this does not start or register the service.

**Parameters:**
- `runner`: core associated with this event
- `name`: service name

## Fields

### postStopListener {#com.jsmacrosce.jsmacros.core.service.EventService_postStopListener}

```js
postStopListener: MethodWrapper<Object, Object, Object, ?>
```

Callback run after event listeners and registered resources are removed when the service stops.

**Since:** 1.9.1

### serviceName {#com.jsmacrosce.jsmacros.core.service.EventService_serviceName}

```js
serviceName: String
```

Immutable service name supplied at construction.

### stopListener {#com.jsmacrosce.jsmacros.core.service.EventService_stopListener}

```js
stopListener: MethodWrapper<Object, Object, Object, ?>
```

Callback run before event listeners and registered resources are removed when the service stops.

## Methods

### decrementAndGetInt {#com.jsmacrosce.jsmacros.core.service.EventService_decrementAndGetInt-String-}

```js
decrementAndGetInt(String name): Integer
```

Decrements the integer value and returns the result; returns `null` without changing the map if it is absent or not an integer.

**Parameters:**
- `name`: key to decrement

**Returns:** the value after decrement, or `null`

**Since:** 1.6.5

### getAndDecrementInt {#com.jsmacrosce.jsmacros.core.service.EventService_getAndDecrementInt-String-}

```js
getAndDecrementInt(String name): Integer
```

Decrements the integer value and returns its previous value; returns `null` without changing the map if it is absent or not an integer.

**Parameters:**
- `name`: key to read and decrement

**Returns:** the value before decrement, or `null`

**Since:** 1.6.5

### getAndIncrementInt {#com.jsmacrosce.jsmacros.core.service.EventService_getAndIncrementInt-String-}

```js
getAndIncrementInt(String name): Integer
```

Increments the integer value and returns its previous value; returns `null` without changing the map if it is absent or not an integer.

**Parameters:**
- `name`: key to read and increment

**Returns:** the value before increment, or `null`

**Since:** 1.6.5

### getBoolean {#com.jsmacrosce.jsmacros.core.service.EventService_getBoolean-String-}

```js
getBoolean(String name): Boolean
```

Returns the value if it is a boolean; otherwise returns `null`.

**Parameters:**
- `name`: key to read

**Returns:** the boolean value, or `null`

**Since:** 1.6.5

### getDouble {#com.jsmacrosce.jsmacros.core.service.EventService_getDouble-String-}

```js
getDouble(String name): Double
```

Returns the value if it is a double; otherwise returns `null`.

**Parameters:**
- `name`: key to read

**Returns:** the double value, or `null`

**Since:** 1.6.5

### getInt {#com.jsmacrosce.jsmacros.core.service.EventService_getInt-String-}

```js
getInt(String name): Integer
```

Returns the value if it is an integer; otherwise returns `null`.

**Parameters:**
- `name`: key to read

**Returns:** the integer value, or `null`

**Since:** 1.6.5

### getObject {#com.jsmacrosce.jsmacros.core.service.EventService_getObject-String-}

```js
getObject(String name): Object
```

Returns the value stored for this key, or `null` if absent.

**Parameters:**
- `name`: key to read

**Returns:** the stored value, or `null`

**Since:** 1.6.5

### getRaw {#com.jsmacrosce.jsmacros.core.service.EventService_getRaw-}

```js
getRaw(): Map<String, Object>
```

Returns the live argument map; direct mutations bypass [putObject(String, Object)](#com.jsmacrosce.jsmacros.core.service.EventService_putObject-String-Object-)'s guest-object check.

**Returns:** live shared argument map

### getString {#com.jsmacrosce.jsmacros.core.service.EventService_getString-String-}

```js
getString(String name): String
```

Returns the value if it is a string; otherwise returns `null`.

**Parameters:**
- `name`: key to read

**Returns:** the string value, or `null`

**Since:** 1.6.5

### getType {#com.jsmacrosce.jsmacros.core.service.EventService_getType-String-}

```js
getType(String name): String
```

Returns the stored value's type label, or `null` if the key is absent.

**Parameters:**
- `name`: key to inspect

**Returns:** `Int`, `String`, `Double`, `Boolean`, or `Object`; `null` if absent

**Since:** 1.6.5

### incrementAndGetInt {#com.jsmacrosce.jsmacros.core.service.EventService_incrementAndGetInt-String-}

```js
incrementAndGetInt(String name): Integer
```

Increments the integer value and returns the result; returns `null` without changing the map if it is absent or not an integer.

**Parameters:**
- `name`: key to increment

**Returns:** the value after increment, or `null`

**Since:** 1.6.5

### putBoolean {#com.jsmacrosce.jsmacros.core.service.EventService_putBoolean-String-boolean-}

```js
putBoolean(String name, boolean b): boolean
```

Stores a boolean in this service event's shared argument map.

**Parameters:**
- `name`: map key
- `b`: value to store

**Returns:** the same value stored in the map

**Since:** 1.6.5

### putDouble {#com.jsmacrosce.jsmacros.core.service.EventService_putDouble-String-double-}

```js
putDouble(String name, double d): double
```

Stores a double in this service event's shared argument map.

**Parameters:**
- `name`: map key
- `d`: value to store

**Returns:** the same value stored in the map

**Since:** 1.6.5

### putInt {#com.jsmacrosce.jsmacros.core.service.EventService_putInt-String-int-}

```js
putInt(String name, int i): int
```

Stores an integer in this service event's shared argument map.

**Parameters:**
- `name`: map key
- `i`: value to store

**Returns:** the same value stored in the map

**Since:** 1.6.5

### putObject {#com.jsmacrosce.jsmacros.core.service.EventService_putObject-String-Object-}

```js
putObject(String name, Object o): Object
```

Stores an object in this service event's shared argument map. Guest-language objects are rejected.

**Parameters:**
- `name`: map key
- `o`: value to store

**Returns:** the same value stored in the map

**Since:** 1.6.5

### putString {#com.jsmacrosce.jsmacros.core.service.EventService_putString-String-String-}

```js
putString(String name, String str): String
```

Stores a string in this service event's shared argument map.

**Parameters:**
- `name`: map key
- `str`: value to store

**Returns:** the same value stored in the map

**Since:** 1.6.5

### remove {#com.jsmacrosce.jsmacros.core.service.EventService_remove-String-}

```js
remove(String key): void
```

Removes a key from this service event's shared argument map.

**Parameters:**
- `key`: key to remove

**Since:** 1.6.5

### toggleBoolean {#com.jsmacrosce.jsmacros.core.service.EventService_toggleBoolean-String-}

```js
toggleBoolean(String name): Boolean
```

Toggles the boolean value and returns the result; returns `null` without changing the map if it is absent or not a boolean.

**Parameters:**
- `name`: key to toggle

**Returns:** the value after toggling, or `null`

**Since:** 1.6.5

### toString {#com.jsmacrosce.jsmacros.core.service.EventService_toString-}

```js
toString(): String
```

Returns a diagnostic representation containing the service name.

**Returns:** diagnostic service-name text

### unregisterOnStop {#com.jsmacrosce.jsmacros.core.service.EventService_unregisterOnStop-boolean-Registrable[]-}

```js
unregisterOnStop(boolean offEvents, Registrable<?>... list): void
```

Configures cleanup performed when the service stops; each call replaces the previous configuration. Cleanup runs between [stopListener](#com.jsmacrosce.jsmacros.core.service.EventService_stopListener) and [postStopListener](#com.jsmacrosce.jsmacros.core.service.EventService_postStopListener).

**Parameters:**
- `offEvents`: whether to remove every listener registered by the service, rather than only listeners owned by its script context
- `list`: resources to unregister; an empty list disables resource cleanup

**Since:** 1.9.1
