1 20 21 22 package org.snmp4j.agent; 23 24 import java.util.Map ; 25 import org.snmp4j.smi.OctetString; 26 import java.util.TreeMap ; 27 28 35 public class ProxyMap { 36 37 private Map proxies = new TreeMap (); 38 39 public ProxyMap() { 40 } 41 42 public ProxyForwarder add(ProxyForwarder proxyForwarder, 43 OctetString contextEngineID, 44 int proxyType) { 45 return (ProxyForwarder) 46 this.proxies.put(new ProxyKey(contextEngineID, proxyType), 47 proxyForwarder); 48 } 49 50 public ProxyForwarder remove(OctetString contextEngineID, 51 int proxyType) { 52 return (ProxyForwarder) 53 this.proxies.remove(new ProxyKey(contextEngineID, proxyType)); 54 } 55 56 public ProxyForwarder get(OctetString contextEngineID, 57 int proxyType) { 58 ProxyForwarder proxy =(ProxyForwarder) 59 this.proxies.get(new ProxyKey(contextEngineID, proxyType)); 60 if (proxy == null) { 61 proxy = (ProxyForwarder) this.proxies.get(new ProxyKey(null, proxyType)); 62 } 63 return proxy; 64 } 65 66 static class ProxyKey implements Comparable { 67 68 private OctetString contextEngineID; 69 private int proxyType; 70 71 ProxyKey(OctetString contextEngineID, int proxyType) { 72 this.contextEngineID = contextEngineID; 73 this.proxyType = proxyType; 74 } 75 76 public int compareTo(Object o) { 77 ProxyKey other = (ProxyKey)o; 78 if (((contextEngineID == null) && (other.contextEngineID != null)) || 79 ((other.contextEngineID == null) && (contextEngineID != null)) || 80 ((other.contextEngineID == null) && (contextEngineID == null)) || 81 (contextEngineID.equals(other.contextEngineID))) { 82 if ((proxyType == ProxyForwarder.PROXY_TYPE_ALL) || 83 (other.proxyType == ProxyForwarder.PROXY_TYPE_ALL)) { 84 return 0; 85 } 86 return (proxyType - other.proxyType); 87 } 88 return contextEngineID.compareTo(other.contextEngineID); 89 } 90 91 } 92 } 93 | Popular Tags |