Package javax.util.jcache

Examples of javax.util.jcache.Attributes


        return getTrueObject(objHandle, arguments);
    }

    private Object getTrueObject(final CacheObject objHandle, final Object arguments) {
        if (objHandle.needsLoading(arguments)) {
            Attributes attribs = objHandle.getAttributes();
            CacheLoader loader = attribs.getLoader();
            Object retrievedObject;
            try {
                retrievedObject = loader.load(objHandle, arguments);
                if (retrievedObject == null) {
                    throw new ObjectNotFoundException("The returned object from the CacheLoader " + loader.getClass().getName() + " was null.");
                }
                if (retrievedObject instanceof CacheOutputStream) {
                    /*
                     * a CacheLoader has created an OutputStream, and loaded the
                     * object. Get the owner object for the stream, and return
                     * the corresponding InputStream. The StreamObjects are
                     * created in the CacheLoader, but the regular memory
                     * objects are created below, is this correct? And a double
                     * creation is also done... once before the load, and once
                     * further down, but this is not called as we have multiple
                     * return points in this method.... well, if it works, dont
                     * touch it! Refactor when we are moving towards a
                     * production release.
                     * 
                     */
                    return ((CacheOutputStream) retrievedObject).getStreamObject().getInputStream();
                } else if (retrievedObject instanceof File) {
                    /*
                     * The object was a DiskObject, return the path to the
                     * diskfile.
                     */
                    return ((File) retrievedObject).getAbsolutePath();
                }
                attribs.setCreateTime(System.currentTimeMillis());
            } catch (CacheException e) {
                this.lastException  = e.getClass();
                this.lastMessage = e.getMessage();
                return null;
            }
View Full Code Here


     */
    public void resetAttributes(Attributes attributes) {
        if (!isValid()) {
            return;
        }
        Attributes att = region.getAttributes();
        att.reset();
        att.applyAttributes(attributes);
    }
View Full Code Here

     */
    public void resetAttributes(Object name, Attributes attributes) {
        if (!isValid()) {
            return;
        }
        Attributes att = CacheImpl.getCache(true).getRegion(name).getAttributes();
        att.reset();
        att.applyAttributes(attributes);
    }
View Full Code Here

     *         it is not initialized, or it is unavailable.
     */
    public void defineRegion(final String name)
        throws ObjectExistsException, NullObjectNameException,
            CacheNotAvailableException {
        Attributes att = CacheAccessFactory.getInstance().getDefaultAttributes();
        defineRegion(name, att);
    }
View Full Code Here

     */
    public void defineRegion(final String name, final Attributes attributes)
        throws ObjectExistsException, NullObjectNameException,
            CacheNotAvailableException {
    CacheImpl cache = CacheImpl.getCache(true);
    Attributes lAttribs=attributes;
    if(lAttribs==null) lAttribs=CacheAccessFactory.getInstance().getDefaultAttributes();
    cache.addRegion(name, lAttribs);
    }
View Full Code Here

            return true;
        }
        return false;
    }
  private boolean hasExpired(CacheObject obj) throws NullObjectException {
    Attributes attributes = obj.getAttributes();
    if(attributes==null) throw new NullObjectException("A null attributes was detected.");
    /*-1 is the default for attributes, and the default is
     * non invalidation, so if the ttl is -1, the objects remains in the cache.
     */

    if(attributes.getTimeToLive()==-1) {
      return false;
    }
    if(attributes.getLoader()!=null) return false;
    long now = System.currentTimeMillis();
    long timealive = (now - attributes.getCreateTime()) / 1000;

    //only ttl is support for now. the rest of the params can be implemented later.
    if (timealive >= attributes.getTimeToLive()) {
      return true;
    }
    return false;
  }
View Full Code Here

    private CacheObjectInfoImpl impl;
    private static final long TTL = 5;
   
    protected void setUp() throws Exception {
        testObj = new CacheObject("key", "value", new CacheGroup("group"), new CacheRegion("name", new AttributesImpl()), null);
       Attributes att = CacheAccessFactory.getInstance().getDefaultAttributes();
       att.setTimeToLive(TTL);
        testObj.setAttributes(att);
        impl = new CacheObjectInfoImpl(testObj);
       
    }
View Full Code Here

    }

    public final void testGetExpire() throws ParseException {
        SimpleDateFormat form = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
       
        Attributes att = testObj.getAttributes();
        //TTL in seconds
        long ttl = att.getTimeToLive();
        //createtime in millis
        long createTime = att.getCreateTime();
        //expiry is in second precision, lets round ouf our own.
        long expire = form.parse(impl.getExpire()).getTime();
        long expectedExpiry = form.parse(form.format(new Date((ttl*1000)+createTime))).getTime();
        assertEquals(expectedExpiry, expire);
        //check that objects which never expire, never expire....
        CacheObject obj = new CacheObject("key", "value", null, null, null);
        Attributes att1 = CacheAccessFactory.getInstance().getDefaultAttributes();
        obj.setAttributes(att1);
        CacheObjectInfoImpl imp = new CacheObjectInfoImpl(obj);
        assertEquals(CacheObjectInfo.NEVER_EXPIRES, imp.getExpire());
       
    }
View Full Code Here

TOP

Related Classes of javax.util.jcache.Attributes

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.