Package net.sf.cache4j

Examples of net.sf.cache4j.CacheException


        }
        if(cacheConfig.getCacheId()==null) {
            throw new NullPointerException("config.getCacheId() is null");
        }
        if(!(cache instanceof Cache)) {
            throw new CacheException("cache not instance of "+ManagedCache.class.getName());
        }

        synchronized(_cacheMap){
            if(_cacheMap.containsKey(cacheConfig.getCacheId())) {
                throw new CacheException("Cache id:"+cacheConfig.getCacheId()+" exists");
            }

            _cacheMap.put(cacheConfig.getCacheId(), cache);
        }
    }
View Full Code Here


        int objSize = 0;
        try {
            objSize = _config.getMaxMemorySize()>0 ? Utils.size(obj) : 0;
        } catch (IOException e) {
            throw new CacheException(e.getMessage());
        }

        //��������� �� ��������� �� ������������ ����
        checkOverflow(objSize);

        if (tlCO==null) {
            //���� � ������� ������ ��� CacheObject ������ ����� get() ����� ����
            //��� �� ��������� ��� ������ ������
            co = getCacheObject(objId);
        } else {
            //���� � ������� ������ ���� ������ ������ ����� ���� ����� get() ������ null

            //������������� �� �������� ������ � ������������� ����������� ������� ������ ����
            //�����������. ���� ��� �� ��� �� ��� ������ ������ get() ��� ������� ���� ����
            //� ��� ������ ������ put() ��� ������� ������ ����, � ��� �����������.
            if(tlCO.getObjectId().equals(objId)){
                //����� �� ��������� ����������� � ������ get() ������
                //����� ������ ���������� ������ ������������ ��� ���������� ���������
                co = tlCO;
                //������� ������ �� �������� ������ ����� ������ ����� �����������
                //������ ������ put()
                _tl.set(null);
            } else {
                tlCO.unlock();
                throw new CacheException("Cache:"+_config.getCacheId()+" wait for call put() with objId="+tlCO.getObjectId());
            }
        }

        co.lock();
        _cacheInfo.incPut();
View Full Code Here

            throw new NullPointerException("objId is null");
        }

        CacheObject tlCO = (CacheObject)_tl.get();
        if (tlCO!=null) {
            throw new CacheException("Cache:"+_config.getCacheId()+" wait for call put() with objId="+tlCO.getObjectId());
        }

        CacheObject co = getCacheObject(objId);
        co.lock();
        Object o = co.getObject();
View Full Code Here

        //���� �� ������� ������� �������� ������ ������ ����� put() �� ��� ������
        //����� ���� ��� get() ������ null
        CacheObject tlCO = (CacheObject)_tl.get();
        if (tlCO!=null) {
            throw new CacheException("Cache:"+_config.getCacheId()+" wait for call put() with objId="+tlCO.getObjectId());
        }

        CacheObject co = null;//getCacheObject(objId);
        synchronized (this) {
            co = (CacheObject)_map.get(objId);
View Full Code Here

            //System.out.println(""+this.hashCode()+" GET LOCK Thread:"+Thread.currentThread().getName()+" "+(_lockThread!=null));
            _lockThread = Thread.currentThread(); //������������� ����������� �����
        } catch (InterruptedException ex) {
            notify();      //��� � ��� ���� �������
            //notifyAll(); //��������� ��� ������
            throw new CacheException(ex.getMessage());
        }
    }
View Full Code Here

            NodeList nodeList = document.getChildNodes();
            Node node = nodeList==null || nodeList.getLength()==0 ? null : nodeList.item(0);

            //�������� ���� ������ ���������� cache-config
            if (node==null || !"cache-factory".equalsIgnoreCase(node.getNodeName())) {
                throw new CacheException("root node must be \"cache-factory\"");
            }

            if ((node instanceof Element)) {
                long cleanInteval = getTimeLong(((Element)node).getAttribute("clean-interval"));
                if(cleanInteval>0){
                    cf.setCleanInterval(cleanInteval);
                } else {
                    //�� ��������� 30 ������
                    cf.setCleanInterval(30000); //30sec
                }
            }

            for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
                if ((n instanceof Element) && "cache".equalsIgnoreCase(n.getNodeName())) {
                    Cache cache = null;
                    CacheConfig config = null;

                    String id = ((Element)n).getAttribute("id");
                    String desc = ((Element)n).getAttribute("desc");
                    long ttl = getTimeLong(((Element)n).getAttribute("ttl"));
                    long idle = getTimeLong(((Element)n).getAttribute("idle"));
                    long maxMemorySize = getCapacityLong(((Element)n).getAttribute("max-memory-size"));
                    int maxSize = getInt(((Element)n).getAttribute("max-size"));

                    String type = ((Element)n).getAttribute("type");
                    if(type==null || type.trim().length()==0){
                        type = "synchronized";
                    }
                    type = type.trim().toLowerCase();
                    if(type.equals("blocking")){
                        cache = new BlockingCache();
                    } else if(type.equals("synchronized")) {
                        cache = new SynchronizedCache();
                    } else if(type.equals("nocache")) {
                        cache = new EmptyCache();
                    } else {
                        throw new CacheException("Unknown cache type:"+type);
                    }

                    String algorithm = ((Element)n).getAttribute("algorithm");
                    if(algorithm==null || algorithm.trim().length()==0){
                        algorithm = "lru";
                    }
                    algorithm = algorithm.trim().toLowerCase();
                    if(!algorithm.equals(CacheConfigImpl.LRU) &&
                       !algorithm.equals(CacheConfigImpl.LFU) &&
                       !algorithm.equals(CacheConfigImpl.FIFO) ) {
                        throw new CacheException("Unknown cache algorithm:"+algorithm);
                    }

                    String reference = ((Element)n).getAttribute("reference");
                    if(reference==null || reference.trim().length()==0){
                        reference = "strong";
                    }
                    reference = reference.trim().toLowerCase();
                    if(!reference.equals("strong") && !reference.equals("soft") ) {
                        throw new CacheException("Unknown cache object reference:"+reference);
                    }

                    config = new CacheConfigImpl(id, desc, ttl, idle, maxMemorySize, maxSize, type, algorithm, reference);
                    ((ManagedCache)cache).setCacheConfig(config);

                    cf.addCache(cache);
                }
            }

        } catch (SAXParseException e) {
            String msg = "Parsing error, line " + e.getLineNumber() + ", uri " + e.getSystemId()+"\n"+
                         "   " + e.getMessage();
            throw new CacheException(msg);
        } catch (Exception e) {
            throw new CacheException(e.getMessage());
        }
    }
View Full Code Here

        //��������� ������ �������
        int objSize = 0;
        try {
            objSize = _config.getMaxMemorySize()>0 ? Utils.size(obj) : 0;
        } catch (IOException e) {
            throw new CacheException(e.getMessage());
        }

        //��������� �� ����� �� ������������ ����� ��������� �������
        checkOverflow(objSize);
View Full Code Here

TOP

Related Classes of net.sf.cache4j.CacheException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.