MessageManager callbacks execution order


#1

Hello,
I’ m testing MessageManager with ConnectionManager, but I’m a little bit confused of order of execution of callbacks. The piece of code is:
cm <- ConnectionManager({ "blinkupBehavior" : ConnectionManager.BLINK_ALWAYS, "stayConnected" : true , "ackTimeout" : 1, "checkTimeout" : 1 }); imp.setsendbuffersize(8096); local options = { "debug": false, "retryInterval": 61, "messageTimeout": 1, "autoRetry": true, // "maxAutoRetries": 10, "connectionManager": cm } local mm = MessageManager(options) mm.beforeSend( function(msg, enqueue, drop) { computer.write(setTimeString()+": executing - \"mm.beforeSend\" "+msg.payload.data+"\\r\ ") enqueue() } ) mm.beforeRetry( function(msg, skip, drop) { computer.write(setTimeString()+": executing - \"mm.beforeRetry\" "+msg.payload.data+"\\r\ ") if(imp.getmemoryfree()<20000) { computer.write(setTimeString()+": OUT OF MEMORY , will clear memory"+"\\r\ ") drop() } } ) mm.onTimeout( function(msg, wait, fail) { computer.write(setTimeString()+": executing - \"mm.onTimeout\" "+msg.payload.data+"\\r\ ") } ) mm.onFail( function(msg, error, retry) { computer.write(setTimeString()+": executing - \"mm.onFail\" "+msg.payload.data+"\\r\ ") retry(); } ); function count() { computer.write(setTimeString()+": Pending messages: "+mm.getPendingCount()+"\\r\ ") computer.write(setTimeString()+": Free Memory: "+imp.getmemoryfree()+"\\r\ ") imp.wakeup(60,count) } count() mm.onReply( function(msg, response) { computer.write(setTimeString()+": Response for " + msg.payload.data + " received: " + response+"\\r\ ") server.log("Response for " + msg.payload.data + " received: " + response); } ) function sendData() { mm.send("name", counter++); imp.wakeup(60, sendData); } sendData()

After filtering internet connection of Device, which is connected via UART to PC , output is:

STARTING PROGRAM 2017-03-24 07:32:33: Pending messages: 0 2017-03-24 07:32:33: Free Memory: 65000 2017-03-24 07:32:33: executing - "mm.beforeSend" 0 2017-03-24 07:32:33: executing - "mm.beforeRetry" 0 2017-03-24 07:32:34: Response for 0 received: AGENT: Got it! 2017-03-24 07:33:33: Pending messages: 0 2017-03-24 07:33:33: Free Memory: 63888 // here Device is disconnected from Internet 2017-03-24 07:33:33: executing - "mm.beforeSend" 1 2017-03-24 07:33:33: executing - "mm.beforeRetry" 1 2017-03-24 07:33:35: executing - "mm.onTimeout" 1 2017-03-24 07:34:33: Pending messages: 0 2017-03-24 07:34:33: Free Memory: 63372 2017-03-24 07:34:33: executing - "mm.beforeSend" 2 2017-03-24 07:34:33: executing - "mm.beforeRetry" 2 2017-03-24 07:34:35: executing - "mm.onTimeout" 2 2017-03-24 07:35:33: Pending messages: 0 2017-03-24 07:35:33: Free Memory: 62700 2017-03-24 07:35:33: executing - "mm.beforeSend" 3 2017-03-24 07:35:33: executing - "mm.beforeRetry" 3 2017-03-24 07:35:35: executing - "mm.onTimeout" 3 2017-03-24 07:36:33: Pending messages: 0 2017-03-24 07:36:33: Free Memory: 62028 2017-03-24 07:36:33: executing - "mm.beforeSend" 4 2017-03-24 07:36:33: executing - "mm.beforeRetry" 4 2017-03-24 07:36:35: executing - "mm.onTimeout" 4 2017-03-24 07:37:33: Pending messages: 0 2017-03-24 07:37:33: Free Memory: 70360 2017-03-24 07:37:33: executing - "mm.beforeSend" 5 2017-03-24 07:37:34: executing - "mm.beforeRetry" 5 2017-03-24 07:37:34: executing - "mm.onFail" 5 2017-03-24 07:38:33: Pending messages: 1 2017-03-24 07:38:33: Free Memory: 63688 2017-03-24 07:38:33: executing - "mm.beforeSend" 6 2017-03-24 07:38:33: executing - "mm.beforeRetry" 6 2017-03-24 07:38:33: executing - "mm.onFail" 6 2017-03-24 07:38:35: executing - "mm.beforeRetry" 5 2017-03-24 07:38:35: executing - "mm.onFail" 5 2017-03-24 07:39:33: Pending messages: 2 2017-03-24 07:39:33: Free Memory: 63364 2017-03-24 07:39:33: executing - "mm.beforeSend" 7 2017-03-24 07:39:34: executing - "mm.beforeRetry" 7 2017-03-24 07:39:34: executing - "mm.onFail" 7 2017-03-24 07:39:34: executing - "mm.beforeRetry" 6 2017-03-24 07:39:34: executing - "mm.onFail" 6 2017-03-24 07:39:36: executing - "mm.beforeRetry" 5 2017-03-24 07:39:36: executing - "mm.onFail" 5 2017-03-24 07:40:33: Pending messages: 3

beforeSend -> beforeRetry -> onTimeout
but after some period: beforeSend -> beforeRetry -> onFail

  1. Is retrying of packet LIFO ?
  2. Is it possible, when reaching memory limit to delete for example the first N messages.