1 28 29 package com.caucho.server.cluster; 30 31 import com.caucho.util.LruCache; 32 33 import java.util.Hashtable ; 34 35 38 public class BackingManager { 39 private Hashtable <String ,BackingContext> _contextMap = 40 new Hashtable <String ,BackingContext>(); 41 42 private LruCache<BackingKey,ObjectBacking> _backingCache = 43 new LruCache<BackingKey,ObjectBacking>(1024); 44 45 private BackingKey _key = new BackingKey(); 46 47 50 public ObjectBacking getBacking(String contextId, String objectId) 51 { 52 synchronized (this) { 53 _key.init(contextId, objectId); 54 55 ObjectBacking backing = _backingCache.get(_key); 56 57 if (backing != null) 58 return backing; 59 60 BackingContext context = getContext(contextId); 61 62 if (context == null) 63 return null; 64 65 backing = context.getBacking(objectId); 66 67 _backingCache.put(new BackingKey(contextId, objectId), backing); 68 69 return backing; 70 } 71 } 72 73 76 public BackingContext getContext(String contextId) 77 { 78 return _contextMap.get(contextId); 79 } 80 81 84 public void setContext(String contextId, BackingContext context) 85 { 86 _contextMap.put(contextId, context); 87 } 88 89 92 public void removeContext(String contextId) 93 { 94 _contextMap.remove(contextId); 95 } 96 97 static class BackingKey { 98 private String _contextId; 99 private String _objectId; 100 101 BackingKey() 102 { 103 } 104 105 BackingKey(String contextId, String objectId) 106 { 107 _contextId = contextId; 108 _objectId = objectId; 109 } 110 111 void init(String contextId, String objectId) 112 { 113 _contextId = contextId; 114 _objectId = objectId; 115 } 116 117 public int hashCode() 118 { 119 return _contextId.hashCode() * 65521 + _objectId.hashCode(); 120 } 121 122 public boolean equals(Object o) 123 { 124 if (! (o instanceof BackingKey)) 125 return false; 126 127 BackingKey key = (BackingKey) o; 128 129 return (_contextId.equals(key._contextId) && 130 _objectId.equals(key._objectId)); 131 } 132 } 133 } 134 | Popular Tags |