Closed jsagerOffis closed 3 months ago
example code:
using Mango using Sockets: InetAddr, @ip_str import Mango.AgentCore.handle_message @agent struct ReplyAgent end function handle_message(agent::ReplyAgent, message::Any, meta::Any) println("$(agent.aid) got a message \nwith content $message \nand meta $meta") end function main() c1_addr = InetAddr(ip"127.0.0.1", 5555) c1 = Container() c1.protocol = TCPProtocol(address=c1_addr) a1 = ReplyAgent() register(c1, a1, "Timmy") # start container loop wait(Threads.@spawn start(c1)) timmy_addr = AgentAddress("Timmy", c1_addr, nothing) unknown_addr = AgentAddress("unknown", c1_addr, nothing) # send some messages wait(send_message(c1, "hello", unknown_addr)) # stop container loop wait(Threads.@spawn shutdown(c1)) end main()
Output:
┌ Warning: Container Dict{String, Agent}("Timmy" => ReplyAgent(ReentrantLock(nothing, 0x00000000, 0x00, Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), (0, 0, 0)), AgentContext(Container │ agents: Dict{String, Agent} │ agent_counter: Int64 1 │ protocol: TCPProtocol │ codec: Tuple{typeof(Mango.EncodeDecode.encode), typeof(Mango.EncodeDecode.decode)} │ shutdown: Bool false │ loop: Task │ tasks: Array{Any}((0,)) │ ), AgentRoleHandler(Role[], Tuple{Role, Function, Function}[], Tuple{Role, Function}[], Dict{DataType, Vector{Tuple{Role, Function, Function}}}(), Dict{DataType, Any}()), Scheduler │ tasks: ConcurrentCollections.Implementations.LinearProbingDict{Task, TaskData, Union{ConcurrentCollections.Implementations.Empty, Task}, Union{ConcurrentCollections.Implementations.Empty, ConcurrentCollections.Implementations.Moved{ConcurrentCollections.Implementations.Empty}, ConcurrentCollections.Implementations.Moved{TaskData}, TaskData}} │ , "Timmy", Dict{String, Tuple}())) has no agent with id: unknown └ @ Mango.ContainerCore ~/.julia/packages/Mango/zCuwp/src/container/core.jl:159 ERROR: LoadError: BoundsError: attempt to access 0-element Vector{Any} at index [1] Stacktrace: [1] getindex @ ./essentials.jl:13 [inlined] [2] forward_message(container::Container, msg::String, meta::OrderedCollections.OrderedDict{String, Any}; receivers::Nothing) @ Mango.ContainerCore ~/.julia/packages/Mango/zCuwp/src/container/core.jl:169 [3] forward_message @ ~/.julia/packages/Mango/zCuwp/src/container/core.jl:146 [inlined] [4] send_message(container::Container, content::String, agent_adress::AgentAddress, sender_id::Nothing; kwargs::@Kwargs{}) @ Mango.ContainerCore ~/.julia/packages/Mango/zCuwp/src/container/core.jl:212 [5] send_message (repeats 2 times) @ ~/.julia/packages/Mango/zCuwp/src/container/core.jl:186 [inlined] [6] main() @ Main ~/work/code/tutorial_demo_env/my_first_agent.jl:29 [7] top-level scope @ ~/work/code/tutorial_demo_env/my_first_agent.jl:35 in expression starting at /home/jens/work/code/tutorial_demo_env/my_first_agent.jl:35
example code:
Output: