tinystruct focuses on reducing unnecessary complexity in application development. Its lightweight, modular nature makes it an excellent choice for developers looking for a straightforward, efficient framework for various Java-based projects.
tinystruct follows a modular, action-oriented architecture that enables code reuse between command-line applications and web services. The framework provides a unified interface through the @Action annotation mechanism, allowing developers to write code once and run it anywhere.
The diagram above illustrates how tinystruct allows applications to be accessed through both web services and command-line interfaces using the same underlying code. This architecture promotes code reusability, maintainability, and flexibility in deployment options.
Add the dependency into your pom.xml.
<dependency>
<groupId>org.tinystruct</groupId>
<artifactId>tinystruct</artifactId>
<version>1.6.2</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
Extend the AbstractApplication in Java
package tinystruct.examples;
import org.tinystruct.AbstractApplication;
import org.tinystruct.ApplicationException;
import org.tinystruct.system.annotation.Action;
public class example extends AbstractApplication {
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public String version() {
return "1.0";
}
@Action("praise")
public String praise() {
return "Praise the Lord!";
}
@Action("say")
public String say() throws ApplicationException {
if (null != getContext().getAttribute("--words"))
return getContext().getAttribute("--words").toString();
throw new ApplicationException("Could not find the parameter words.");
}
@Action("say")
public String say(String words) {
return words;
}
}
@Action("process")
public String process() throws ApplicationException {
// Get command line parameters from context
if (null != getContext().getAttribute("--data")) {
String data = getContext().getAttribute("--data").toString();
return processData(data);
}
throw new ApplicationException("Missing required parameter: --data");
}
public class ExampleApp extends AbstractApplication {
private static final EventDispatcher dispatcher = EventDispatcher.getInstance();
static {
dispatcher.registerHandler(InitEvent.class, handler ->
System.out.println(handler.getPayload()));
}
@Override
public void init() {
// Trigger event on initialization
dispatcher.dispatch(new InitEvent());
}
@Action("praise")
public String praise() {
return "Praise the Lord!";
}
@Action("say")
public String say() throws ApplicationException {
if (null != getContext().getAttribute("--words"))
return getContext().getAttribute("--words").toString();
throw new ApplicationException("Could not find the parameter --words.");
}
@Action("say")
public String say(String words) {
return words;
}
@Override
public String version() {
return "1.0";
}
}
# Database configuration
driver=org.h2.Driver
database.url=jdbc:h2:~/test
database.user=
database.password=
database.connections.max=10
# Default settings
default.file.encoding=UTF-8
default.home.page=say/Praise the Lord!
default.reload.mode=true
default.date.format=yyyy-MM-dd HH:mm:ss
# Error handling
default.error.process=false
default.error.page=error
# HTTP configuration
default.http.max_content_length = 4194304
# System directory
system.directory=
# Mail configuration
mail.smtp.host=
mail.pop3.host=
mail.smtp.port=
mail.pop3.port=
mail.smtp.auth=
mail.pop3.auth=
smtp.auth.user=
smtp.auth.pwd=
# Logging configuration
logging.override = !TRUE
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = UTF-8
org.tinystruct.valve.Watcher$LockEventListener.level=WARNING
# MQTT configuration
mqtt.server.host=tcp://192.168.0.101
mqtt.server.port=1883
# MCP configuration
mcp.auth.token=123456