public synchronized ScheduledFuture scheduleTimeout ( final int sequenceNumber , long time , TimeUnit unit ) { if ( ! files . containsKey ( sequenceNumber ) ) return null ; ScheduledFuture future = timeoutExecutor . schedule ( new Runnable ( ) { public void run ( ) { synchronized ( StreamTransferTask . this ) { // remove so we don't cancel ourselves timeoutTasks . remove ( sequenceNumber ) ; StreamTransferTask . this . complete ( sequenceNumber ) ; } } } , time , unit ) ; ScheduledFuture prev = timeoutTasks . put ( sequenceNumber , future ) ; assert prev == null ; return future ; }
Schedule timeout task to release reference for file sent . When not receiving ACK after sending to receiver in given time the task will release reference .