-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
731 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package com.noleme.vault.container.definition; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.*; | ||
|
||
/** | ||
* @author Pierre Lecerf ([email protected]) | ||
|
@@ -11,30 +9,48 @@ | |
public class Definitions | ||
{ | ||
private final Variables variables; | ||
private final Services definitions; | ||
private final Services services; | ||
private final Tags tags; | ||
|
||
public Definitions() | ||
{ | ||
this.variables = new Variables(); | ||
this.definitions = new Services(); | ||
this.services = new Services(); | ||
this.tags = new Tags(); | ||
} | ||
|
||
@Deprecated public Variables getVariables() { return this.variables(); } | ||
@Deprecated public Services getDefinitions() { return this.services(); } | ||
|
||
/** | ||
* Returns a container indexing variables by their identifiers. | ||
* | ||
* @return | ||
* @return the Variables container | ||
*/ | ||
public Variables getVariables() | ||
public Variables variables() | ||
{ | ||
return this.variables; | ||
} | ||
|
||
/** | ||
* Returns a container indexing services by their identifiers. | ||
* | ||
* @return the Services container | ||
*/ | ||
public Services services() | ||
{ | ||
return this.services; | ||
} | ||
|
||
/** | ||
* Returns a container indexing tags by their identifiers. | ||
* This can be used in a VaultModule for performing operations over tagged services. | ||
* | ||
* @return | ||
* @return the Tags container | ||
*/ | ||
public Services getDefinitions() | ||
public Tags tags() | ||
{ | ||
return this.definitions; | ||
return this.tags; | ||
} | ||
|
||
public static class Variables extends Dictionary<Object> | ||
|
@@ -67,6 +83,75 @@ public Services remove(String name) | |
} | ||
} | ||
|
||
public static class Tags | ||
{ | ||
private final Map<String, Set<Tag>> tagsByIdentifier; | ||
private final Map<String, Set<Tag>> tagsByService; | ||
|
||
public Tags() | ||
{ | ||
this.tagsByIdentifier = new HashMap<>(); | ||
this.tagsByService = new HashMap<>(); | ||
} | ||
|
||
public Set<String> identifiers() | ||
{ | ||
return this.tagsByIdentifier.keySet(); | ||
} | ||
|
||
public Set<String> taggedServices() | ||
{ | ||
return this.tagsByService.keySet(); | ||
} | ||
|
||
public Set<Tag> forIdentifier(String identifier) | ||
{ | ||
return this.tagsByIdentifier.get(identifier); | ||
} | ||
|
||
public Set<Tag> forService(String service) | ||
{ | ||
return this.tagsByService.get(service); | ||
} | ||
|
||
/** | ||
* Removes all tags associated with a service, and makes sure the are properly un-indexed. | ||
* | ||
* @param identifier A service identifier | ||
* @return the Tags container | ||
*/ | ||
public Tags clearTagsForService(String identifier) | ||
{ | ||
if (!this.tagsByService.containsKey(identifier)) | ||
return this; | ||
|
||
for (Tag tag : this.tagsByService.get(identifier)) | ||
this.tagsByIdentifier.get(tag.getIdentifier()).remove(tag); | ||
this.tagsByService.remove(identifier); | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Registers a tag onto a service and indexes it by its tag identifier. | ||
* | ||
* @param tag A tag to be registered | ||
* @return the Tags container | ||
*/ | ||
public Tags register(Tag tag) | ||
{ | ||
if (!this.tagsByIdentifier.containsKey(tag.getIdentifier())) | ||
this.tagsByIdentifier.put(tag.getIdentifier(), new HashSet<>()); | ||
if (!this.tagsByService.containsKey(tag.getService())) | ||
this.tagsByService.put(tag.getService(), new HashSet<>()); | ||
|
||
this.tagsByIdentifier.get(tag.getIdentifier()).add(tag); | ||
this.tagsByService.get(tag.getService()).add(tag); | ||
|
||
return this; | ||
} | ||
} | ||
|
||
private static abstract class Dictionary <T> | ||
{ | ||
private final Map<String, T> dictionary; | ||
|
@@ -81,7 +166,7 @@ public boolean has(String name) | |
return this.dictionary.containsKey(name); | ||
} | ||
|
||
public Object get(String name) | ||
public T get(String name) | ||
{ | ||
return this.dictionary.get(name); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
import com.noleme.vault.container.Invocation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Pierre Lecerf ([email protected]) on 21/08/2015. | ||
|
@@ -12,14 +14,14 @@ public abstract class ServiceDefinition | |
{ | ||
protected String identifier; | ||
protected List<Invocation> invocations = new ArrayList<>(); | ||
protected List<String> dependencies = new ArrayList<>(); | ||
protected Set<String> dependencies = new HashSet<>(); | ||
|
||
public String getIdentifier() | ||
{ | ||
return this.identifier; | ||
} | ||
|
||
public List<String> getDependencies() | ||
public Set<String> getDependencies() | ||
{ | ||
return this.dependencies; | ||
} | ||
|
@@ -35,10 +37,6 @@ public ServiceDefinition setIdentifier(String identifier) | |
return this; | ||
} | ||
|
||
/** | ||
* | ||
* @param invocation | ||
*/ | ||
public ServiceDefinition addInvocation(Invocation invocation) | ||
{ | ||
for (Object o : invocation.getParams()) | ||
|
@@ -55,7 +53,7 @@ public ServiceDefinition addInvocation(Invocation invocation) | |
*/ | ||
public void syncDependencies() | ||
{ | ||
this.dependencies = new ArrayList<>(); | ||
this.dependencies = new HashSet<>(); | ||
|
||
for (Invocation invocation : this.invocations) | ||
{ | ||
|
@@ -64,8 +62,7 @@ public void syncDependencies() | |
if (o instanceof String && !((String)o).isEmpty() && ((String)o).startsWith("@")) | ||
{ | ||
String dep = ((String)o).substring(1); | ||
if (!this.dependencies.contains(dep)) | ||
this.dependencies.add(dep); | ||
this.dependencies.add(dep); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/noleme/vault/container/definition/ServiceTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.noleme.vault.container.definition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Pierre LECERF ([email protected]) | ||
* Created on 09/05/2021 | ||
*/ | ||
public class ServiceTag extends ServiceDefinition | ||
{ | ||
private final List<String> entries; | ||
|
||
public ServiceTag(String identifier) | ||
{ | ||
this.identifier = identifier; | ||
this.entries = new ArrayList<>(); | ||
} | ||
|
||
public List<String> getEntries() | ||
{ | ||
return this.entries; | ||
} | ||
|
||
public ServiceTag addEntry(String identifier) | ||
{ | ||
this.entries.add(identifier); | ||
this.dependencies.add(identifier); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void syncDependencies() | ||
{ | ||
super.syncDependencies(); | ||
|
||
this.dependencies.addAll(this.entries); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "ServiceTag#"+this.identifier+"("+this.entries.size()+")"; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/noleme/vault/container/definition/Tag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.noleme.vault.container.definition; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
/** | ||
* @author Pierre LECERF ([email protected]) | ||
* Created on 08/05/2021 | ||
*/ | ||
public class Tag | ||
{ | ||
private final String identifier; | ||
private final String service; | ||
private final ObjectNode node; | ||
|
||
public Tag(String identifier, String service, ObjectNode node) | ||
{ | ||
this.identifier = identifier; | ||
this.service = service; | ||
this.node = node; | ||
} | ||
|
||
public String getIdentifier() | ||
{ | ||
return this.identifier; | ||
} | ||
|
||
public String getService() | ||
{ | ||
return this.service; | ||
} | ||
|
||
public ObjectNode getNode() | ||
{ | ||
return this.node; | ||
} | ||
} |
Oops, something went wrong.