Welcome to the JavaTaskQueue repository!
This project implements a robust, distributed-style Task Queue and Job Scheduler built purely with Java 17, without relying on any external frameworks like Spring or Web Application servers. It uses SQLite for lightweight, reliable persistence.
Below you'll find comprehensive instructions on how to use and interact with the project.
Before running the application, make sure you have:
- Java 17 (or newer) installed and available in your
PATH. - Maven (Apache Maven 3.8+ recommended) installed.
You need to compile the Java files and package them along with the required dependencies (SQLite JDBC and JSON library) into an executable JAR.
Open your terminal or command prompt in the project root directory and run:
mvn clean packageThis command will:
- Clean previous build artifacts.
- Compile the source code.
- Run the automated test suite.
- Generate an Uber/Fat JAR inside the
targetdirectory:target/JavaTaskQueue-jar-with-dependencies.jar.
Note: If you want to skip tests (not recommended), you can use
mvn clean package -DskipTests.
The Task Broker acts as the core of the task queue. It orchestrates task scheduling, delegation to worker threads, and saving states to the SQLite database.
In a terminal, start the server using:
java -jar target/JavaTaskQueue-jar-with-dependencies.jarYou should see a banner along with initialization logs confirming that the SQLite repository and TCPServer (on port 9090) have successfully started.
The application comes with an interactive command-line interface (CLI) to communicate with the TaskQueue server.
Open a new, separate terminal window and run the client:
java -cp target/JavaTaskQueue-jar-with-dependencies.jar com.taskqueue.client.TaskQueueClientIf your server is running on another machine or port, you can specify them:
java -cp target/JavaTaskQueue-jar-with-dependencies.jar com.taskqueue.client.TaskQueueClient --host 192.168.1.10 --port 9091Once connected, you will see a jtq> prompt.
From the jtq> prompt, you can type several commands.
Submit tasks using JSON strings. The queue currently supports three types of tasks: ECHO, COMPUTE, and SLEEP.
- Echo Task:
SUBMIT {"type":"ECHO","payload":"Hello, JavaTaskQueue!","priority":"HIGH"} - Compute Task (Factorial):
SUBMIT {"type":"COMPUTE","payload":"FACTORIAL:15","priority":"MEDIUM"} - Sleep Task (Delay simulation):
SUBMIT {"type":"SLEEP","payload":"3000","priority":"LOW"}
- Check specific task status:
STATUS <task-id-returned-from-submit> - List all tasks:
LIST
- Cancel a task:
CANCEL <task-id> - Shutdown Server:
SHUTDOWN - Exit the Client:
exit
To just run the tests and verify component integrity (Broker, Workers, Compute Handlers, etc.):
mvn testIf you want to extend the application to support new task logic:
- Create a class implementing
com.taskqueue.handler.TaskHandler. - Register it in
Main.javabefore starting the server:TaskHandlerRegistry.register("NEW_TYPE", new MyCustomHandler());
Enjoy using JavaTaskQueue!