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
CoreService
to 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
DefaultCoreService
to act as a fully functional core service. - Creates and manages
DefaultSessionManager
according to theDaemonConfig
settings, 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
transletName
is allowed byRequestAcceptor
. - Creates a
DaemonActivity
instance 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
Translet
object containing the execution result.
DefaultDaemonServiceBuilder
(Builder Class)
A factory class that creates and configures DefaultDaemonService
instances.
Key Responsibilities:
- Receives an
AspectranConfig
object, instantiatesDefaultDaemonService
, and injects the necessary configurations. - Configures
ServiceStateListener
to ensure that the service’s lifecycle (start, stop, pause, etc.) is correctly integrated withCoreServiceHolder
andSessionManager
.
3. Interaction with Other Packages
com.aspectran.core.service
: Directly inheritsDefaultCoreService
to reuse all of Aspectran’s core functionalities (lifecycle,ActivityContext
management, etc.).com.aspectran.daemon.activity
:DefaultDaemonService
creates aDaemonActivity
for everytranslate()
call.DaemonActivity
acts 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 theDaemonConfig
configuration 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.