Commit 98caebe5 authored by chiaming2000's avatar chiaming2000
Browse files

Simulator: clean up (release resources) uncommitted batch operations

within a connection if the connection is closed.      
parent 23a38875
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import io.netty.channel.ChannelHandlerContext;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

@@ -328,4 +329,24 @@ public class NioBatchOpPreProcessor {

        return kineticMessage;
    }
    
    /**
     * remove batches from this connection.
     * 
     * @param km kinetic message.
     */
    public static void cleanUpConnection (long cid) {
        
        // connection id
        String keyPrefix = String.valueOf(cid);
        // batch keys
        Set <String> keys = batchMap.keySet();
        
        // remove matched connection ids
        for (String key: keys) {    
            if (key.startsWith(keyPrefix)) {
                batchMap.remove(key);
            }
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -187,6 +187,9 @@ public class NioMessageServiceHandler extends
        // map
        ConnectionInfo info = SimulatorEngine.removeConnectionInfo(ctx);
        
        // remove batches in batch queue
        NioBatchOpPreProcessor.cleanUpConnection(info.getConnectionId());

        logger.info("connection info is removed, id=" + info.getConnectionId()
                + ", is secure channel=" + this.isSecureChannel);
	}