1. Design Goals and Key Roles
This package provides specialized service implementations for running Aspectran as an independent background process (daemon) without a web server. The design goals of this package are as follows:
- Provide an Independent Execution Environment: Provides a foundation for building standalone applications that have their own lifecycle, without relying on a web container.
- Proactive Request Execution Model: Unlike
WebService, which reacts to external HTTP requests, it implements a proactive execution model where specific internal logic or a scheduler directly triggers translet execution. - Programmatic Entry Point: Provides clear and controllable entry points through
translate()methods, allowing translets to be called programmatically from within the code. - Session Functionality Support in Non-Web Environments: Optionally provides session management functionality to allow long-running applications like daemons to maintain state across multiple
translate()calls.
In conclusion, this package aims to enable the full utilization of Aspectran’s powerful features (AOP, DI, etc.) in UI-less server applications such as background tasks, batch processes, and message queue listeners.
2. Detailed Analysis of Key Classes and Interfaces
DaemonService (Interface)
The specification for Aspectran services specialized for the daemon environment.
Key Responsibilities:
- Inherits
CoreServiceto possess all core service functionalities. - Defines
translate(...)methods, which are the core entry points for programmatically executing translets. These methods are the primary way for daemon applications to call internal services. - Defines the
newSessionAdapter()method for creating a session adapter (SessionAdapter) for the daemon environment.
DefaultDaemonService (Implementation Class)
The final implementation of DaemonService, responsible for receiving programmatic translet calls and handling the entire process of creating and executing DaemonActivity.
Key Responsibilities:
- Inherits
DefaultCoreServiceto act as a fully functional core service. - Creates and manages
DefaultSessionManageraccording to theDaemonConfigsettings, allowing session simulation even in a daemon environment. - Provides security features through
RequestAcceptor, which can limit the list of translets that can be called bytranslate()methods.
Key Method Analysis:
translate(String transletName, ...): This class’s core execution method. It plays a role equivalent toWebService.service()in a web environment.- Checks if the service is in a paused state.
- Checks if the requested
transletNameis allowed byRequestAcceptor. - Creates a
DaemonActivityinstance specialized for the daemon environment. - Sets the translet name, virtual HTTP method, attributes, parameters, etc., received by the
translate()method intoDaemonActivity. - Calls
activity.prepare()andactivity.perform()to drive Aspectran’s standard request processing pipeline. - Returns the
Transletobject containing the execution result.
DefaultDaemonServiceBuilder (Builder Class)
A factory class that creates and configures DefaultDaemonService instances.
Key Responsibilities:
- Receives an
AspectranConfigobject, instantiatesDefaultDaemonService, and injects the necessary configurations. - Configures
ServiceStateListenerto ensure that the service’s lifecycle (start, stop, pause, etc.) is correctly integrated withCoreServiceHolderandSessionManager.
3. Interaction with Other Packages
com.aspectran.core.service: Directly inheritsDefaultCoreServiceto reuse all of Aspectran’s core functionalities (lifecycle,ActivityContextmanagement, etc.).com.aspectran.daemon.activity:DefaultDaemonServicecreates aDaemonActivityfor everytranslate()call.DaemonActivityacts as an adapter that converts programmatic calls into a form that the core engine can understand.com.aspectran.core.context.config: Reads daemon-specific configurations (session management, polling settings, etc.) from theDaemonConfigconfiguration object and applies them to the service.
4. Package Summary and Architectural Significance
The com.aspectran.daemon.service package plays a crucial role in transforming a reactive web framework into a proactive application container. While WebService waits for external requests, DaemonService provides a structure where the application itself can call its own logic (translets) as needed.
The translate() method is an internal API call gateway that architecturally performs the same role as a web request. All translets called through this method can receive all of Aspectran’s features, such as aspects (transactions, security, etc.) and dependency injection, just like web requests.
Furthermore, providing session management functionality in a non-web environment is one of the unique features of this package. This allows for the effective construction of complex background applications that need to maintain state across multiple translate() calls.