Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@


class AtomDBProxy(BaseProxy):
COMMAND_SIZE_LIMIT = 50

# Proxy Commands
ADD_ATOMS = "add_atoms"
START_STREAM = "start_stream"
END_STREAM = "end_stream"

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -63,7 +67,7 @@ def flush():

return atoms

def add_atoms(self, atoms: list[Atom]) -> list[str]:
def add_atoms(self, atoms: list[Atom], use_streaming: bool = False) -> list[str]:
"""
Serialize atoms, send `ADD_ATOMS` to the remote peer, and return their handles.

Expand All @@ -79,13 +83,22 @@ def add_atoms(self, atoms: list[Atom]) -> list[str]:
"""
args = []
handles = []
stream_info = [str(len(atoms))]

if use_streaming:
self.to_remote_peer(self.START_STREAM, stream_info)

for atom in atoms:
atom_type = "NODE" if atom.arity() == 0 else "LINK"
args.append(atom_type)
atom.tokenize(args)
handles.append(atom.handle)

self.to_remote_peer(self.ADD_ATOMS, args)
if len(args) > self.COMMAND_SIZE_LIMIT or atom == atoms[-1]:
self.to_remote_peer(self.ADD_ATOMS, args)
args.clear()

if use_streaming:
self.to_remote_peer(self.END_STREAM, [])

return handles
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import concurrent.futures
import time
import uuid

from hyperon_das.commons.atoms import Link, Node
Expand Down Expand Up @@ -76,6 +77,8 @@ def test_atomdb_proxy_simple_client():

proxy.add_atoms(atoms)

time.sleep(1) # Wait a moment for the data to be committed to the database

decoder = AtomDecoder()

node_db1 = decoder.get_atom(node1.handle)
Expand Down
6 changes: 3 additions & 3 deletions 3rd_party_slots/python_client/tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from hyperon_das.logger import log

DAS_MONGODB_HOSTNAME = "0.0.0.0"
DAS_MONGODB_PORT = 28000
DAS_MONGODB_USERNAME = "dbadmin"
DAS_MONGODB_PASSWORD = "dassecret"
DAS_MONGODB_PORT = 40021
DAS_MONGODB_USERNAME = "admin"
DAS_MONGODB_PASSWORD = "admin"


class AtomDecoder(HandleDecoder):
Expand Down