-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CAP] Added a factory for runtime (#3216)
* Added Runtime Factory to support multiple implementations * Rename to ComponentEnsemble to ZMQRuntime * rename zmq_runtime * rename zmq_runtime * pre-commit fixes * pre-commit fix * pre-commit fixes and default runtime * pre-commit fixes * Rename constants * Rename Constants --------- Co-authored-by: Li Jiang <[email protected]>
- Loading branch information
1 parent
a246a79
commit 466c851
Showing
20 changed files
with
130 additions
and
42 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List | ||
|
||
from .Actor import Actor | ||
from .ActorConnector import ActorConnector | ||
from .proto.CAP_pb2 import ActorInfo | ||
|
||
|
||
class IRuntime(ABC): | ||
@abstractmethod | ||
def register(self, actor: Actor): | ||
pass | ||
|
||
@abstractmethod | ||
def connect(self): | ||
pass | ||
|
||
@abstractmethod | ||
def disconnect(self): | ||
pass | ||
|
||
@abstractmethod | ||
def find_by_topic(self, topic: str) -> ActorConnector: | ||
pass | ||
|
||
@abstractmethod | ||
def find_by_name(self, name: str) -> ActorConnector: | ||
pass | ||
|
||
@abstractmethod | ||
def find_termination(self) -> ActorConnector: | ||
pass | ||
|
||
@abstractmethod | ||
def find_by_name_regex(self, name_regex) -> List[ActorInfo]: | ||
pass |
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
samples/apps/cap/py/autogencap/Constants.py → samples/apps/cap/py/autogencap/constants.py
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,2 +1,3 @@ | ||
Termination_Topic: str = "Termination" | ||
Directory_Svc_Topic: str = "Directory_Svc" | ||
ZMQ_Runtime: str = "ZMQ" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from autogencap.actor_runtime import IRuntime | ||
from autogencap.constants import ZMQ_Runtime | ||
from autogencap.DebugLog import Error | ||
from autogencap.zmq_runtime import ZMQRuntime | ||
|
||
|
||
class RuntimeFactory: | ||
_supported_runtimes = {} | ||
|
||
""" | ||
Factory class for creating a runtime instance. | ||
""" | ||
|
||
@staticmethod | ||
def get_runtime(runtime_type: str = ZMQ_Runtime) -> IRuntime: | ||
""" | ||
Creates a runtime instance based on the runtime type. | ||
:param runtime_type: The type of runtime to create. | ||
:return: The runtime instance. | ||
""" | ||
if runtime_type in RuntimeFactory._supported_runtimes: | ||
return RuntimeFactory._supported_runtimes[runtime_type] | ||
else: | ||
not_found = f"Runtime type not found: {runtime_type}" | ||
Error("RuntimeFactory", not_found) | ||
raise ValueError(not_found) | ||
|
||
@staticmethod | ||
def register_runtime(runtime_type: str, runtime: IRuntime): | ||
""" | ||
Registers a runtime instance. | ||
:param runtime: The runtime instance. | ||
""" | ||
RuntimeFactory._supported_runtimes[runtime_type] = runtime | ||
|
||
@classmethod | ||
def _initialize(cls): | ||
""" | ||
Static initialization method. | ||
""" | ||
cls.register_runtime(ZMQ_Runtime, ZMQRuntime()) | ||
|
||
|
||
# Static initialization | ||
RuntimeFactory._initialize() |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.