Package com.tnsai.communication
Class SharedBlackboard
java.lang.Object
com.tnsai.communication.SharedBlackboard
Shared blackboard for multi-agent collaboration and coordination.
The blackboard pattern allows agents to:
- Post findings, proposals, and status updates
- Read and react to other agents' entries
- Vote on proposals
- Build consensus through structured communication
Thread-safe implementation for concurrent access.
Example usage:
SharedBlackboard blackboard = new SharedBlackboard();
// Post a finding
blackboard.post("analyzer", EntryType.ISSUE_FOUND, "Memory leak in UserService",
Map.of("file", "UserService.java", "line", 42));
// Listen for proposals
blackboard.addTypeListener(EntryType.DESIGN_PROPOSAL, entry ->
System.out.println("New proposal: " + entry.getTitle()));
// Vote on a proposal
blackboard.vote(proposalId, "reviewer", VoteType.APPROVE);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEntry on the blackboard.static enumTypes of blackboard entries.static final recordVote result record.static enumVote types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Consumer<SharedBlackboard.Entry> listener) Adds a listener for all entries.voidaddTypeListener(SharedBlackboard.EntryType type, Consumer<SharedBlackboard.Entry> listener) Adds a listener for specific entry types.voidclear()Clears all entries (use with caution).find(Predicate<SharedBlackboard.Entry> predicate) Finds entries matching a predicate.Gets all entries.getByAuthor(String authorId) Gets entries by author.Gets an entry by ID.Gets entries by type.getConcerns(String entryId) Gets concerns for an entry.Gets open questions (questions without answers).Gets pending proposals (proposals without decisions).getRecent(int count) Gets recent entries.getReplies(String entryId) Gets replies to an entry.Gets summary statistics.getVoteResult(String entryId) Gets the vote result for an entry.booleanhasConsensus(String entryId, int minVotes, double threshold) Checks if an entry has consensus.booleanisEmpty()Checks if blackboard is empty.post(SharedBlackboard.Entry entry) Posts an entry using builder pattern.post(String authorId, SharedBlackboard.EntryType type, String title, Object content) Posts a new entry to the blackboard.voidremoveListener(Consumer<SharedBlackboard.Entry> listener) Removes a listener.voidremoveTypeListener(SharedBlackboard.EntryType type, Consumer<SharedBlackboard.Entry> listener) Removes a type listener.reply(String authorId, String parentId, SharedBlackboard.EntryType type, String title, Object content) Posts a reply to an existing entry.intsize()Gets entry count.voidvote(String entryId, String voterId, SharedBlackboard.VoteType voteType) Casts a vote on an entry.
-
Constructor Details
-
SharedBlackboard
public SharedBlackboard()
-
-
Method Details
-
getVoteResult
Gets the vote result for an entry.- Parameters:
entryId- Entry ID- Returns:
- Vote result
-
hasConsensus
Checks if an entry has consensus.- Parameters:
entryId- Entry IDminVotes- Minimum votes requiredthreshold- Approval threshold (0.0 - 1.0)- Returns:
- true if consensus reached
-
getAllEntries
Gets all entries. -
getById
Gets an entry by ID. -
getByAuthor
Gets entries by author. -
getReplies
Gets replies to an entry. -
getRecent
Gets recent entries. -
find
Finds entries matching a predicate. -
getPendingProposals
Gets pending proposals (proposals without decisions). -
getOpenQuestions
Gets open questions (questions without answers). -
getConcerns
Gets concerns for an entry. -
addListener
Adds a listener for all entries. -
removeListener
Removes a listener. -
getSummary
Gets summary statistics. -
size
public int size()Gets entry count. -
isEmpty
public boolean isEmpty()Checks if blackboard is empty. -
clear
public void clear()Clears all entries (use with caution).