{
33 |
34 | /**
35 | * Generates a unique identity for InMemory repository Node insertion
36 | *
37 | * @return ID - newly generated unique identity
38 | */
39 | ID generateIdentity();
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/pl/exsio/nestedj/config/mem/lock/InMemoryLock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2019 eXsio.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9 | * permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
11 | * the Software.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 | * SOFTWARE.
19 | */
20 |
21 | package pl.exsio.nestedj.config.mem.lock;
22 |
23 | import pl.exsio.nestedj.NestedNodeRepository;
24 | import pl.exsio.nestedj.model.NestedNode;
25 |
26 | import java.io.Serializable;
27 | import java.util.Collections;
28 | import java.util.HashSet;
29 | import java.util.Set;
30 | import java.util.concurrent.atomic.AtomicBoolean;
31 | import java.util.function.Function;
32 |
33 | /**
34 | * In Memory Lock - stores a Set of Lock Handles to determine whether a Node can be modified or not.
35 | * It is up to the user to provide the Lock Handle Object taht fits the needs. The Handle should have a proper
36 | * equals() and hashCode() to be correctly stored and removed in/from Set.
37 | *
38 | * Additionally the Lock check whether the whole Repository is locked or not. Locked repository takes precedence before
39 | * locking single Node.
40 | *
41 | * @param - Nested Node Identifier Class
42 | * @param - Nested Node Class
43 | */
44 | public class InMemoryLock> implements NestedNodeRepository.Lock {
45 |
46 | private final AtomicBoolean repositoryLocked = new AtomicBoolean(false);
47 |
48 | private final Set