Package org.apache.jcs.engine.behavior

Examples of org.apache.jcs.engine.behavior.IElementAttributes


      key = groupAttrName;
    }

    ICacheElement cacheElement = new CacheElement(CACHE_NAME, key,
        cacheEntry.value);
    IElementAttributes attributes = cache.getElementAttributes().copy();
    cacheElement.setElementAttributes(attributes);

    cache.update(cacheElement);
    return key;
  }
View Full Code Here


    Serializable newKey = getKey(key, cachingModel);
    ICacheElement newCacheElement = new CacheElement(cache.getCacheName(),
        newKey, obj);

    IElementAttributes elementAttributes = cache.getElementAttributes().copy();
    newCacheElement.setElementAttributes(elementAttributes);

    try {
      cache.update(newCacheElement);
View Full Code Here

        Arrays.sort( keys );

        LinkedList records = new LinkedList();

        ICacheElement element;
        IElementAttributes attributes;
        CacheElementInfo elementInfo;

        DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT,
                                                            DateFormat.SHORT );

        long now = System.currentTimeMillis();

        for ( int i = 0; i < keys.length; i++ )
        {
            element =
                cache.getMemoryCache().getQuiet( (Serializable) keys[ i ] );

            attributes = element.getElementAttributes();

            elementInfo = new CacheElementInfo();

            elementInfo.key = String.valueOf( keys[ i ] );
            elementInfo.eternal = attributes.getIsEternal();
            elementInfo.maxLifeSeconds = attributes.getMaxLifeSeconds();

            elementInfo.createTime =
                format.format( new Date( attributes.getCreateTime() ) );

            elementInfo.expiresInSeconds =
                ( now - attributes.getCreateTime()
                    - ( attributes.getMaxLifeSeconds() * 1000 ) ) / -1000;

            records.add( elementInfo );
        }

        return records;
