@@ -23,6 +23,7 @@ import scala.io.Source
23
23
class DynamicInstanceDAO (configuration : Configuration ) extends InstanceDAO with AppLogging with JsonSupport {
24
24
25
25
private val instances : mutable.Set [Instance ] = new mutable.HashSet [Instance ]()
26
+ private val instanceMatchingResults : mutable.Map [Long , mutable.MutableList [Boolean ]] = new mutable.HashMap [Long ,mutable.MutableList [Boolean ]]()
26
27
27
28
implicit val system : ActorSystem = Server .system
28
29
implicit val materializer : ActorMaterializer = ActorMaterializer ()
@@ -39,6 +40,7 @@ class DynamicInstanceDAO (configuration : Configuration) extends InstanceDAO wit
39
40
// Verify id is not already present in instances!
40
41
if (! hasInstance(instance.id.get)){
41
42
instances.add(instance)
43
+ instanceMatchingResults.put(instance.id.get, mutable.MutableList ())
42
44
dumpToRecoveryFile()
43
45
Success (log.info(s " Added instance ${instance.name} with id ${instance.id} to database. " ))
44
46
} else {
@@ -59,6 +61,7 @@ class DynamicInstanceDAO (configuration : Configuration) extends InstanceDAO wit
59
61
if (hasInstance(id)){
60
62
// AddInstance verifies that id is always present, hasInstance verifies that find will return an instance
61
63
instances.remove(instances.find(i => i.id.get == id).get)
64
+ instanceMatchingResults.remove(id)
62
65
dumpToRecoveryFile()
63
66
Success (log.info(s " Successfully removed instance with id $id. " ))
64
67
} else {
@@ -88,11 +91,38 @@ class DynamicInstanceDAO (configuration : Configuration) extends InstanceDAO wit
88
91
89
92
override def removeAll () : Unit = {
90
93
instances.clear()
94
+ instanceMatchingResults.clear()
91
95
dumpToRecoveryFile()
92
96
}
93
97
98
+ override def addMatchingResult (id : Long , matchingSuccessful : Boolean ): Try [Unit ] = {
99
+ if (hasInstance(id)){
100
+ instanceMatchingResults.get(id) match {
101
+ case Some (resultList) =>
102
+ resultList += matchingSuccessful
103
+ Success (log.info(s " Successfully added matching result $matchingSuccessful to instance with id $id. " ))
104
+ case None =>
105
+ log.warning(s " Could not add matching result, list for instance with id $id not present! " )
106
+ Failure (new RuntimeException (" No matching result list present" ))
107
+ }
108
+ } else {
109
+ log.warning(s " Cannot add matching result, instance with id $id not present. " )
110
+ Failure (new RuntimeException (s " Cannot add matching result, instance with id $id not present. " ))
111
+ }
112
+ }
113
+
114
+ override def getMatchingResultsFor (id : Long ): Try [List [Boolean ]] = {
115
+ if (hasInstance(id) && instanceMatchingResults.contains(id)){
116
+ Success (List () ++ instanceMatchingResults(id))
117
+ } else {
118
+ log.warning(s " Cannot get matching results, id $id not present! " )
119
+ Failure (new RuntimeException (s " Cannot get matching results, id $id not present! " ))
120
+ }
121
+ }
122
+
94
123
private [daos] def clearData () : Unit = {
95
124
instances.clear()
125
+ instanceMatchingResults.clear()
96
126
}
97
127
98
128
private [daos] def dumpToRecoveryFile () : Unit = {
0 commit comments