1. Design Goals and Key Roles
The com.aspectran.daemon.service package provides the service layer implementation required to run Aspectran as an autonomous background daemon or operating system service without web servers or GUI environments.
The primary architectural objectives of this package are:
- Complete Standalone Runtime: Operates completely independently of web containers or application servers, integrating directly with operating system service managers (Linux
systemd, Apache Commons Daemonjsvc, Windows Serviceprocrun) to manage autonomous lifecycles. - Proactive Execution Model: Unlike reactive web architectures that wait passively for external HTTP requests, daemons drive a proactive execution model where internal schedulers, message queue consumers, and file pollers (
FileCommander) directly trigger business translets. - Programmatic Standard Entry Point (
translate): Exposes an intuitive API gateway allowing application code to programmatically dispatch translets with virtual parameters and receive outcomes synchronously. - In-Memory Session Management in Non-Web Contexts: Incorporates
DefaultSessionManagerto provide virtual session state across sequentialtranslate()calls in long-running processes. - Integrated Command Control Subsystem: Couples with
DaemonCommandRegistryto enable runtime administrative commands (restart, component reloading, status inspections) via file-based command drops or internal consoles.
2. Key Classes and Interfaces
classDiagram
class CoreService {
<<interface>>
}
class AbstractCoreService {
<<abstract>>
}
class DaemonService {
<<interface>>
+translate(String transletName) Translet
+translate(String transletName, Map attributes) Translet
+translate(String transletName, Map attributes, Map parameters) Translet
+getCommandRegistry() CommandRegistry
+getSessionManager() SessionManager
+newSessionAdapter() SessionAdapter
}
class AbstractDaemonService {
<<abstract>>
-DaemonConfig daemonConfig
-SessionManager sessionManager
-CommandRegistry commandRegistry
#doStart()
#doStop()
}
class DefaultDaemonService {
+translate(Translet translet)
#service(Activity activity)
}
class DefaultDaemonServiceBuilder {
+build(AspectranConfig) DaemonService
}
CoreService <|-- DaemonService
AbstractCoreService <|-- AbstractDaemonService
DaemonService <|.. AbstractDaemonService
AbstractDaemonService <|-- DefaultDaemonService
DefaultDaemonServiceBuilder ..> DefaultDaemonService : creates
DaemonService (Interface)
The top-level specification for daemon-specific services in Aspectran. Extends CoreService:
- Key Responsibilities:
translate(...): The primary overloaded entry point executing translets programmatically. Accepts translet names, attribute maps, parameter maps, and virtual HTTP methods, executing the pipeline and returning the completedTransletinstance.getCommandRegistry(): Returns theCommandRegistrymanaging commands runnable within the daemon process.getSessionManager(): Exposes theSessionManagermaintaining in-memory session state across translet invocations.newSessionAdapter(): Instantiates a daemon-specificSessionAdapterfor session virtualization.
AbstractDaemonService (Abstract Class)
The abstract template encapsulating core infrastructure wiring for DaemonService:
- Implementation Mechanics:
- Session Manager Lifecycle: Instantiates
DefaultSessionManagerconfigured viaDaemonConfig(sessionConfig), binding its start and stop routines todoStart()anddoStop(). - Command Registry Configuration: Populates
DaemonCommandRegistrywith built-in commands (restart,quit,sysinfo,translet,pollingInterval). - File Poller Integration: Launches background monitoring threads when external file command pollers (
FileCommander) are activated.
- Session Manager Lifecycle: Instantiates
DefaultDaemonService (Implementation Class)
The primary concrete implementation of DaemonService, translating programmatic calls into DaemonActivity instances and driving execution:
- Execution Pipeline (
translate):- Availability Verification: Ensures the service is active and not paused (
isPaused). Rejects requests if suspended. - Access Control Inspection (
RequestAcceptor): Validates requested translet names against configuredRequestAcceptorrule constraints. DaemonActivityInstantiation: Creates a dedicatedDaemonActivity, injecting supplied parameters, attributes, and virtual methods.- Pipeline Dispatching: Calls
service(activity)->activity.prepare()->activity.perform(), executing AOP advice chains, business actions, and response transformers. - Outcome Delivery: Returns the completed
Transletobject housing accumulatedProcessResultdata and serialized output.
- Availability Verification: Ensures the service is active and not paused (
DefaultDaemonServiceBuilder (Builder Class)
Factory builder that constructs and initializes DefaultDaemonService from AspectranConfig:
- Parses encoding settings, session timeouts, and command registry configurations from the
daemonconfiguration block. - Registers
ServiceStateListenerhandlers to register the daemon service withCoreServiceHolderupon startup.
3. Interactions with Other Packages and Subsystems
graph TD
subgraph Host ["OS Service Host Bridges"]
Jsvc["JsvcDaemon (Linux jsvc)"]
Procrun["ProcrunDaemon (Windows Service)"]
Simple["SimpleDaemon (Standalone Process)"]
DefaultD["DefaultDaemon (FileCommander Bundled)"]
end
subgraph ServiceLayer ["com.aspectran.daemon.service"]
DService["DefaultDaemonService"]
Registry["DaemonCommandRegistry"]
end
subgraph ActivityLayer ["com.aspectran.daemon.activity"]
DActivity["DaemonActivity"]
ReqAdapter["DaemonRequestAdapter (Map-based)"]
ResAdapter["DaemonResponseAdapter (Writer-based)"]
end
Jsvc --> DService
Procrun --> DService
Simple --> DService
DefaultD --> DService
DService --> Registry
DService -->|Created on translate()| DActivity
DActivity --> ReqAdapter
DActivity --> ResAdapter
- Four Daemon Host Bridges:
JsvcDaemon(Apache Commons Daemon),ProcrunDaemon(Windows Service),SimpleDaemon(main entry point), andDefaultDaemon(bundled withFileCommander) own aDaemonServiceinstance, delegating OS service commands (init,start,stop,destroy) toServiceLifeCycle. com.aspectran.daemon.command.polling:FileCommandermonitors incoming.commandfiles in designated polling directories, dispatching tasks toDaemonService.translate().com.aspectran.daemon.activity:DaemonServicetransforms programmatic invocations intoDaemonActivityinstances, executing them within Aspectran’s core pipeline.
4. Package Summary and Architectural Significance
The com.aspectran.daemon.service package expands Aspectran from a reactive web framework into an autonomous enterprise batch and background worker container:
- Multi-Purpose Business Logic Reuse: Translets written for web controllers can be invoked directly as background batch jobs or administration commands via
translate()without altering business logic. - OS-Native Lifecycle Support: Integrates cleanly with standard Linux and Windows service wrappers, supporting resilient, long-running production daemon workloads.
- In-Memory Session Virtualization: Simulates virtual sessions and in-memory I/O streams in network-less environments, preserving a uniform programming model across all application domains.