publishChange does not trigger an execute
Todd Wright
twright at bbn.com
Fri Dec 14 11:51:09 EST 2007
Michiel Kamermans wrote:
> Hi,
>
> I'm using cougaar 12.4 and implemented a very simple agent, using relays
> based on the ones from the pizzaparty demo.
Okay. Also see the ping demo in the 12.4 release's "demo-ping.zip", which is a
trimmed-down relay demo.
You might also be interested in:
demo-hello.zip : trivial "hello world" plugin
demo-mandelbrot.zip : various UI and relay design patterns
demo-mesh.zip : relay performance benchmark
> When run from the society
> xml I use, one nameserver agent and two of these simple agents are
> created, as well as a jframe button that tells "agent 1" to send an
> object over a relay to "agent 2". these simple agents just look at
> whether they received an object, wait two seconds, and then send a same
> object back - effectively sending one object starts a stream of
> back-and-forth communication.
>
> Problem is, I tried two approaches; in the first I make a new relay a la
> "Relaysource relay = new RelaySource(agentaddress,new Object())" and
> then use blackboard.publishAdd(relay) to have cougaar do all the right
> things and have the RelayTarget created at the target agent. This works
> fine in that a back-and-forth stream keeps going until I kill the JVM.
Good. The ping demo uses the same "add/remove" pattern.
> The second approach fails horribly: instead of making new relays all the
> time, I give the agents a simple "acquaintance" set, which is just a
> HashMap<MessageAddress,RelaySource> so that agents can reuse a one-time
> made relay for each agent that contacts them. For the first message from
> agent 1 to agent 2, all goes well because it doesn't have agent 2 as
> acquaintance yet, so it has to make a new relay and use publishAdd to
> have it added to the blackboard. Then when agent 2 receives the object,
> it also doesn't know agent 1 yet, so when replying it creates a new
> relay to agent 1 and then publishAdds it to the blackboard. Then when
> agent 1 receives this response, things fail. It will retrieve the relay
> from its acquantaince set, change what's on the relay, and then call
> blackboard.publishChange for this relay... and then agent 2's execute()
> method is never called =(
This "add/change" pattern is also fine. The performance should be nearly
identical as the "add/remove" pattern.
It looks like the problem is in DPNTargetRelay, where it does:
// We don't use responses, but rather use separate relays
public int updateContent(Object newContent, Token token) {
return Relay.NO_CHANGE;
}
The pizza demo apparently never publishChange'd its relays.
I recommend that you use the standard "SimpleRelay" classes included in the
Cougaar core. See the ping demo for an example. That should fix this bug and
you won't need your own classes:
DPNRelayFactory.java
DPNSourceRelay.java
DPNTargetRelay.java
DPNTargetRelayFactory.java
>
> I've put the source code on
> http://pomax.nihongoresources.com/downloads/cougaar with the main class
> being DPNTestClass.java
Looks good. A couple comments:
1)
As noted above, consider using "SimpleRelay".
2)
In the Swing callback for "startConnectionStream()", you could use a
TodoSubscription, which is similar to a "SwingUtilities.invokeLater(...)" for
the "execute()" thread. An example is attached at the end of:
http://www.cougaar.org/pipermail/cougaar-developers/2007-June/002353.html
3)
I see you're using a spin loop to add a delay:
while (System.currentTimeMillis()-start < 1000*seconds) {
seconds = seconds * 1;
}
This is fine, just a bit surprising. Of course, you could do:
try { Thread.sleep(seconds*1000); } catch (InterruptedException ie) {}
or use an asynchronous Cougaar Alarm, as illustrated in the ping demo.
>
> When I run this (I can't really put all the dependency code online too,
> due to ye olde proprietary silliness) the output is as follows:
>
>
> COUGAAR 12.0 (JDK1.4) built on Mon Jul 25 08:05:17 CEST 2005
> Repository: B12_0JDK1_4 on Mon Jul 25 08:00:06 CEST 2005
> VM: JDK 1.6.0_01-b06 (mixed mode)
> OS: Windows XP (5.1)
> 13:12:49,078 SHOUT - XMLComponentInitializerServiceProvider -
> Initializing node "DPN1" from XML file "DPNSociety.xml"
> 13:12:56,968 WARN - DirectSysStatSupplier - No handler for Memory on
> platform Windows XP
> 13:12:56,968 WARN - DirectSysStatSupplier - No handler for CPU on
> platform Windows XP
> 13:12:56,968 WARN - DirectSysStatSupplier - No handler for LoadAverage
> on platform Windows XP
> 13:12:56,968 WARN - DirectSysStatSupplier - No handler for Sockets on
> platform Windows XP
> 13:12:59,046 SHOUT - AssetInitializerServiceComponent - DPN1: Not using
> a database, initializing solely from Files.
> 13:13:00,921 SHOUT - DPNTestClass - Agent 1: loaded agent...
> 13:13:01,343 SHOUT - DPNTestClass - Agent 1: StartButtonObject created
> 13:13:01,453 SHOUT - DPNTestClass - Agent 2: loaded agent...
> 13:13:01,515 SHOUT - DPNTestClass - Agent 2: StartButtonObject created
> 13:13:01,609 SHOUT - DPNTestClass - Agent 2: setting up subscriptions
> 13:13:01,609 SHOUT - DPNTestClass - Agent 1: setting up subscriptions
> 13:13:01,625 SHOUT - DPNTestClass - Agent 1: calling execute
> 13:13:01,625 SHOUT - DPNTestClass - Agent 2: calling execute
> 13:13:01,625 SHOUT - DPNTestClass - Agent 1: calling execute
> 13:13:01,625 SHOUT - DPNTestClass - Agent 2: calling execute
> 2007-12-14 01:13:06,546 SHOUT [DOTS] - ............
>
> I then press the button of the StartButtonObject for agent1, which calls
> agent 1's startContainerStream() method
>
> 13:14:05,171 SHOUT - DPNTestClass - Agent 1: adding relay to blackboard
> 2007-12-14 01:14:05,171 SHOUT [DOTS] - +-
> 13:14:05,203 SHOUT - DPNTestClass - Agent 2: calling execute
> 13:14:05,203 SHOUT - DPNTestClass - Agent 2: ***
> 13:14:05,203 SHOUT - DPNTestClass - Agent 2: a new relay was found
> 13:14:05,203 DEBUG - DPNTestClass - Agent 2: received DPNTestContainer 1
> from Agent 1
> 2007-12-14 01:14:06,546 SHOUT [DOTS] - .
> 13:14:07,203 DEBUG - DPNTestClass - Agent 2: sending DPNTestContainer 2
> as response to Agent 1
> 13:14:07,203 SHOUT - DPNTestClass - Agent 2: adding relay to blackboard
> 2007-12-14 01:14:07,203 SHOUT [DOTS] - +-
> 13:14:07,203 SHOUT - DPNTestClass - Agent 1: calling execute
> 13:14:07,203 SHOUT - DPNTestClass - Agent 1: ***
> 13:14:07,203 SHOUT - DPNTestClass - Agent 1: a new relay was found
> 13:14:07,203 DEBUG - DPNTestClass - Agent 1: received DPNTestContainer 2
> from Agent 2
> 13:14:09,203 DEBUG - DPNTestClass - Agent 1: sending DPNTestContainer 3
> as response to Agent 2
> 13:14:09,203 SHOUT - DPNTestClass - Agent 1: publishing change on relay
> 2007-12-14 01:14:09,203 SHOUT [DOTS] -
> +-...........................................................
>
> And no amount of waiting leads to agent 2's execute() being called =(
>
> I hope I just forgot to add something really simple to the relay class
> or publish call (just to make sure I tried adding a changelist
> Collection to publishChange but that didn't help get execute called).
>
> So... does anyone have any idea what I (clearly) must have done wrong?
>
> Thank you in advance,
No problem. Thanks for the clear writeup.
Todd
>
>
> - Mike Kamermans
> University of Amsterdam
>
> _______________________________________________
> Cougaar-developers mailing list
> Cougaar-developers at cougaar.org
> http://cougaar.org/mailman/listinfo/cougaar-developers
>
More information about the Cougaar-developers
mailing list