Description
This is a Java-based client–server application for storing, retrieving and modifying JSON data. It supports various JSON types (including objects, arrays, numbers and strings) and allows nested key access using keys provided as JSON arrays.
Features
- File-Based Persistence: A file-based database is used to store the JSON data, ensuring data preservation across server restarts.
- Concurrent Request Handling:
ExecutorService
is used to process multiple client requests concurrently. - Thread-Safe File Access: The
ReentrantReadWriteLock
implementation ofReadWriteLock
is used to manage controlled read/write access to the database file. - Dynamic JSON Storage: Various JSON types are supported, allowing storage and modification of complex nested data.
- Nested Key Access: Keys specified as JSON arrays are used to perform operations on nested JSON values.
- Selective Deletion: Specific nested keys can be removed without affecting parent objects.
Examples
-
Set a Simple Key-Value Pair:
java Main -t set -k message -v "Hello World!"
Sent:
{"type":"set","key":"message","value":"Hello World!"}
Received:{"response":"OK"}
-
Set a Nested JSON Object:
java Main -in setFile.json
Sent:
{ "type": "set", "key": "user", "value": { "name": "Jane Doe", "contact": { "email": "jane.doe@example.com", "phone": "555-1234" }, "preferences": { "language": "Java", "editor": "IntelliJ IDEA" } } }
Received:
{"response":"OK"}
-
Retrieve a Nested Value:
java Main -in getFile.json
Sent:
{"type":"get","key":["user","name"]}
Received:{"response":"OK","value":"Jane Doe"}
-
Update a Nested Value:
java Main -in updateFile.json
Sent:
{"type":"set","key":["user","contact","phone"],"value":"555-4321"}
Received:{"response":"OK"}
-
Delete a Nested Value:
java Main -in deleteFile.json
Sent:
{"type":"delete","key":["user","preferences","editor"]}
Received:{"response":"OK"}
-
Exit the Application:
java Main -t exit
Sent:
{"type":"exit"}
Received:{"response":"OK"}