use of j.util.ConcurrentList in project JFramework by gugumall.
the class DBMirror method available.
/**
* @return
*/
boolean available() {
if (shutdown) {
status = DBMirror.STATUS_UNAVAILABLE;
return false;
}
if (!avail) {
status = DBMirror.STATUS_UNAVAILABLE;
return false;
}
if (!isMonitor && (monitor != null && monitor.matches(JUtilString.RegExpHttpUrl))) {
synchronized (this) {
String url = monitor;
if (url.indexOf("?") > 0)
url += "&request=isAvail";
else
url += "?request=isAvail";
url += "&db_name=" + dbname;
url += "&mirror_uuid=" + uuid;
JHttpContext context = null;
int loop = 0;
while ((context == null || context.getStatus() != 200) && loop < 10) {
try {
context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
loop++;
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
try {
Thread.sleep(6000);
} catch (Exception ex) {
}
}
}
String result = context == null ? "false" : context.getResponseText();
// log.log("status from monitor - "+url+","+result, Logger.LEVEL_INFO);
context.finalize();
context = null;
if ("true".equalsIgnoreCase(result)) {
status = DBMirror.STATUS_AVAILABLE;
} else {
status = DBMirror.STATUS_UNAVAILABLE;
}
return "true".equalsIgnoreCase(result);
}
} else {
synchronized (this) {
if (factory == null) {
try {
factory = DAOFactory.getInstance(dbname, config);
factory.resetIgnoreColsWhileUpdating();
ConcurrentList cols = db.getIgnoreColsWhileUpdateViaBean();
for (int i = 0; i < cols.size(); i++) {
String col = (String) cols.get(i);
factory.ignoreColWhileUpdating(col.substring(0, col.indexOf(",")).trim(), col.substring(col.indexOf(",") + 1).trim());
}
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
return false;
}
}
}
}
DAO dao = null;
try {
dao = factory.createDAO(DBMirror.class, this);
dao.close();
status = DBMirror.STATUS_AVAILABLE;
return true;
} catch (Exception e) {
status = DBMirror.STATUS_UNAVAILABLE;
log.log(e, Logger.LEVEL_INFO);
if (dao != null) {
try {
dao.close();
dao = null;
} catch (Exception ex) {
}
}
return false;
}
}
use of j.util.ConcurrentList in project JFramework by gugumall.
the class DBMirror method connect.
/**
* @param clazz
* @return
* @throws Exception
*/
DAO connect(Class clazz) throws Exception {
synchronized (this) {
if (factory == null) {
factory = DAOFactory.getInstance(dbname, config);
factory.resetIgnoreColsWhileUpdating();
ConcurrentList cols = db.getIgnoreColsWhileUpdateViaBean();
for (int i = 0; i < cols.size(); i++) {
String col = (String) cols.get(i);
factory.ignoreColWhileUpdating(col.substring(0, col.indexOf(",")).trim(), col.substring(col.indexOf(",") + 1).trim());
}
}
}
return factory.createDAO(clazz, this);
}
use of j.util.ConcurrentList in project JFramework by gugumall.
the class JCacheUnitList method sub.
/*
* (non-Javadoc)
* @see j.cache.JCacheUnit#sub(j.cache.JCacheParams)
*/
public Object sub(JCacheParams params) throws Exception {
checkStatus(false);
ConcurrentList values = container.snapshot();
if (params != null) {
if (params.valueFilter != null) {
// 按条件过滤
for (int i = 0; i < values.size(); i++) {
Object value = values.get(i);
if (!params.valueFilter.matches(value)) {
values.remove(i);
i--;
}
}
}
if (params.fromIndex >= 0 && params.toIndex > params.fromIndex) {
// 指定起始位置
int start = params.fromIndex;
int to = params.toIndex;
if (start >= 0) {
if (values.size() > start) {
values = JUtilList.subConcurrentList(values, start, to > values.size() ? values.size() : to);
} else {
values.clear();
}
}
}
if (params.sorter != null) {
// 排序
List temp = params.sorter.mergeSort(values, params.sortType);
values.clear();
values.addAll(temp);
}
values.setTotal(values.size());
if (params.recordsPerPage > 0 && params.pageNum > 0) {
// 分页
int start = params.recordsPerPage * (params.pageNum - 1);
int to = params.recordsPerPage * params.pageNum;
if (start >= 0) {
if (values.size() > start) {
values = JUtilList.subConcurrentList(values, start, to > values.size() ? values.size() : to);
} else {
values.clear();
}
}
}
}
return values;
}
use of j.util.ConcurrentList in project JFramework by gugumall.
the class JDCache method values.
/*
* (non-Javadoc)
* @see j.cache.JCache#values(java.lang.String, j.cache.JCacheParams)
*/
public ConcurrentList values(String cacheId, JCacheParams jdcParams) throws Exception {
Servant info = findService(cacheId);
if (info.service != null) {
return info.service.values(cacheId, jdcParams);
} else {
Map params = new HashMap();
params.put("cacheId", cacheId);
params.put("params", JObject.serializable2String((Serializable) jdcParams));
String response = Client.httpCallPost(info.jhttp, info.jclient, info.serviceCode, info.httpChannel, "values", params);
params.clear();
params = null;
return (ConcurrentList) JObject.string2Serializable(response);
}
}
use of j.util.ConcurrentList in project JFramework by gugumall.
the class Statics method concurrentList.
/**
* @param key
* @return
*/
public static ConcurrentList concurrentList(String key) {
if (statics.containsKey(key)) {
return (ConcurrentList) statics.get(key);
} else {
ConcurrentList _static = new ConcurrentList();
statics.put(key, _static);
return _static;
}
}
Aggregations