Skip to content

Commit

Permalink
Merge branch 'feature/tags'
Browse files Browse the repository at this point in the history
  • Loading branch information
eledhwen committed May 10, 2021
2 parents c9e0392 + b830d3d commit aeae7f0
Show file tree
Hide file tree
Showing 29 changed files with 731 additions and 90 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Add the following in your `pom.xml`:
<dependency>
<groupId>com.noleme</groupId>
<artifactId>noleme-vault</artifactId>
<version>0.13</version>
<version>0.14</version>
</dependency>
```

Expand Down Expand Up @@ -105,7 +105,8 @@ Other features that will need to be documented include:
* service aliasing
* service closing
* service container composition
* custom modules
* service tagging & aggregation
* custom and generic modules
* custom preprocessing routines

_TODO_
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.noleme</groupId>
<artifactId>noleme-vault</artifactId>
<version>0.13</version>
<version>0.14</version>
<packaging>jar</packaging>

<name>Noleme Vault</name>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/noleme/vault/builder/CellarPathStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public CellarPathStage(VaultFactory factory, List<String> paths, VaultAdjuster a
@Override
public void build(Vault vault) throws VaultException
{
Definitions definitions = new Definitions();

definitions = this.factory.parser().extractOrigin(this.paths, definitions, this.adjuster);
Definitions definitions = this.factory.parser().extractOrigin(this.paths, new Definitions(), this.adjuster);

logger.debug("Populating vault using configuration files {}", this.paths);

Expand Down
107 changes: 96 additions & 11 deletions src/main/java/com/noleme/vault/container/definition/Definitions.java
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])
Expand All @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public void syncDependencies()

this.dependencies.add(this.target);
}

@Override
public String toString()
{
return "ServiceAlias#"+this.identifier+"->"+this.target;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -35,10 +37,6 @@ public ServiceDefinition setIdentifier(String identifier)
return this;
}

/**
*
* @param invocation
*/
public ServiceDefinition addInvocation(Invocation invocation)
{
for (Object o : invocation.getParams())
Expand All @@ -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)
{
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ 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);
}
}
}

@Override
public String toString()
{
return "ServiceInstantiation#"+this.identifier+"("+this.type+")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ 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);
}
}
}

@Override
public String toString()
{
return "ServiceProvider#"+this.identifier+"("+this.type+"::"+this.method+")";
}
}
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 src/main/java/com/noleme/vault/container/definition/Tag.java
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;
}
}
Loading

0 comments on commit aeae7f0

Please sign in to comment.