Search in sources :

Example 16 with ConcurrentList

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;
    }
}
Also used : JHttpContext(j.http.JHttpContext) ConcurrentList(j.util.ConcurrentList) JUtilString(j.util.JUtilString)

Example 17 with ConcurrentList

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

Example 18 with ConcurrentList

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;
}
Also used : ConcurrentList(j.util.ConcurrentList) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilList(j.util.JUtilList)

Example 19 with ConcurrentList

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);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ConcurrentList(j.util.ConcurrentList) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(j.util.ConcurrentMap)

Example 20 with ConcurrentList

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

Aggregations

ConcurrentList (j.util.ConcurrentList)22 ConcurrentMap (j.util.ConcurrentMap)5 JUtilList (j.util.JUtilList)4 List (java.util.List)4 Client (j.service.Client)3 JUtilString (j.util.JUtilString)3 JCacheParams (j.cache.JCacheParams)2 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HttpClient (org.apache.http.client.HttpClient)2 JHttpContext (j.http.JHttpContext)1 Http (j.service.Http)1 Rmi (j.service.Rmi)1 JUtilSorter (j.util.JUtilSorter)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1