View Full Code Here

    private boolean isExpired( ICacheElement element )
    {
        try
        {
            IElementAttributes attributes = element.getElementAttributes();

            if ( !attributes.getIsEternal() )
            {
                long now = System.currentTimeMillis();

                // Remove if maxLifeSeconds exceeded

                long maxLifeSeconds = attributes.getMaxLifeSeconds();
                long createTime = attributes.getCreateTime();

                if ( maxLifeSeconds != -1
                     && ( now - createTime ) > ( maxLifeSeconds * 1000 ) )
                {
                    if ( log.isDebugEnabled() )
                    {
                        log.debug( "Exceeded maxLife: " + element.getKey() );
                    }

                    return true;
                }
                else
                {
                    long idleTime = attributes.getIdleTime();
                    long lastAccessTime = attributes.getLastAccessTime();

                    // Remove if maxIdleTime exceeded
                    // FIXME: Does this really belong here?

                    if ( ( idleTime != -1 )
View Full Code Here

    }

    /** Set the default ElementAttributes for new caches. */
    protected void setDefaultElementAttributes( Properties props )
    {
        IElementAttributes iea =
            parseElementAttributes( props, "", this.DEFAULT_REGION );
        ccMgr.setDefaultElementAttributes( iea );

        log.info( "setting defaultElementAttributes to " + iea );
    }
View Full Code Here

        if ( cca == null )
        {
            cca = parseCompositeCacheAttributes( props, regName, regionPrefix );
        }

        IElementAttributes ea = parseElementAttributes( props, regName, regionPrefix );

        CompositeCache cache = null;
        if ( regionPrefix.equals( SYSTEM_REGION_PREFIX ) )
        {
            //cache = ccMgr.createSystemCache( regName, auxCaches, cca, new ElementAttributes() );
View Full Code Here

    protected IElementAttributes
        parseElementAttributes( Properties props,
                                String regName,
                                String regionPrefix )
    {
        IElementAttributes eAttr;

        String attrName = regionPrefix + regName + this.ELEMENT_ATTRIBUTE_PREFIX;

        // auxFactory was not previously initialized.
        //String prefix = regionPrefix + regName + ATTRIBUTE_PREFIX;
        eAttr = ( IElementAttributes ) OptionConverter.instantiateByKey( props, attrName,
                                                                         org.apache.jcs.engine.behavior.IElementAttributes.class,
                                                                         null );
        if ( eAttr == null )
        {
            log.warn( "Could not instantiate eAttr named '" + attrName +
                      "', using defaults." );

            IElementAttributes eAttr2 = ccMgr.getDefaultElementAttributes();
            eAttr = eAttr2.copy();
        }

        log.debug( "Parsing options for '" + attrName + "'" );

        PropertySetter.setProperties( eAttr, props, attrName + "." );
View Full Code Here

//                            attrp.setIsRemote(true);

                            long n_start = System.currentTimeMillis();
                            for ( int n = 0; n < num; n++ )
                            {
                                IElementAttributes attrp = cache_control.getElementAttributes();
                                TestElementEventHandler hand = new TestElementEventHandler();
                                attrp.addElementEventHandler( hand );
                                cache_control.put( "key" + n,
                                    "data" + n + " put from ta = junk", attrp );
                            }
                            long n_end = System.currentTimeMillis();
                            p( "---put " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
                        }
                    }
                    else
                        if ( message.startsWith( "put" ) )
                    {

                        String key = null;
                        String val = null;
                        StringTokenizer toke = new StringTokenizer( message );
                        int tcnt = 0;
                        while ( toke.hasMoreElements() )
                        {
                            tcnt++;
                            String t = ( String ) toke.nextElement();
                            if ( tcnt == 2 )
                            {
                                key = t.trim();
                            }
                            else
                                if ( tcnt == 3 )
                            {
                                val = t.trim();
                            }
                        }

                        if ( tcnt < 3 )
                        {
                            p( "usage: put key val" );
                        }
                        else
                        {
//                            IElementAttributes attrp = new ElementAttributes();
//                            attrp.setIsLateral(true);
//                            attrp.setIsRemote(true);
                            long n_start = System.currentTimeMillis();
//                            cache_control.put( key, val, attrp.copy() );
                            cache_control.put( key, val );
                            long n_end = System.currentTimeMillis();
                            p( "---put " + key + " | " + val + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
                        }
                    }
                    else
                        if ( message.startsWith( "remove" ) )
                    {
                        String key = message.substring( message.indexOf( " " ) + 1, message.length() );
                        cache_control.remove( key );
                        p( "removed " + key );
                    }
                    else
                        if ( message.startsWith( "deattr" ) )
                    {
                        IElementAttributes ae = cache_control.getElementAttributes( );
                        p( "Default IElementAttributes " + ae );
                    }
                    else
                        if ( message.startsWith( "cloneattr" ) )
                    {
                        String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
                        int num = Integer.parseInt( numS.trim() );
                        if ( numS == null )
                        {
                            p( "usage: put numbertoput" );
                        }
                        else
                        {
                            IElementAttributes attrp = new ElementAttributes();
                            long n_start = System.currentTimeMillis();
                            for ( int n = 0; n < num; n++ )
                            {
                                attrp.copy();
                            }
                            long n_end = System.currentTimeMillis();
                            p( "---cloned attr " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
                        }
                    }
View Full Code Here

            Object[] keys = cache.getKeyArray();
            int size = keys.length;

            Serializable key;
            ICacheElement cacheElement;
            IElementAttributes attributes;

            for ( int i = 0; i < size; i++ )
            {
                key = ( Serializable ) keys[ i ];
                cacheElement = cache.getQuiet( key );

                if ( cacheElement == null )
                {
                    continue;
                }

                attributes = cacheElement.getElementAttributes();

                boolean remove = false;

                long now = System.currentTimeMillis();

                // Useful, but overkill even for DEBUG since it is written for
                // every element in memory
                //
                // if ( log.isDebugEnabled() )
                // {
                //     log.debug( "IsEternal: " + attributes.getIsEternal() );
                //     log.debug( "MaxLifeSeconds: "
                //                + attributes.getMaxLifeSeconds() );
                //     log.debug( "CreateTime:" + attributes.getCreateTime() );
                // }

                // If the element is not eternal, check if it should be
                // removed and remove it if so.

                if ( !cacheElement.getElementAttributes().getIsEternal() )
                {
                    remove = checkForRemoval( cacheElement, now );

                    if ( remove )
                    {
                        cache.remove( cacheElement.getKey() );
                    }
                }

                // If the item is not removed, check is it has been idle
                // long enough to be spooled.

                if ( !remove && ( maxMemoryIdleTime != -1 ) )
                {
                    final long lastAccessTime = attributes.getLastAccessTime();

                    if ( lastAccessTime + maxMemoryIdleTime < now )
                    {
                        if ( log.isDebugEnabled() )
                        {
View Full Code Here

     * @throws IOException
     */
    private boolean checkForRemoval( ICacheElement cacheElement, long now )
        throws IOException
    {
        IElementAttributes attributes = cacheElement.getElementAttributes();

        final long maxLifeSeconds = attributes.getMaxLifeSeconds();
        final long createTime = attributes.getCreateTime();

        // Check if maxLifeSeconds has been exceeded
        if ( maxLifeSeconds != -1 && now - createTime > maxLifeSeconds * 1000 )
        {
            if ( log.isInfoEnabled() )
            {
                log.info( "Exceeded maxLifeSeconds: " + cacheElement.getKey() );
            }

            handleElementEvents( cacheElement, IElementEventConstants
                .ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND );

            return true;
        }

        final long idleTime = attributes.getIdleTime();
        final long lastAccessTime = attributes.getLastAccessTime();

        // Check maxIdleTime has been exceeded
        if ( idleTime != -1 && now - lastAccessTime > idleTime * 1000 )
        {
            if ( log.isInfoEnabled() )
View Full Code Here

TOP

Related Classes of org.apache.jcs.engine.behavior.IElementAttributes

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.