-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation.txt
37 lines (26 loc) · 1.99 KB
/
documentation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1. Assignment analysis
The task is to develop the solution to automatically reload prop set on file change.
Prop file monitoring is done by FileWatcher.java class which utilizes apache.commons.io.monitor
library capabilities.
Arguably, Java WatchService API would be a better choice, but it's not available for Java 1.5
The main challenge is to have thread safe solution without performance penalties on getConfig method.
This is done by implementing "swap" pattern - while new property set is not ready,
existing set is used for serving getConfig requests.
Only when new set is complete it replaces the old one.
Set of properties is represented by SimpleConfigurator class, which is functionally equal to "old", non-reloadable solution.
So, in reality old code can be re-used.
Configurator interface defines client-facing functionality, making replacement of "old" configurator transparent for the rest of the system.
Finally, the AutoReloadConfigurator.java represents complete solution. It's
aggregates FileWatcher and swappable SimpleConfigurator. SimpleConfigurator is wrapped by
AtomicReference - lock-free, thread-safe mechanism for swapping.
Each class is covered by TestNG unit test. Tests verifies just the basic functionality, not corner cases or error conditions.
2. Assumptions
2.1 Singleton pattern and life cycle of AutoReloadConfigurator is done by Tomcat and not part of this solution.
2.2 Individual properties are independent from client perspective . Scenario: client calls getConfig 2 times to get prop1 and prop2.
in case when update happened in between those calls, prop1 and prop2 values will be inconsistent to each other.
In order to get consistent set of properties new "batch" method should be implemented:
Map<String,String> getConfig (Set<String> keys)
2.3 Error handling is done by client, configurator just throws exceptions
3. Execution instructions
Assignment is done as a Maven project, in order to compile and execute unit tests run following command:
"mvn install" from project root folder.