Search in sources :

Example 6 with JCacheParams

use of j.cache.JCacheParams in project JFramework by gugumall.

the class OnlinesCluster method getActiveUsers.

/**
 * @param rpp
 * @param pn
 * @return
 */
public static List getActiveUsers(int rpp, int pn) {
    JCacheParams params = new JCacheParams();
    params.recordsPerPage = rpp;
    params.pageNum = pn;
    try {
        return onlines.values(params);
    } catch (Exception e) {
        log.log(e, Logger.LEVEL_ERROR);
        return new ConcurrentList();
    }
}
Also used : JCacheParams(j.cache.JCacheParams) ConcurrentList(j.util.ConcurrentList) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 7 with JCacheParams

use of j.cache.JCacheParams in project JFramework by gugumall.

the class SSOServer method findLoginStatusOfUserId.

/**
 * @param userId
 * @return
 */
public static LoginStatus[] findLoginStatusOfUserId(String userId) {
    if (userId == null || userId.equals(""))
        return null;
    try {
        List temp = users.values(new JCacheParams(new LoginStatusFilter(userId)));
        LoginStatus[] arr = new LoginStatus[temp.size()];
        temp.toArray(arr);
        return arr;
    } catch (Exception e) {
        log.log(e, Logger.LEVEL_ERROR);
    }
    return null;
}
Also used : JCacheParams(j.cache.JCacheParams) List(java.util.List) ConcurrentList(j.util.ConcurrentList)

Example 8 with JCacheParams

use of j.cache.JCacheParams in project JFramework by gugumall.

the class SSOServer method run.

/*
	 *  (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    while (true) {
        try {
            Thread.sleep(15000);
        } catch (Exception ex) {
        }
        if (!SSOConfig.isServer())
            continue;
        // 注销过期用户
        try {
            JCacheParams params = new JCacheParams();
            params.valueFilter = LoginStatusRemover.getInstance();
            List values = users.values(params);
            for (int i = 0; i < values.size(); i++) {
                LoginStatus loginStatus = (LoginStatus) values.get(i);
                if (loginStatus != null && loginStatus.isTimeout()) {
                    // 超时
                    try {
                        // 注销
                        logout(SSOConfig.getSsoClientByIdOrUrl(loginStatus.getClientId()), loginStatus);
                    } catch (Exception e) {
                    }
                    if (loginStatus != null)
                        loginStatus = null;
                }
            }
            values.clear();
            values = null;
            users.remove(params);
            params = null;
        } catch (Exception ex) {
            log.log(ex, Logger.LEVEL_ERROR);
        }
    }
}
Also used : JCacheParams(j.cache.JCacheParams) List(java.util.List) ConcurrentList(j.util.ConcurrentList)

Example 9 with JCacheParams

use of j.cache.JCacheParams in project JFramework by gugumall.

the class SSOServer method logout.

/**
 * 注销sso server端信息并通知sso client端注销
 * @param client
 * @param loginStatus
 * @throws Exception
 */
private static void logout(Client client, LoginStatus loginStatus) throws Exception {
    HttpSession session = SSOContext.getSession(loginStatus.getSessionId());
    if (session != null) {
        // 移除session中保存的全局会话ID
        try {
            session.removeAttribute(Constants.SSO_GLOBAL_SESSION_ID);
        } catch (Exception e) {
            log.log(e.getMessage(), Logger.LEVEL_INFO);
        }
    }
    // 从缓存中清除
    users.remove(new JCacheParams(loginStatus.getUserId()));
    users.remove(new JCacheParams(loginStatus.getGlobalSessionId()));
    // 当前操作的SSO Client直接发送注销命令
    // SSONotifier.getNotifier(client).logout(client,
    // loginStatus.getGlobalSessionId(),
    // loginStatus.getUserId(),
    // loginStatus.getUserIp());
    // 其它SSO Client通过通知线程发送注销命令
    ConcurrentList ssoClients = SSOConfig.getSsoClients();
    for (int i = 0; i < ssoClients.size(); i++) {
        Client c = (Client) ssoClients.get(i);
        // if(c.getId().equals(client.getId())) continue;//当前操作的SSO Client直接发送注销命令
        SSONotifier.addTask(c, loginStatus.getGlobalSessionId(), loginStatus.getUserId(), loginStatus.getUserIp(), SSONotifier.type_logout);
    }
    // set to null
    loginStatus = null;
}
Also used : JCacheParams(j.cache.JCacheParams) HttpSession(javax.servlet.http.HttpSession) ConcurrentList(j.util.ConcurrentList)

Example 10 with JCacheParams

use of j.cache.JCacheParams in project JFramework by gugumall.

the class RdbmsDao method autoIncreaseKey.

public String autoIncreaseKey(String table, String column, 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 (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)

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