Seite 1 von 1

[A3|Milestone 4] Sending replies

Verfasst: 28. Jan 2008 17:03
von LukasRos
I'm working on Milestone 4 and got stuck when trying to send a reply to the sender to tell him to change redundancy settings.
My code is this:

Code: Alles auswählen

TypedMap rmap = new TypedMap();
rmap.putInt("new_rate_advice", sender.suggestedNewRedundancyRate());
rmap.putInt("sender_id", 0);
rmap.putInt("seq", 0);
Message reply = new Message(rmap);
reply.put("payload", "bin", new Blob());
putHeader(reply, "correction", rmap);
						
sendReply(msg, reply);
Yes, I know that I place the information twice - once in the "general" map and as additional headers, that was done intentionally.
But what I get is a NullPointerException from BinCollectHandler, pointing to the serializeString. What does this handler expect here, how can I format my reply message so that it is accepted?

Re: [A3|Milestone 4] Sending replies

Verfasst: 28. Jan 2008 20:28
von erwin.ait
Looks like you forgot msg.setType(mimeType); Please see samples/handlers/ex4 how to send reply messages.

Re: [A3|Milestone 4] Sending replies

Verfasst: 29. Jan 2008 21:27
von sander
Hi!

For MS4 our handler uses reply messages to control the amount of redundancy. After sending a certain number of messages our handler adds a XOR message. If the handler on the receiver side notices packet loss it informs the handler on the sender side to increase the amount of redundancy by sending a reply message:

Code: Alles auswählen

        TypedMap ctrl = new TypedMap();
        ctrl.putString("request", "control");
        ctrl.putString("mode", "set");
        ctrl.putInt("adjustment", i);
        Message ctrlMsg = new Message();
        putHeader(ctrlMsg, "fec", ctrl);
        ctrlMsg.setType(mimeType);
        sendReply(msg, ctrlMsg);
        resetReceiver(i);
The problem is, that if our TestSender-Application send it's messages to fast, our handler does not receive these control messages in time:

Code: Alles auswählen

 for (int i=1; i<=NUM_MESSAGES; i++)
	    {
	      TypedMap map = new TypedMap();
	      map.putInt("seq", i);
	      Message msg = new Message(map);
	      if (payload!=null)
	        msg.put("payload", "bin", payload);
	      publisher.send(msg);
	            
	      numMsgSent++;	      
	      Thread.sleep(1);
	    }
If we increase the time between 2 messages from Thread.sleep(1) to Thread.sleep(100) everything seems to work.

Is there a way to make the handler wait for a control message before sending further messages?

Re: [A3|Milestone 4] Sending replies

Verfasst: 30. Jan 2008 13:44
von erwin.ait
Thread.sleep(1) means basically that you are trying to send 1000 messages/sec. Depending on the speed of your computer, this might already be close to the limit. Maybe use something like Thread.sleep(10).
sander hat geschrieben: The problem is, that if our TestSender-Application send it's messages to fast, our handler does not receive these control messages in time:
It should be no problem if your handler receives the control message a bit delayed. In addition, sending a control message for each received data packet would cause too much additional traffic.
sander hat geschrieben: Is there a way to make the handler wait for a control message before sending further messages?
The overall design of the handler should be asynchronous and not synchronous. Don't introduce such tight couplings between data and control messages.