Initial commit of data store for API2 experiments
This commit is contained in:
parent
2f7c337b02
commit
3ba2b685b6
1 changed files with 49 additions and 0 deletions
49
daemon/core/experiments.py
Normal file
49
daemon/core/experiments.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2016 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
# author: Rod Santiago
|
||||
#
|
||||
|
||||
|
||||
from core.api import core_pb2
|
||||
from multiprocessing import Lock
|
||||
|
||||
|
||||
|
||||
|
||||
class ExperimentStore(object):
|
||||
__lastid = 0
|
||||
__experiments = {}
|
||||
__lock = Lock()
|
||||
|
||||
@staticmethod
|
||||
def addExperiment(exp):
|
||||
with ExperimentStore.__lock:
|
||||
id = str(ExperimentStore.__lastid)
|
||||
ExperimentStore.__lastid += 1
|
||||
exp.experimentId = id
|
||||
if not id in ExperimentStore.__experiments:
|
||||
ExperimentStore.__experiments[id] = exp
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
@staticmethod
|
||||
def delExperiment(exp):
|
||||
if not exp.HasField("experimentId"):
|
||||
print 'Experiment ID is needed but not supplied'
|
||||
return False
|
||||
id = exp.experimentId
|
||||
with ExperimentStore.__lock:
|
||||
if id in ExperimentStore.__experiments:
|
||||
del ExperimentStore.__experiments[id]
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue