Package org.apache.jcs.engine.behavior

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


        disk.doRemoveAll();

        int cnt = 25;
        for ( int i = 0; i < cnt; i++ )
        {
            IElementAttributes eAttr = new ElementAttributes();
            eAttr.setIsSpool( true );
            ICacheElement element = new CacheElement( cattr.getCacheName(), "key:" + i, "data:" + i );
            element.setElementAttributes( eAttr );
            disk.doUpdate( element );
        }

        long preAddRemoveSize = disk.getDataFileSize();

        IElementAttributes eAttr = new ElementAttributes();
        eAttr.setIsSpool( true );
        ICacheElement elementSetup = new CacheElement( cattr.getCacheName(), "key:" + "A", "data:" + "A" );
        elementSetup.setElementAttributes( eAttr );
        disk.doUpdate( elementSetup );

        ICacheElement elementRet = disk.doGet( "key:" + "A" );
View Full Code Here


                log.debug( "Keys size: " + size );
            }

            Serializable key;
            ICacheElement cacheElement;
            IElementAttributes attributes;

            int spoolCount = 0;

            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 ) )
                {
                    if ( !spoolLimit || ( spoolCount < this.maxSpoolPerRun ) )
                    {

                        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

     *             If an error occurs
     */
    private void handleElementEvents( ICacheElement cacheElement, int eventType )
        throws IOException
    {
        IElementAttributes attributes = cacheElement.getElementAttributes();

        ArrayList eventHandlers = attributes.getElementEventHandlers();

        if ( eventHandlers != null )
        {
            if ( log.isDebugEnabled() )
            {
View Full Code Here

     *
     * @param props
     */
    protected void setDefaultElementAttributes( Properties props )
    {
        IElementAttributes iea = parseElementAttributes( props, "", CompositeCacheConfigurator.DEFAULT_REGION );
        compositeCacheManager.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 = new CompositeCache( regName, cca, ea );

        // Next, create the auxiliaries for the new cache
View Full Code Here

     * @param regionPrefix
     * @return IElementAttributes
     */
    protected IElementAttributes parseElementAttributes( Properties props, String regName, String regionPrefix )
    {
        IElementAttributes eAttr;

        String attrName = regionPrefix + regName + CompositeCacheConfigurator.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 )
        {
            if ( log.isInfoEnabled() )
            {
                log.info( "No special ElementAttribute class defined for key [" + attrName + "], using default class." );
            }

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

        if ( log.isDebugEnabled() )
        {
            log.debug( "Parsing options for '" + attrName + "'" );
View Full Code Here

                        else
                        {
                            long n_start = System.currentTimeMillis();
                            for ( int n = 0; n < num; n++ )
                            {
                                IElementAttributes attrp = cache_control.getDefaultElementAttributes();
                                ElementEventHandlerMockImpl hand = new ElementEventHandlerMockImpl();
                                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
                        {

                            long n_start = System.currentTimeMillis();
                            cache_control.put( key, val );
                            long n_end = System.currentTimeMillis();
                            p( "---put " + key + " | " + val + " in " + String.valueOf( n_end - n_start )
                                + " millis ---" );
                        }
                    }
                    /////////////////////////////////////////////////////////////////////
                    if ( message.startsWith( "removem" ) )
                    {
                        String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
                        int num = Integer.parseInt( numS.trim() );
                        if ( numS == null )
                        {
                            p( "usage: removem numbertoremove" );
                        }
                        else
                        {
                            removeMultiple( num );
                        }
                    }

                    else if ( message.startsWith( "removeall" ) )
                    {
                        cache_control.clear();
                        p( "removed all" );
                    }
                    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.getDefaultElementAttributes();
                        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

     * @exception CacheException
     */
    public IElementAttributes getElementAttributes( Object name )
        throws CacheException
    {
        IElementAttributes attr = null;

        try
        {
            attr = this.cacheControl.getElementAttributes( (Serializable) name );
        }
View Full Code Here

        access = CacheAccess.getAccess( "test" );

        assertNotNull( "We should have an access class", access );

        long maxLife = 9876;
        IElementAttributes attr = new ElementAttributes();
        attr.setMaxLifeSeconds( maxLife );

        access.setDefaultElementAttributes( attr );

        assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
            .getMaxLifeSeconds() );

        String key = "mykey";
        String value = "myvalue";
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.