ServiceManager
com.jsmacrosce.jsmacros.core.service.ServiceManager
Manages registered script services, their running contexts, and reloads triggered by file changes.
Nested types
Constructors
new ServiceManager
Methods
disableReload
disableService
disableService(String name): ServiceManager.ServiceStatus#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
enableService(String name): ServiceManager.ServiceStatus#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
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
getTrigger
Returns the trigger configuration for a registered service.
Parameters:
name: registered service name
Returns: the service trigger
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 setisCrashed
isEnabled
isRunning
load
load(): void#Loads configured services, registering missing services and updating existing triggers.
markCrashed
registerService
Registers a service from a file under the macro folder and starts it immediately.
Parameters:
name: service namepathToFile: path relative to the macro folder
Returns:
false if a service with this name is already registeredRegisters a service from a file under the macro folder, optionally starting it immediately.
Parameters:
name: service namepathToFile: path relative to the macro folderenabled: whether to start the service immediately
Returns:
false if a service with this name is already registeredregisterService(String name, ServiceTrigger trigger): boolean#Registers a service with the given trigger and starts it if the trigger is enabled.
Parameters:
name: service nametrigger: service trigger configuration
Returns:
false if a service with this name is already registeredrenameService
restartService
restartService(String name): ServiceManager.ServiceStatus#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 trackedkeepAlive:trueto add the sync object;falseto remove it
startReloadListener
Enables service reloads in response to file changes.
startService
startService(String name): ServiceManager.ServiceStatus#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
status(String name): ServiceManager.ServiceStatus#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
Disables service reloads in response to file changes.
stopService
stopService(String name): ServiceManager.ServiceStatus#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
Checks eligible services for file modification and restarts them when their file timestamp changes.