MCPcopy Create free account
hub / github.com/akeranen/the-one / makeRoomForMessage

Method makeRoomForMessage

routing/ActiveRouter.java:268–288  ·  view source on GitHub ↗

Removes messages from the buffer (oldest first) until there's enough space for the new message. @param size Size of the new message transferred, the transfer is aborted before message is removed @return True if enough space could be freed, false if not

(int size)

Source from the content-addressed store, hash-verified

266 * @return True if enough space could be freed, false if not
267 */
268 protected boolean makeRoomForMessage(int size){
269 if (size > this.getBufferSize()) {
270 return false; // message too big for the buffer
271 }
272
273 int freeBuffer = this.getFreeBufferSize();
274 /* delete messages from the buffer until there's enough space */
275 while (freeBuffer < size) {
276 Message m = getNextMessageToRemove(true); // don't remove msgs being sent
277
278 if (m == null) {
279 return false; // couldn't remove any more messages
280 }
281
282 /* delete message from the buffer as "drop" */
283 deleteMessage(m.getId(), true);
284 freeBuffer += m.getSize();
285 }
286
287 return true;
288 }
289
290 /**
291 * Drops messages whose TTL is less than zero.

Callers 4

checkReceivingMethod · 0.95
makeRoomForNewMessageMethod · 0.95
updateMethod · 0.95
checkReceivingMethod · 0.80

Calls 6

getIdMethod · 0.95
getSizeMethod · 0.95
getBufferSizeMethod · 0.80
getFreeBufferSizeMethod · 0.80
deleteMessageMethod · 0.45

Tested by

no test coverage detected