??????? findService ????????????????????????????????? StringUtil.isEmpty ????????????????????????????????????????????????????????method-service?????????? ClientFactory ??????????????????????? ClientFactory ?? AppInfoDAO ??????????????Щlog???????????????????????????????Щ????????????????????????С????????????????????????? findService ?????????????????????????????????????????ɡ???????????????????????????????????????????????????????????????????????????????????????ClientFactory ?? AppInfoDAO ?????????仯???????????????ServiceTableImpl ???????????????????????????仯??????????????????????????Χ???????? ServiceTableImpl ????? ServiceTableImpl + ClientFactory + AppInfoDAO??
????????????????????????????????飬??????????? ServiceTableImpl?????????????? ClientFactory ?? AppInfoDAO????????????????????????????ServiceTableImpl??????????????????????????? ClientFactory ?? AppInfoDAO ???????????????????????????appInfoDAO.getAppInfoByMethod(method) ????????????????? serviceid?? ?? referenceClient.getService(serviceId) ?????????????????????
???????????Mock???? - ??????????? AppInfoDAO ??????????????????????????????????????? AppInfoDAO ?????????? getAppInfoByMethod ??????
????// ???AppInfoDAO??????getAppInfoByMethod?????????????????
????public class MockAppInfoDAO extends AppInfoDAO {
????AppInfo getAppInfoByMethod(String method) {
????AppInfo appInfo = new AppInfo();
????appInfo.setServiceId("a service id");
????return appInfo;
????}
????}
????//?? MockAppInfoDAO ???ServiceTableImpl
????ServiceTableImpl.setAppInfoDAO(new MockAppInfoDAO());
???????????????Mock??ClientFactory?????????? ServiceTableImpl ??????????????????????????????????????????
?????????????????????????? - Android??????????????Android??????????????????????Android???н??????н?????????????????????????????????????????????????????????д??????ò????????????????????????????????????
public class ShortLifeMemoCache<T> implements CacheService<T> {
private static final long DEFAULT_TTL = 1L*60*60*1000;
/**
* ???????(Time to live)????λ:????
*/
private long ttl = DEFAULT_TTL;
private final Map<String?? Value<T>> cache =  new HashMap<String?? Value<T>>();
@Override
public void put(String key?? T t) {
long life = System.currentTimeMillis() + ttl;
cache.put(key?? new Value<T>(t?? life));
}
@Override
public T get(String key) {
Value<T> v = cache.get(key);
if (v != null){
if(v.getLife() > System.currentTimeMillis()) {
return v.getValue();
} else {
cache.remove(key);
}
}
return null;
}
@Override
public T remove(String key) {
return cache.remove(key).getValue();
}
@Override
public int size() {
return cache.size();
}
// ???getter??setter????
...
// ??????Value?????????????????????
static class Value<T> {
// ???????
private long life;
// ?????Value
private T t;
public Value() {}
public Value(T t?? long life) {
setValue(t?? life);
}
// ???getter??setter????
...
}
}
?????1???????????????????????滺?棬???????K-V????????ж??????С??????????С???????????????????????????
?????2???????????????ttl?????ttl???ó???????С????????????????????????????????????????????????????????