Use small helper routine to fetch atom metadata entries
Change-Id: Ibcffbdd9f499e91f2a4218133271cb10d16078a8
This commit is contained in:
committed by
Thomas Goirand
parent
e91fbaebb1
commit
4083de96fd
@@ -171,13 +171,16 @@ class Runtime(object):
|
|||||||
self._atom_notifier,
|
self._atom_notifier,
|
||||||
self._task_executor)
|
self._task_executor)
|
||||||
|
|
||||||
|
def _fetch_atom_metadata_entry(self, atom_name, metadata_key):
|
||||||
|
return self._atom_cache[atom_name][metadata_key]
|
||||||
|
|
||||||
def check_atom_transition(self, atom, current_state, target_state):
|
def check_atom_transition(self, atom, current_state, target_state):
|
||||||
"""Checks if the atom can transition to the provided target state."""
|
"""Checks if the atom can transition to the provided target state."""
|
||||||
# This does not check if the name exists (since this is only used
|
# This does not check if the name exists (since this is only used
|
||||||
# internally to the engine, and is not exposed to atoms that will
|
# internally to the engine, and is not exposed to atoms that will
|
||||||
# not exist and therefore doesn't need to handle that case).
|
# not exist and therefore doesn't need to handle that case).
|
||||||
metadata = self._atom_cache[atom.name]
|
check_transition_handler = self._fetch_atom_metadata_entry(
|
||||||
check_transition_handler = metadata['check_transition_handler']
|
atom.name, 'check_transition_handler')
|
||||||
return check_transition_handler(current_state, target_state)
|
return check_transition_handler(current_state, target_state)
|
||||||
|
|
||||||
def fetch_edge_deciders(self, atom):
|
def fetch_edge_deciders(self, atom):
|
||||||
@@ -185,21 +188,19 @@ class Runtime(object):
|
|||||||
# This does not check if the name exists (since this is only used
|
# This does not check if the name exists (since this is only used
|
||||||
# internally to the engine, and is not exposed to atoms that will
|
# internally to the engine, and is not exposed to atoms that will
|
||||||
# not exist and therefore doesn't need to handle that case).
|
# not exist and therefore doesn't need to handle that case).
|
||||||
metadata = self._atom_cache[atom.name]
|
return self._fetch_atom_metadata_entry(atom.name, 'edge_deciders')
|
||||||
return metadata['edge_deciders']
|
|
||||||
|
|
||||||
def fetch_scheduler(self, atom):
|
def fetch_scheduler(self, atom):
|
||||||
"""Fetches the cached specific scheduler for the given atom."""
|
"""Fetches the cached specific scheduler for the given atom."""
|
||||||
# This does not check if the name exists (since this is only used
|
# This does not check if the name exists (since this is only used
|
||||||
# internally to the engine, and is not exposed to atoms that will
|
# internally to the engine, and is not exposed to atoms that will
|
||||||
# not exist and therefore doesn't need to handle that case).
|
# not exist and therefore doesn't need to handle that case).
|
||||||
metadata = self._atom_cache[atom.name]
|
return self._fetch_atom_metadata_entry(atom.name, 'scheduler')
|
||||||
return metadata['scheduler']
|
|
||||||
|
|
||||||
def fetch_scopes_for(self, atom_name):
|
def fetch_scopes_for(self, atom_name):
|
||||||
"""Fetches a walker of the visible scopes for the given atom."""
|
"""Fetches a walker of the visible scopes for the given atom."""
|
||||||
try:
|
try:
|
||||||
metadata = self._atom_cache[atom_name]
|
return self._fetch_atom_metadata_entry(atom_name, 'scope_walker')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# This signals to the caller that there is no walker for whatever
|
# This signals to the caller that there is no walker for whatever
|
||||||
# atom name was given that doesn't really have any associated atom
|
# atom name was given that doesn't really have any associated atom
|
||||||
@@ -208,8 +209,6 @@ class Runtime(object):
|
|||||||
# atom and users can provide random names that do not actually
|
# atom and users can provide random names that do not actually
|
||||||
# exist...
|
# exist...
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
return metadata['scope_walker']
|
|
||||||
|
|
||||||
# Various helper methods used by the runtime components; not for public
|
# Various helper methods used by the runtime components; not for public
|
||||||
# consumption...
|
# consumption...
|
||||||
@@ -218,11 +217,11 @@ class Runtime(object):
|
|||||||
"""Resets all the provided atoms to the given state and intention."""
|
"""Resets all the provided atoms to the given state and intention."""
|
||||||
tweaked = []
|
tweaked = []
|
||||||
for atom in atoms:
|
for atom in atoms:
|
||||||
metadata = self._atom_cache[atom.name]
|
|
||||||
if state or intention:
|
if state or intention:
|
||||||
tweaked.append((atom, state, intention))
|
tweaked.append((atom, state, intention))
|
||||||
if state:
|
if state:
|
||||||
change_state_handler = metadata['change_state_handler']
|
change_state_handler = self._fetch_atom_metadata_entry(
|
||||||
|
atom.name, 'change_state_handler')
|
||||||
change_state_handler(atom, state)
|
change_state_handler(atom, state)
|
||||||
if intention:
|
if intention:
|
||||||
self.storage.set_atom_intention(atom.name, intention)
|
self.storage.set_atom_intention(atom.name, intention)
|
||||||
|
|||||||
Reference in New Issue
Block a user