Package io.agentscope.harness.agent.bus
Class WorkspaceMessageBus
java.lang.Object
io.agentscope.harness.agent.bus.WorkspaceMessageBus
- All Implemented Interfaces:
MessageBus,AutoCloseable
MessageBus implementation backed by AbstractFilesystem.
Works with any filesystem backend (local, remote, sandbox). Suitable for cross-process scenarios where multiple JVMs share the same workspace directory.
Mode D (pub/sub) is degraded to polling: subscribe(java.lang.String) returns a Flux that emits
an empty signal every 3 seconds; publish(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>) is a no-op.
File layout under busRoot:
{busRoot}/
queues/{key-hash}/
{entryId}.json — Mode A entries (drain = ls + read + delete)
logs/{key-hash}/
{entryId}.json — Mode C entries (append-only)
-
Field Summary
Fields inherited from interface io.agentscope.harness.agent.bus.MessageBus
SESSION_EVENTS_KEY_PREFIX, SESSION_REPLAY_MAX_LEN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<String> Append a payload to the replay log at the given key.Read up tomaxCountentries from the replay log, starting aftersince.reactor.core.publisher.Mono<Void> Delete the replay log at the given key and all of its entries.reactor.core.publisher.Mono<Void> Publish a payload on the broadcast channel.reactor.core.publisher.Mono<Void> queueDelete(String key) Delete the drain queue at the given key and all of its entries.queueDrain(String key, int maxCount) Drain up tomaxCountentries from the queue at the given key.reactor.core.publisher.Mono<Boolean> Check whether the drain queue at the given key has any entries, without consuming them.reactor.core.publisher.Mono<String> Append a payload to the drain queue at the given key.Subscribe to a broadcast channel.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.harness.agent.bus.MessageBus
close, enqueueWakeup, enqueueWakeup, inboxDrain, inboxHasMessages, inboxPush, sessionPublishEvent, sessionReadEvents, sessionSubscribeEvents, sessionTrimEvents, subscribeWakeup
-
Constructor Details
-
WorkspaceMessageBus
- Parameters:
filesystem- anyAbstractFilesystemimplementationbusRoot- absolute path within the filesystem for bus data (e.g."/bus")
-
-
Method Details
-
queuePush
Description copied from interface:MessageBusAppend a payload to the drain queue at the given key.- Specified by:
queuePushin interfaceMessageBus- Parameters:
key- queue identifier (caller-defined naming convention)payload- JSON-serializable dict to enqueue- Returns:
- the transport-level entry id
-
queueDrain
Description copied from interface:MessageBusDrain up tomaxCountentries from the queue at the given key. Returned entries are removed from the queue atomically. A subsequent call returns only entries that arrived after this one.- Specified by:
queueDrainin interfaceMessageBus- Parameters:
key- queue identifiermaxCount- maximum number of entries to return- Returns:
- entries in arrival order; empty list when the queue is empty
-
queueDelete
Description copied from interface:MessageBusDelete the drain queue at the given key and all of its entries. Idempotent.- Specified by:
queueDeletein interfaceMessageBus- Parameters:
key- queue identifier
-
queuePeek
Description copied from interface:MessageBusCheck whether the drain queue at the given key has any entries, without consuming them.- Specified by:
queuePeekin interfaceMessageBus- Parameters:
key- queue identifier- Returns:
- true if the queue has at least one entry
-
logAppend
public reactor.core.publisher.Mono<String> logAppend(String key, Map<String, Object> payload, int maxLen) Description copied from interface:MessageBusAppend a payload to the replay log at the given key. Readers track their own cursor; entries persist until trimmed or capped bymaxLen.- Specified by:
logAppendin interfaceMessageBus- Parameters:
key- log identifierpayload- JSON-serializable dict to appendmaxLen- cap the log at approximately this many entries; older entries are trimmed when exceeded. Use0or negative for no cap.- Returns:
- the transport-level entry id (usable as a cursor for subsequent reads)
-
logRead
Description copied from interface:MessageBusRead up tomaxCountentries from the replay log, starting aftersince. Non-destructive: the same entries can be returned to any number of readers.- Specified by:
logReadin interfaceMessageBus- Parameters:
key- log identifiersince- cursor — return entries strictly newer than this id.nullreads from the beginning.maxCount- maximum number of entries to return- Returns:
- entries in append order; empty list when no entries are newer than
since
-
logTrim
Description copied from interface:MessageBusDelete the replay log at the given key and all of its entries. Idempotent.- Specified by:
logTrimin interfaceMessageBus- Parameters:
key- log identifier
-
publish
Description copied from interface:MessageBusPublish a payload on the broadcast channel. Only currently-subscribed listeners receive it.- Specified by:
publishin interfaceMessageBus- Parameters:
key- channel identifierpayload- JSON-serializable dict
-
subscribe
Description copied from interface:MessageBusSubscribe to a broadcast channel. Yields payloads published after subscription is established. The caller owns the subscription's lifetime — cancelling the Flux ends it.- Specified by:
subscribein interfaceMessageBus- Parameters:
key- channel identifier- Returns:
- stream of payloads
-