Skip to content

ServiceManager ​

com.jsmacrosce.jsmacros.core.service.ServiceManager

Since1.6.3

Manages registered script services, their running contexts, and reloads triggered by file changes.

Nested types ​

Constructors ​

new ServiceManager ​

new ServiceManager(Core<?, ?> runner)#
Stores the core used for subsequent service operations; this constructor does not register or start services.

Parameters:

  • runner: core that owns this manager

Methods ​

disableReload ​

disableReload(String serviceName): voidSince1.8.4#
Removes cached crash and file-timestamp state for the registered service; this does not stop it.

Parameters:

  • serviceName: the name of the service to disable the reload feature for

disableService ​

Disables a registered service without stopping it.

Parameters:

  • name: service name
Returns: ServiceStatus.UNKNOWN if unregistered; otherwise ServiceStatus.ENABLED if this call disabled it, or ServiceStatus.DISABLED if already disabled

enableService ​

Enables a registered service without starting it.

Parameters:

  • name: service name
Returns: ServiceStatus.UNKNOWN if unregistered; otherwise ServiceStatus.DISABLED if this call enabled it, or ServiceStatus.ENABLED if already enabled

getServiceData ​

getServiceData(String name): EventServiceSince1.6.5#
Returns the triggering event for a registered service's current context; the service must be running.

Parameters:

  • name: registered service name
Returns: the service event

getServices ​

getServices(): Set<String>#
Returns: an immutable snapshot of the registered service names

getTrigger ​

getTrigger(String name): ServiceTriggerSince1.6.5#
Returns the trigger configuration for a registered service.

Parameters:

  • name: registered service name
Returns: the service trigger

Note: [named getServiceData previously]

hasKeepAlive ​

static hasKeepAlive(BaseScriptContext<?> ctx): boolean#
Checks whether a service-triggered context's non-null sync object is in the shared keep-alive set.

Parameters:

  • ctx: context to check
Returns: true only when the triggering event is an EventService and its non-null sync object is in the set

isCrashed ​

isCrashed(String serviceName): booleanSince1.8.4#

Parameters:

  • serviceName: the name of the service to check
Returns: true if the service is marked crashed

isEnabled ​

isEnabled(String name): booleanSince1.8.4#
Returns whether a registered service is enabled.

Parameters:

  • name: service name
Returns: false if unregistered or disabled; true if enabled

isRunning ​

isRunning(String name): booleanSince1.8.4#
Returns whether the registered service's context is open, regardless of its enabled state.

Parameters:

  • name: service name
Returns: true if registered with an open context; false otherwise

load ​

load(): void#
Loads configured services, registering missing services and updating existing triggers.

markCrashed ​

markCrashed(String serviceName): voidSince1.8.4#
Marks a service as crashed so the file-change listener can restart it after its file changes.

Parameters:

  • serviceName: the name of the service to mark as crashed

registerService ​

registerService(String name, String pathToFile): boolean#
Registers a service from a file under the macro folder and starts it immediately.

Parameters:

  • name: service name
  • pathToFile: path relative to the macro folder
Returns: false if a service with this name is already registered
registerService(String name, String pathToFile, boolean enabled): boolean#
Registers a service from a file under the macro folder, optionally starting it immediately.

Parameters:

  • name: service name
  • pathToFile: path relative to the macro folder
  • enabled: whether to start the service immediately
Returns: false if a service with this name is already registered
registerService(String name, ServiceTrigger trigger): boolean#
Registers a service with the given trigger and starts it if the trigger is enabled.

Parameters:

  • name: service name
  • trigger: service trigger configuration
Returns: false if a service with this name is already registered

renameService ​

renameService(String oldName, String newName): boolean#
Renames a registered service, preserving its trigger and running context.

Parameters:

  • oldName: current service name
  • newName: replacement service name
Returns: false if the new name is already registered or the old name is unknown

restartService ​

Stops the service, then starts it again if registered, even if disabled.

Parameters:

  • name: service name
Returns: the result of stopping the service, or ServiceStatus.UNKNOWN if unregistered; a stopped service returns ServiceStatus.STOPPED even though it is then started

save ​

save(): void#
Saves registered service triggers to configuration and writes the configuration.

setAutoUnregisterKeepAlive ​

static setAutoUnregisterKeepAlive(BaseScriptContext<?> ctx, boolean keepAlive): void#
Adds or removes the context's sync object from the shared auto-unregister keep-alive set.

Parameters:

  • ctx: context whose sync object is tracked
  • keepAlive: true to add the sync object; false to remove it

startReloadListener ​

startReloadListener(): voidSince1.8.4#
Enables service reloads in response to file changes.

startService ​

Starts a service if it is not already running.

Parameters:

  • name: service name
Returns: ServiceStatus.UNKNOWN if unknown; otherwise ServiceStatus.STOPPED if this call starts it, or ServiceStatus.RUNNING if it was already running

status ​

Parameters:

  • name: service name
Returns: ServiceStatus.UNKNOWN if unregistered; otherwise ServiceStatus.ENABLED or ServiceStatus.STOPPED when enabled and respectively running or stopped, or ServiceStatus.RUNNING or ServiceStatus.DISABLED when disabled and respectively running or stopped

stopReloadListener ​

stopReloadListener(): voidSince1.8.4#
Disables service reloads in response to file changes.

stopService ​

Stops a running service, invoking its stop callbacks and unregistering its event listeners and registrables.

Parameters:

  • name: service name
Returns: ServiceStatus.UNKNOWN if unknown; otherwise ServiceStatus.RUNNING if this call stopped it, or ServiceStatus.STOPPED if it was already stopped

tickReloadListener ​

tickReloadListener(): voidSince1.8.4#
Checks eligible services for file modification and restarts them when their file timestamp changes.

unregisterService ​

unregisterService(String name): boolean#
Stops and unregisters a service if present.

Parameters:

  • name: service name
Returns: true if a service was registered and removed