1. Design Goals and Key Roles
This package provides specialized service implementations for running Aspectran as an interactive command-line shell. The design goals of this package are as follows:
- Provide an Interactive CLI Environment: Provides a foundation for building complete interactive CLI applications where users can directly input commands and view results in the console.
- User Input-Based Execution Model: Implements an execution model driven by direct user command input via the console, rather than external HTTP requests or internal programmatic calls.
- Abstraction of Console I/O: Through the
ShellConsole
interface, it abstracts interaction with the actual console (JLine, system console, etc.), ensuring that service logic is not dependent on specific console technologies. - Support for User-Friendly Shell Features: Provides various convenience features expected in a typical shell environment, such as command history, welcome/help messages, and output redirection (
>
).
In conclusion, this package aims to create an interactive management tool that can manage or test Aspectran’s powerful backend features.
2. Detailed Analysis of Key Classes and Interfaces
ShellService
(Interface)
The specification for Aspectran services specialized for the interactive shell environment.
Key Responsibilities:
- Inherits
CoreService
to possess all core service functionalities. - Provides access (
getConsole()
) toShellConsole
, which handles console I/O. - Defines methods related to the shell’s UI, such as welcome messages and help output.
- Defines the
translate(...)
method, which is the core entry point for executing a translet by receiving a parsed command line (TransletCommandLine
).
DefaultShellService
(Implementation Class)
The final implementation of ShellService
, responsible for receiving commands from the user and handling the entire process of creating and executing ShellActivity
.
Key Responsibilities:
- Inherits
DefaultCoreService
to act as a fully functional core service. - Maintains a reference to
ShellConsole
and uses it for all user interactions. - Reads and applies shell-specific configurations (welcome message, prompt, etc.) from
ShellConfig
.
Key Method Analysis:
translate(TransletCommandLine tcl)
: This class’s core execution method. The shell’s main loop parses user input to create aTransletCommandLine
object, and then calls this method.- Extracts the translet name, virtual HTTP method, parameters, attributes, etc., to be executed from the
TransletCommandLine
object. - Checks for output redirection specified by the user in the command (e.g.,
> output.log
) and determines theWriter
to which the result will be output. (If no redirection, it uses the consoleWriter
.) - Creates a
ShellActivity
instance specialized for the shell environment. - Sets the request information and the determined output
Writer
intoShellActivity
. - Calls
activity.prepare()
andactivity.perform()
to drive Aspectran’s standard request processing pipeline. - Supports asynchronous execution (
--async
option), in which case it usesCompletableFuture
to process the task in the background.
- Extracts the translet name, virtual HTTP method, parameters, attributes, etc., to be executed from the
DefaultShellServiceBuilder
(Builder Class)
A factory class that creates and configures DefaultShellService
instances.
Key Responsibilities:
- Receives an
AspectranConfig
and aShellConsole
implementation to instantiateDefaultShellService
. - Configures
ServiceStateListener
to ensure that the service lifecycle is correctly integrated withCoreServiceHolder
. - Responsible for configuring the initial console environment at service startup, including clearing the screen, displaying welcome messages, and help.
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.shell.activity
:DefaultShellService
creates aShellActivity
for every valid command.ShellActivity
acts as an adapter between console I/O and the core engine.com.aspectran.shell.console
: Handles all console I/O through theShellConsole
interface. This meansDefaultShellService
does not need to know about the actual console implementation (e.g.,JLineShellConsole
).com.aspectran.shell.command
: The shell’s main loop uses theCommandParser
in this package to convert the user input string into aTransletCommandLine
object.
4. Package Summary and Architectural Significance
The com.aspectran.shell.service
package transforms the Aspectran framework into an interactive CLI application framework. This demonstrates the flexibility of the architecture by implementing a user-driven interaction model, which is different from the reactive web service model or the proactive daemon service model.
The TransletCommandLine
object acts as a DTO (Data Transfer Object) that holds request information for the shell environment, separating command parsing logic from execution logic. Additionally, the ShellConsole
interface abstracts the external I/O device, the console, ensuring that service logic is not dependent on specific console technologies.
Through this package, developers can easily build powerful management tools or test clients that can directly call and control all beans and business logic (translets) managed by Aspectran from the terminal.