Search in sources :

Example 11 with JCacheParams

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;
    }
}
Also used : JCacheParams(j.cache.JCacheParams) JUtilString(j.util.JUtilString)

Example 12 with JCacheParams

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;
    }
}
Also used : JCacheParams(j.cache.JCacheParams) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilString(j.util.JUtilString) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 13 with JCacheParams

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;
    }
}
Also used : JCacheParams(j.cache.JCacheParams) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 14 with JCacheParams

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);
    }
}
Also used : JCacheParams(j.cache.JCacheParams)

Example 15 with JCacheParams

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);
    }
}
Also used : JCacheParams(j.cache.JCacheParams)

Aggregations

JCacheParams (j.cache.JCacheParams)16 ConcurrentList (j.util.ConcurrentList)6 List (java.util.List)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 JUtilString (j.util.JUtilString)4 File (java.io.File)2 HttpSession (javax.servlet.http.HttpSession)2 CachedMap (j.cache.CachedMap)1 RemoteException (java.rmi.RemoteException)1 LinkedList (java.util.LinkedList)1