Skip to content

Commit 9ea5173

Browse files
JavaSaBrCopilot
andauthored
Update readme part 2 (#56)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 933234f commit 9ea5173

1 file changed

Lines changed: 190 additions & 49 deletions

File tree

README.md

Lines changed: 190 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,77 @@
1-
# License #
1+
# RLib
22

3-
Please see the file called LICENSE.
3+
A modular Java utility library providing common utilities for classpath scanning, runtime compilation, logging, networking, mail, collections, concurrency, and more.
44

5-
## How to use for java 21+
5+
[![Build Status](https://github.com/JavaSaBr/RLib/actions/workflows/develop.yml/badge.svg)](https://github.com/JavaSaBr/RLib/actions)
66

7-
#### Gradle
7+
## Requirements
8+
9+
- Java 21+
10+
- Gradle 9.1+ (wrapper included)
11+
- Docker (for running Testcontainers-based tests)
12+
13+
## Modules
14+
15+
| Module | Description |
16+
|--------|-------------|
17+
| `rlib-common` | Core utilities and common functionality |
18+
| `rlib-collections` | Extended collection implementations |
19+
| `rlib-compiler` | Runtime Java source compilation API |
20+
| `rlib-concurrent` | Concurrency utilities and helpers |
21+
| `rlib-classpath` | Classpath scanning and class discovery |
22+
| `rlib-functions` | Functional interfaces and utilities |
23+
| `rlib-geometry` | Geometry utilities |
24+
| `rlib-io` | I/O utilities |
25+
| `rlib-reference` | Reference utilities |
26+
| `rlib-reusable` | Object pooling and reusable resources |
27+
| `rlib-logger-api` | Logging API |
28+
| `rlib-logger-impl` | Default logger implementation |
29+
| `rlib-logger-slf4j` | SLF4J logger bridge |
30+
| `rlib-network` | Reactive network API (client/server) |
31+
| `rlib-mail` | Email sending utilities |
32+
| `rlib-testcontainers` | Test utilities including Fake SMTP container |
33+
| `rlib-fx` | JavaFX utilities |
34+
| `rlib-plugin-system` | Plugin system framework |
35+
36+
## Installation
37+
38+
### Gradle
839

940
```groovy
1041
repositories {
1142
maven {
12-
url "https://gitlab.com/api/v4/projects/37512056/packages/maven"
43+
url "https://gitlab.com/api/v4/projects/37512056/packages/maven"
1344
}
1445
}
1546
1647
ext {
17-
rlibVersion = "10.0.alpha10"
48+
rlibVersion = "10.0.alpha10"
1849
}
1950
2051
dependencies {
21-
implementation "javasabr.rlib:rlib-common:$rlibVersion"
22-
implementation "javasabr.rlib:rlib-collections:$rlibVersion"
23-
implementation "javasabr.rlib:rlib-compiler:$rlibVersion"
24-
implementation "javasabr.rlib:rlib-concurrent:$rlibVersion"
25-
implementation "javasabr.rlib:rlib-geometry:$rlibVersion"
26-
implementation "javasabr.rlib:rlib-logger-api:$rlibVersion"
27-
implementation "javasabr.rlib:rlib-logger-slf4j:$rlibVersion"
28-
implementation "javasabr.rlib:rlib-plugin-system:$rlibVersion"
29-
implementation "javasabr.rlib:rlib-reference:$rlibVersion"
30-
implementation "javasabr.rlib:rlib-reusable:$rlibVersion"
31-
implementation "javasabr.rlib:rlib-fx:$rlibVersion"
32-
implementation "javasabr.rlib:rlib-network:$rlibVersion"
33-
implementation "javasabr.rlib:rlib-mail:$rlibVersion"
34-
implementation "javasabr.rlib:rlib-testcontainers:$rlibVersion"
52+
implementation "javasabr.rlib:rlib-common:$rlibVersion"
53+
implementation "javasabr.rlib:rlib-collections:$rlibVersion"
54+
implementation "javasabr.rlib:rlib-compiler:$rlibVersion"
55+
implementation "javasabr.rlib:rlib-concurrent:$rlibVersion"
56+
implementation "javasabr.rlib:rlib-geometry:$rlibVersion"
57+
implementation "javasabr.rlib:rlib-logger-api:$rlibVersion"
58+
implementation "javasabr.rlib:rlib-logger-slf4j:$rlibVersion"
59+
implementation "javasabr.rlib:rlib-plugin-system:$rlibVersion"
60+
implementation "javasabr.rlib:rlib-reference:$rlibVersion"
61+
implementation "javasabr.rlib:rlib-reusable:$rlibVersion"
62+
implementation "javasabr.rlib:rlib-fx:$rlibVersion"
63+
implementation "javasabr.rlib:rlib-network:$rlibVersion"
64+
implementation "javasabr.rlib:rlib-mail:$rlibVersion"
65+
implementation "javasabr.rlib:rlib-testcontainers:$rlibVersion"
3566
}
3667
```
37-
## Most interesting parts:
38-
39-
### Fake SMTP Server
40-
41-
```java
42-
43-
var container = new FakeSMTPTestContainer()
44-
.withSmtpPassword("pwd")
45-
.withSmtpUser("test_user");
46-
47-
container.start();
48-
container.waitForReadyState();
49-
50-
// sending emails to this server
51-
52-
// checking API
53-
var count = container.getEmailCountFrom("from@test.com");
5468

55-
// clearing API
56-
container.deleteEmails();
57-
```
69+
## Usage Examples
5870

5971
### Classpath Scanner API
6072

73+
Scan classpath to discover classes implementing interfaces or extending base classes:
74+
6175
```java
6276
var scanner = ClassPathScannerFactory.newDefaultScanner();
6377
scanner.setUseSystemClasspath(true);
@@ -69,21 +83,23 @@ var inherited = scanner.findInherited(AbstractArray.class);
6983

7084
### Compiler API
7185

86+
Compile Java source code at runtime:
87+
7288
```java
7389
var javaSource = getClass().getResource("/java/source/TestCompileJavaSource.java");
7490

7591
var compiler = CompilerFactory.newDefaultCompiler();
7692
var compiled = compiler.compile(javaSource.toURI());
7793

7894
var instance = ClassUtils.newInstance(compiled[0]);
79-
var method = instance
80-
.getClass()
81-
.getMethod("makeString");
82-
var result = method.invoke(instance);
95+
var method = instance.getClass().getMethod("makeString");
96+
var result = method.invoke(instance);
8397
```
8498

8599
### Logger API
86100

101+
Flexible logging with lazy evaluation and configurable log levels:
102+
87103
```java
88104
// getting logger by class/name
89105
var logger = LoggerManager.getLogger(getClass());
@@ -93,7 +109,7 @@ LoggerLevel.DEBUG.setEnabled(true);
93109

94110
logger.debug("Simple message");
95111
logger.debug(5, (val) -> "Lazy message with 5: " + val);
96-
logger.debug(5, "Lazy message with 5:%d"::formated);
112+
logger.debug(5, "Lazy message with 5:%d"::formatted);
97113
logger.debug(5, 10D, (val1, val2) -> "Lazy message with 5: " + val1 + " and 10: " + val2);
98114
logger.debug(5, 10D, "Lazy message with 5:%d and 10:%d"::formatted);
99115

@@ -106,6 +122,8 @@ logger.setEnabled(LoggerLevel.DEBUG, true);
106122

107123
### Mail Sender
108124

125+
Send emails synchronously or asynchronously:
126+
109127
```java
110128
var config = MailSenderConfig
111129
.builder()
@@ -128,15 +146,15 @@ var javaxConfig = JavaxMailSender.JavaxMailSenderConfig
128146

129147
var sender = new JavaxMailSender(config, javaxConfig);
130148

131-
sender.send("to@test.com","Test Subject","Content");
149+
sender.send("to@test.com", "Test Subject", "Content");
132150
sender
133-
.sendAsync("to@test.com","Test Subject","Content")
151+
.sendAsync("to@test.com", "Test Subject", "Content")
134152
.thenAccept(aVoid -> System.out.println("done!"));
135153
```
136154

137155
### Network API
138156

139-
#### Simple String Echo Server/Client
157+
Reactive network communication with simple client/server setup:
140158

141159
```java
142160
var serverNetwork = NetworkFactory.newStringDataServerNetwork();
@@ -155,8 +173,131 @@ var clientNetwork = NetworkFactory.newStringDataClientNetwork();
155173
clientNetwork
156174
.connected(serverAddress)
157175
.doOnNext(connection -> IntStream
158-
.range(10,100)
176+
.range(10, 100)
159177
.forEach(length -> connection.send(new StringWritablePacket(StringUtils.generate(length)))))
160178
.flatMapMany(Connection::receivedEvents)
161179
.subscribe(event -> System.out.println("Received from server: " + event.packet.getData()));
162180
```
181+
182+
### Fake SMTP Server (for testing)
183+
184+
Use a containerized fake SMTP server for integration tests:
185+
186+
```java
187+
var container = new FakeSMTPTestContainer()
188+
.withSmtpPassword("pwd")
189+
.withSmtpUser("test_user");
190+
191+
container.start();
192+
container.waitForReadyState();
193+
194+
// sending emails to this server
195+
196+
// checking API
197+
var count = container.getEmailCountFrom("from@test.com");
198+
199+
// clearing API
200+
container.deleteEmails();
201+
```
202+
203+
### Collections API
204+
205+
Extended collections with dictionaries (maps) and arrays optimized for specific use cases:
206+
207+
```java
208+
// Mutable dictionary (map) with object keys
209+
var dictionary = DictionaryFactory.mutableRefToRefDictionary();
210+
dictionary.put("key1", "value1");
211+
dictionary.put("key2", "value2");
212+
213+
var value = dictionary.get("key1");
214+
215+
// Thread-safe dictionary with stamped lock
216+
var lockableDictionary = DictionaryFactory.stampedLockBasedRefToRefDictionary();
217+
var stamp = lockableDictionary.writeLock();
218+
try {
219+
lockableDictionary.put("key", "value");
220+
} finally {
221+
lockableDictionary.writeUnlock(stamp);
222+
}
223+
224+
// Primitive key dictionaries (no boxing overhead)
225+
var intToRefDictionary = DictionaryFactory.mutableIntToRefDictionary();
226+
intToRefDictionary.put(1, "value1");
227+
228+
var longToRefDictionary = DictionaryFactory.mutableLongToRefDictionary();
229+
longToRefDictionary.put(100L, "value2");
230+
231+
// Mutable arrays with type safety
232+
var array = ArrayFactory.mutableArray(String.class);
233+
array.add("element1");
234+
array.add("element2");
235+
236+
// Thread-safe copy-on-write array
237+
var cowArray = ArrayFactory.copyOnModifyArray(String.class);
238+
239+
// Stamped lock based thread-safe array
240+
var lockableArray = ArrayFactory.stampedLockBasedArray(String.class);
241+
```
242+
243+
### Object Pooling
244+
245+
Reusable object pools for reducing GC pressure:
246+
247+
```java
248+
// Create a pool for reusable objects
249+
var pool = PoolFactory.newReusablePool(MyReusableObject.class);
250+
251+
// Take an object from pool (or create new if empty)
252+
var obj = pool.take();
253+
254+
// Use the object...
255+
256+
// Return to pool for reuse
257+
pool.put(obj);
258+
259+
// Thread-safe pool
260+
var lockablePool = PoolFactory.newLockBasePool(MyObject.class);
261+
```
262+
263+
### Plugin System
264+
265+
Dynamic plugin loading and management:
266+
267+
```java
268+
var pluginSystem = PluginSystemFactory.newBasePluginSystem();
269+
pluginSystem.configureAppVersion(new Version("1.0.0"));
270+
pluginSystem.configureEmbeddedPluginPath(Paths.get("plugins/"));
271+
272+
// Async plugin loading
273+
pluginSystem
274+
.preLoad(ForkJoinPool.commonPool())
275+
.thenCompose(system -> system.initialize(ForkJoinPool.commonPool()))
276+
.toCompletableFuture()
277+
.join();
278+
279+
// Access extension points
280+
var extensionPoint = pluginSystem
281+
.extensionPointManager()
282+
.getExtensionPoint(MyExtension.class);
283+
```
284+
285+
## Building
286+
287+
```bash
288+
# Full build with tests
289+
./gradlew clean build
290+
291+
# Build specific module
292+
./gradlew :rlib-common:build
293+
294+
# Run tests only
295+
./gradlew test
296+
297+
# Skip tests
298+
./gradlew clean build -x test
299+
```
300+
301+
## License
302+
303+
Please see the file called [LICENSE](LICENSE).

0 commit comments

Comments
 (0)