view rep/RoutingTable.java @ 492:d2afd4efdd2d

remove unMergedCmds, use sentList instead.
author one
date Sat, 23 Oct 2010 16:15:14 +0900
parents 18cacd0b3ccf
children
line wrap: on
line source

package rep;

import java.util.HashMap;
import java.util.Map.Entry;

import rep.handler.REPNode;

public class RoutingTable extends HashMap<Integer,REPNode>{

	/**
	 *    Routing Table for the tree structure. We keep our child,
	 *    if we don't know send it to the parent. Every ID has
	 *    session manager ID part, so we keep session manager ID
	 *    based path. 
	 */
	private static final long serialVersionUID = 1L;
	SessionManager manager;

	public RoutingTable(SessionManager sessionManager) {
		super();
		manager = sessionManager;
	}

	public void add(REPNode forwarder, int smid) {
		if (smid>0) put(smid, forwarder)	;
	}
	
	public void remove(REPNode f) {
		for(Entry<Integer, REPNode> entry:entrySet()) {
			if (entry.getValue()==f) remove(entry.getKey());
		}
	}

	public void removeManager(int smid) {
		remove(smid);
	}

	public REPNode toSessionManager(int eid) {
		REPNode next = get(eid);
		if (next==null) return manager.smList.parent();
		return next;
	}

}