-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve HTTP and ZeroMQ adapters (#137)
Closes #111 and #15 Changes: * Add synchronised start/stop mechanism to HTTP adapter * Write suite of tests using this mechanism * Make HTTP adapter support interrupts (it did not appear to already) * Remove `include_json` parameter from HTTP endpoints as `aiohttp` can work that out for itself * Create new ZeroMQ adapter specifically for pushing. The previous one had issues and also implemented more functionality than was needed. Multiple ZMQ adapters for the different ZMQ socket modes (PUSH, PUBLISH, DEALER etc.) seems like a better way to go. * Synchronize ZeroMQ socket binding with a lock to avoid conflicts * Write suite of tests for ZeroMQ push adapter
- Loading branch information
1 parent
94297cb
commit 565beff
Showing
16 changed files
with
697 additions
and
396 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,7 @@ | ||
- examples.devices.http_device.ExampleHttpDevice: | ||
name: http-device | ||
inputs: {} | ||
- examples.devices.zeromq_push_device.ExampleZeroMqPusher: | ||
name: zeromq-pusher | ||
inputs: | ||
updates: http-device:updates |
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,3 @@ | ||
- tickit.devices.source.Source: | ||
name: source | ||
inputs: {} | ||
value: False | ||
- examples.devices.http_device.ExampleHTTP: | ||
- examples.devices.http_device.ExampleHttpDevice: | ||
name: http-device | ||
inputs: | ||
foo: source:value | ||
foo: False | ||
bar: 10 | ||
inputs: {} |
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,49 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Optional, Set | ||
|
||
from tickit.adapters.zeromq.push_adapter import ( | ||
SocketFactory, | ||
ZeroMqPushAdapter, | ||
create_zmq_push_socket, | ||
) | ||
from tickit.core.components.component import Component, ComponentConfig | ||
from tickit.core.components.device_simulation import DeviceSimulation | ||
from tickit.devices.iobox import IoBoxDevice | ||
|
||
|
||
class IoBoxZeroMqAdapter(ZeroMqPushAdapter): | ||
"""An Eiger adapter which parses the commands sent to the HTTP server.""" | ||
|
||
device: IoBoxDevice[str, int] | ||
_addresses_to_publish: Set[str] | ||
|
||
def __init__( | ||
self, | ||
host: str = "127.0.0.1", | ||
port: int = 5555, | ||
socket_factory: Optional[SocketFactory] = create_zmq_push_socket, | ||
addresses_to_publish: Optional[Set[str]] = None, | ||
) -> None: | ||
super().__init__(host, port, socket_factory) | ||
self._addresses_to_publish = addresses_to_publish or set() | ||
|
||
def after_update(self): | ||
for address in self._addresses_to_publish: | ||
value = self.device.read(address) | ||
self.send_message([{address: value}]) | ||
|
||
|
||
@dataclass | ||
class ExampleZeroMqPusher(ComponentConfig): | ||
"""Device that can publish writes to its memory over a zeromq socket.""" | ||
|
||
host: str = "127.0.0.1" | ||
port: int = 5555 | ||
addresses_to_publish: Set[str] = field(default_factory=lambda: {"foo", "bar"}) | ||
|
||
def __call__(self) -> Component: # noqa: D102 | ||
return DeviceSimulation( | ||
name=self.name, | ||
device=IoBoxDevice(), | ||
adapters=[IoBoxZeroMqAdapter()], | ||
) |
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.