use of j.cache.JCacheParams in project JFramework by gugumall.
the class RdbmsDao method autoIncreaseKeyLargerThan.
public String autoIncreaseKeyLargerThan(String table, String column, long min, long addition) throws Exception {
String key = (factory.getDbName().toLowerCase() + "." + table.toLowerCase() + "." + column.toLowerCase()).intern();
synchronized (key) {
Long max = null;
if (DB.isCluster) {
max = (Long) factory.getMaxColumnValues().get(new JCacheParams(key));
} else {
max = (Long) factory.getMaxColumnValuesLocal().get(key);
}
if (max == null) {
DAO dao = null;
try {
dao = DB.connect(factory.getDbName(), DB.class);
String strMax = dao.getMaxNumber(table, column, "");
max = new Long(JUtilMath.isLong(strMax) ? strMax : "0");
} catch (Exception e) {
if (dao != null) {
try {
dao.close();
dao = null;
} catch (Exception ex) {
}
}
throw e;
}
}
long ret = 0;
ret = max.longValue() + 1 + addition;
if (ret < min)
ret = min;
if (DB.isCluster) {
factory.getMaxColumnValues().addOne(key, new Long(ret));
} else {
factory.getMaxColumnValuesLocal().put(key, new Long(ret));
}
return "" + ret;
}
}
use of j.cache.JCacheParams in project JFramework by gugumall.
the class OnlinesCluster method run.
/*
* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
JCacheParams params = new JCacheParams();
params.valueFilter = new OnlineRemover();
while (true) {
try {
Thread.sleep(5000);
} catch (Exception e) {
}
// 配置文件变动
try {
File configFile = new File(Properties.getConfigPath() + "onlines.xml");
if (configLastModified < configFile.lastModified()) {
log.log("onlines.xml has been modified, so reload it.", -1);
load();
}
configFile = null;
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
}
// 移除过期对象
try {
if (onlines == null)
continue;
onlines.remove(params);
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
}
// 移除过期访问记录
long now = SysUtil.getNow();
List keys = counts.listKeys();
for (int i = 0; i < keys.size(); i++) {
String ip = (String) keys.get(i);
RequestCount c = (RequestCount) counts.get(ip);
if (c == null || now - c.latestRequestTime > 60000) {
counts.remove(ip);
}
}
keys.clear();
keys = null;
}
}
use of j.cache.JCacheParams in project JFramework by gugumall.
the class OnlinesCluster method findByUserId.
/**
* @param userId
* @return
*/
public static Online findByUserId(String userId) {
JCacheParams params = new JCacheParams();
OnlineFilter filter = new OnlineFilter();
filter.setUid(userId);
params.valueFilter = filter;
try {
return (Online) onlines.get(params);
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
return null;
}
}
use of j.cache.JCacheParams in project JFramework by gugumall.
the class SSOServer method updateLoginStatus.
/**
* @param updater
*/
public static void updateLoginStatus(LoginStatusUpdater updater) {
if (users == null)
return;
try {
JCacheParams params = new JCacheParams();
params.updater = updater;
users.update(params);
params = null;
} catch (Exception ex) {
log.log(ex, Logger.LEVEL_ERROR);
}
}
use of j.cache.JCacheParams in project JFramework by gugumall.
the class SSOClient method updateLoginStatus.
/**
* @param updater
*/
public static void updateLoginStatus(LoginStatusUpdater updater) {
if (users == null)
return;
_init();
try {
JCacheParams params = new JCacheParams();
params.updater = updater;
users.update(params);
params = null;
} catch (Exception ex) {
log.log(ex, Logger.LEVEL_ERROR);
}
}
Aggregations