This project provides two thread-safe implementations of the Statistics
interface for collecting and calculating statistical data such as minimum, maximum, mean, and variance. The project also demonstrates SPI (Service Provider Interface) to allow switching between different implementations dynamically.
- Thread-Safe Implementations:
AtomicThreadSafeStatistics
: UsesAtomic
variables for thread safety.LockBasedThreadSafeStatistics
: UsesReentrantLock
for thread safety.
- SPI Integration: Allows dynamic switching between implementations.
statistics
├── statistics-spi # SPI interface module
├── statistics-atomic # Atomic implementation
├── statistics-lock # Lock-based implementation
├── statistics-test-base # Base test cases
├── statistics-client # SPI client to use implementations
└── dist # Packaged distribution
- Java: Ensure
JAVA_HOME
is set to a valid JDK installation. - Maven: Verify Maven is installed and available in
PATH
.
- Build all modules:
./build-and-package.sh
This script builds the project, and required artifacts are placed in dist.
- Execute the client:
cd ./dist/bin/ source run-spi-client.sh
- Create a new module (e.g.,
statistics-newimpl
). - Implement the
Statistics
interface. - Register the implementation in
META-INF/services/in.shashwattiwari.statistics.Statistics
.
To run all tests:
mvn test
- JUnit 5: Used for testing.
- Maven: For build and dependency management.
- Add more statistical methods.
- Improve SPI client logging.
- Support for distributed statistics computation.
- Supports performance benchmarking using JMH.
- Can be extended to handle backpressure scenarios.
- Utilise Actor Model based Frameworks like Akka, which inherently handle concurrency.
- One message at a time get processed by respective actors.
- Would be easier to scale horizontally.
For questions or feedback, please contact:
- Shashwat Tiwari: [[email protected]]