1. Design Goals and Key Roles
This package provides the Activity
implementation that actually executes translet calls programmatically initiated from DaemonService
. The design goals of this package are as follows:
- Concretizing the Execution Environment for Programmatic Calls: Inherits from the abstract
CoreActivity
to provideDaemonActivity
, which can process requests in a non-web context, specifically the daemon environment. - In-Memory Simulation of Request/Response: In a daemon environment without HTTP streams or console I/O, it provides adapters that simulate requests and responses using
Map
andWriter
. This allows theCoreActivity
execution pipeline to be reused as is, without code changes. - Integration with
DaemonService
: It is responsible for converting and connecting the parameters and attributes passed during aDaemonService
’stranslate()
method call into a form usable byActivity
.
In conclusion, this package acts as a key bridge between DaemonService
and CoreActivity
, and is responsible for adapting programmatic calls to operate within Aspectran’s standard execution pipeline.
2. Detailed Class Analysis
DaemonActivity
(Implementation Class)
The final implementation of Activity
for the daemon environment. A new instance is created each time DaemonService
’s translate()
method is called.
Key Responsibilities:
- Inherits
CoreActivity
, thus inheriting all of Aspectran’s standard request processing pipeline (advice, action execution, etc.). - Maintains the request name, method, attribute map, and parameter map passed via the
translate()
method as internal state. - Creates and manages request/response/session adapters specific to the daemon environment.
Key Method Analysis:
adapt()
: The core of adaptation for the daemon environment. It is called at the beginning ofCoreActivity
’sperform()
method to convert programmatic calls into standard interfaces.DaemonRequestAdapter
: Wraps theattributeMap
andparameterMap
passed to thetranslate()
method to act as aRequestAdapter
. This allowsCoreActivity
to access data in the same way as if it were reading parameters and attributes from an external request.DaemonResponseAdapter
: Internally wraps anOutputStringWriter
to act as aResponseAdapter
. Results from<echo>
actions, etc., are stored in thisWriter
instead of being output to a real network or console. After execution, thetranslate()
method can return the content of thisWriter
as a result.DefaultSessionAdapter
: If session management is enabled in the parentDaemonService
, it creates a session adapter to support state persistence.
Interaction with Other Classes:
DaemonService
: Within itstranslate()
method, it directly createsDaemonActivity
, sets parameters, and then callsprepare()
andperform()
to execute it.CoreActivity
:DaemonActivity
inheritsCoreActivity
and uses its execution pipeline as is. The primary role ofDaemonActivity
is to connect the inputs and outputs of this pipeline to the daemon environment.- Classes in
com.aspectran.daemon.adapter
package:DaemonRequestAdapter
andDaemonResponseAdapter
are directly created and used within theadapt()
method.
3. Package Summary and Architectural Significance
The com.aspectran.daemon.activity
package is an important example demonstrating the flexibility of Aspectran’s architecture. The core architectural significance of this package lies in the abstraction and simulation of the request/response cycle.
DaemonActivity
simulates requests and responses using only pure Java objects (Map
, Writer
) without actual network I/O. DaemonRequestAdapter
makes a Map
appear like a ‘request’, and DaemonResponseAdapter
makes a Writer
appear like a ‘response’. Thanks to this sophisticated adapter layer, the CoreActivity
execution engine does not need to know whether the data it is processing comes from a real HTTP request or from a method call within the code.
This design provides the technical foundation for building powerful background services by reusing Aspectran’s core functionalities (DI, AOP, transactions, etc.). In other words, by absorbing all dependencies on the execution environment within the adapter layer, it proves that the framework’s core logic can be consistently reused in various scenarios.