-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
containers comments and FIXME in ShadowKnowledgeManagerRegistry
- Loading branch information
1 parent
e5fe5a2
commit c4a245f
Showing
7 changed files
with
300 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="test"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="test"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
186 changes: 96 additions & 90 deletions
186
jdeeco-core/src/cz/cuni/mff/d3s/deeco/knowledge/CloningKnowledgeManagerContainer.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 |
---|---|---|
@@ -1,90 +1,96 @@ | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public class CloningKnowledgeManagerContainer implements | ||
ReplicaKnowledgeManagerContainer, LocalKnowledgeManagerContainer { | ||
|
||
protected final List<KnowledgeManager> locals; | ||
protected final List<KnowledgeManager> replicas; | ||
protected final List<LocalListener> localListeners; | ||
protected final List<ReplicaListener> replicaListeners; | ||
|
||
public CloningKnowledgeManagerContainer() { | ||
this.locals = new LinkedList<>(); | ||
this.replicas = new LinkedList<>(); | ||
this.localListeners = new LinkedList<>(); | ||
this.replicaListeners = new LinkedList<>(); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager createLocal(String id) { | ||
KnowledgeManager result = new CloningKnowledgeManager(id); | ||
locals.add(result); | ||
for (LocalListener listener : localListeners) | ||
listener.localCreated(result, this); | ||
return result; | ||
} | ||
|
||
@Override | ||
public KnowledgeManager removeLocal(KnowledgeManager km) { | ||
if (locals.contains(km)) { | ||
locals.remove(km); | ||
for (LocalListener listener : localListeners) | ||
listener.localRemoved(km, this); | ||
return km; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<KnowledgeManager> getLocals() { | ||
return locals; | ||
} | ||
|
||
@Override | ||
public void registerLocalListener(LocalListener listener) { | ||
if (!localListeners.contains(listener)) | ||
localListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager removeReplica(KnowledgeManager km) { | ||
if (replicas.contains(km)) { | ||
replicas.remove(km); | ||
for (ReplicaListener listener : replicaListeners) | ||
listener.replicaRemoved(km, this); | ||
return km; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<KnowledgeManager> getReplicas() { | ||
return replicas; | ||
} | ||
|
||
@Override | ||
public void registerReplicaListener(ReplicaListener listener) { | ||
if (!replicaListeners.contains(listener)) | ||
replicaListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager createReplica(String id) { | ||
KnowledgeManager result = new CloningKnowledgeManager(id); | ||
if (!(locals.contains(result) || replicas.contains(result))) { | ||
replicas.add(result); | ||
for (ReplicaListener listener : replicaListeners) | ||
listener.replicaCreated(result, this); | ||
return result; | ||
} else | ||
return null; | ||
} | ||
|
||
} | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* This container allows to deal with both local and replica knowledge managers by implementing both interfaces of {@link LocalKnowledgeManagerContainer} | ||
* and {@link ReplicaKnowledgeManagerContainer}. | ||
* It acts as a factory for locals and replicas and gives the ability to register a local listener and a replica listener for the knowledge manager. Also, | ||
* it retrieves the available locals and replicas in a container. | ||
* | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public class CloningKnowledgeManagerContainer implements | ||
ReplicaKnowledgeManagerContainer, LocalKnowledgeManagerContainer { | ||
|
||
protected final List<KnowledgeManager> locals; | ||
protected final List<KnowledgeManager> replicas; | ||
protected final List<LocalListener> localListeners; | ||
protected final List<ReplicaListener> replicaListeners; | ||
|
||
public CloningKnowledgeManagerContainer() { | ||
this.locals = new LinkedList<>(); | ||
this.replicas = new LinkedList<>(); | ||
this.localListeners = new LinkedList<>(); | ||
this.replicaListeners = new LinkedList<>(); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager createLocal(String id) { | ||
KnowledgeManager result = new CloningKnowledgeManager(id); | ||
locals.add(result); | ||
for (LocalListener listener : localListeners) | ||
listener.localCreated(result, this); | ||
return result; | ||
} | ||
|
||
@Override | ||
public KnowledgeManager removeLocal(KnowledgeManager km) { | ||
if (locals.contains(km)) { | ||
locals.remove(km); | ||
for (LocalListener listener : localListeners) | ||
listener.localRemoved(km, this); | ||
return km; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<KnowledgeManager> getLocals() { | ||
return locals; | ||
} | ||
|
||
@Override | ||
public void registerLocalListener(LocalListener listener) { | ||
if (!localListeners.contains(listener)) | ||
localListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager removeReplica(KnowledgeManager km) { | ||
if (replicas.contains(km)) { | ||
replicas.remove(km); | ||
for (ReplicaListener listener : replicaListeners) | ||
listener.replicaRemoved(km, this); | ||
return km; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<KnowledgeManager> getReplicas() { | ||
return replicas; | ||
} | ||
|
||
@Override | ||
public void registerReplicaListener(ReplicaListener listener) { | ||
if (!replicaListeners.contains(listener)) | ||
replicaListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public KnowledgeManager createReplica(String id) { | ||
KnowledgeManager result = new CloningKnowledgeManager(id); | ||
if (!(locals.contains(result) || replicas.contains(result))) { | ||
replicas.add(result); | ||
for (ReplicaListener listener : replicaListeners) | ||
listener.replicaCreated(result, this); | ||
return result; | ||
} else | ||
return null; | ||
} | ||
|
||
} |
62 changes: 48 additions & 14 deletions
62
jdeeco-core/src/cz/cuni/mff/d3s/deeco/knowledge/LocalKnowledgeManagerContainer.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 |
---|---|---|
@@ -1,14 +1,48 @@ | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public interface LocalKnowledgeManagerContainer { | ||
public KnowledgeManager createLocal(String id); | ||
public KnowledgeManager removeLocal(KnowledgeManager km); | ||
public List<KnowledgeManager> getLocals(); | ||
public void registerLocalListener(LocalListener listener); | ||
} | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* Allows adding/removing local knowledge manager to a container with ability to register a listener for each new local knowledge manager. Also, it allows to | ||
* return all the available local knowledge managers in the container. | ||
* | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public interface LocalKnowledgeManagerContainer { | ||
|
||
/** | ||
* A factory for a local knowledge manager. | ||
* | ||
* @param String | ||
* @return {@link KnowledgeManager} | ||
* object containing values for the specified knowledge paths. | ||
*/ | ||
public KnowledgeManager createLocal(String id); | ||
|
||
/** | ||
* Removes a local knowledge manager from the container and return it. | ||
* | ||
* @param {@link KnowledgeManager} | ||
* @return {@link KnowledgeManager} | ||
* object containing values for the specified knowledge paths | ||
*/ | ||
public KnowledgeManager removeLocal(KnowledgeManager km); | ||
|
||
/** | ||
* Retrieves all local knowledge managers in the container. | ||
* | ||
* @return List<{@link KnowledgeManager}> | ||
* object containing values for the specified knowledge paths | ||
*/ | ||
public List<KnowledgeManager> getLocals(); | ||
|
||
/** | ||
* Retrieves values for the collection of the {@link KnowledgePath} objects. | ||
* | ||
* @param {@link ReplicaListener} | ||
* listens for adding replicas to the container or removing them from it. | ||
*/ | ||
public void registerLocalListener(LocalListener listener); | ||
} |
42 changes: 32 additions & 10 deletions
42
jdeeco-core/src/cz/cuni/mff/d3s/deeco/knowledge/LocalListener.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 |
---|---|---|
@@ -1,10 +1,32 @@ | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
/** | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public interface LocalListener { | ||
public void localCreated(KnowledgeManager km, LocalKnowledgeManagerContainer container); | ||
public void localRemoved(KnowledgeManager km, LocalKnowledgeManagerContainer container); | ||
} | ||
package cz.cuni.mff.d3s.deeco.knowledge; | ||
|
||
/** | ||
* | ||
* Gets called by a {@link ShadowKnowledgeManagerRegistry} when an event on a {@link LocalKnowledgeManagerContainer} (i.e. adding/removing local knowledge manager) | ||
* matches the registered trigger. | ||
* | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public interface LocalListener { | ||
|
||
/** | ||
* Gets the event of creating a new local knowledge manager in the local knowledge manager container. | ||
* | ||
* @param {@link KnowledgeManager} | ||
* manages the knowledge | ||
* @param {@link LocalKnowledgeManagerContainer} | ||
* accesses local knowledge managers | ||
*/ | ||
public void localCreated(KnowledgeManager km, LocalKnowledgeManagerContainer container); | ||
|
||
/** | ||
* Gets the event of removing a new local knowledge manager in the local knowledge manager container. | ||
* | ||
* @param {@link KnowledgeManager} | ||
* manages the knowledge | ||
* @param {@link LocalKnowledgeManagerContainer} | ||
* accesses local knowledge managers | ||
*/ | ||
public void localRemoved(KnowledgeManager km, LocalKnowledgeManagerContainer container); | ||
} |
Oops, something went wrong.