Examples of ICacheElement


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

                        while ( itr.hasNext() )
                        {
                            Map.Entry entry = (Map.Entry) itr.next();

                            ICacheElement ce = (ICacheElement) entry.getValue();

                            aux.update( ce );
                        }
                    }
                }
View Full Code Here

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

        IElementSerializer elementSerializer = new StandardSerializer();

        IElementAttributes attr = new ElementAttributes();
        attr.setMaxLifeSeconds( 34 );

        ICacheElement before = new CacheElement( cacheName, key, value );
        before.setElementAttributes( attr );

        ICacheElementSerialized serialized = SerializationConversionUtil.getSerializedCacheElement( before,
                                                                                                    elementSerializer );
        assertNotNull( "Should have a serialized object.", serialized );
        System.out.println( "testSimpleConversion, " + serialized );

        ICacheElement after = SerializationConversionUtil.getDeSerializedCacheElement( serialized, elementSerializer );

        assertNotNull( "Should have a deserialized object.", after );
        assertEquals( "Values should be the same.", before.getVal(), after.getVal() );
        assertEquals( "Attributes should be the same.", before.getElementAttributes().getMaxLifeSeconds(), after
            .getElementAttributes().getMaxLifeSeconds() );
        assertEquals( "Keys should be the same.", before.getKey(), after.getKey() );
        assertEquals( "Cache name should be the same.", before.getCacheName(), after.getCacheName() );

    }
View Full Code Here

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

        IElementSerializer elementSerializer = null;// new StandardSerializer();

        IElementAttributes attr = new ElementAttributes();
        attr.setMaxLifeSeconds( 34 );

        ICacheElement before = new CacheElement( cacheName, key, value );
        before.setElementAttributes( attr );

        try
        {
            SerializationConversionUtil.getSerializedCacheElement( before, elementSerializer );
            fail( "We should have received an IOException." );
View Full Code Here

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

        if ( log.isDebugEnabled() )
        {
            log.debug( logCacheName + "Trying to get from disk: " + key );
        }

        ICacheElement object = null;
        try
        {
            storageLock.readLock().acquire();
            try
            {
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

        if ( log.isDebugEnabled() )
        {
            log.debug( "in cache get(key,container)" );
        }

        ICacheElement ce = null;
        boolean found = false;

        try
        {

            if ( log.isDebugEnabled() )
            {
                log.debug( "get: key = " + key + ", is local invocation = "
                     + ( invocation == this.LOCAL_INVOKATION ) );
            }

            ce = ( ICacheElement ) memCache.get( key, true );

            if ( ce == null )
            {
                // Item not found in memory.  Try the auxiliary caches if local.

                for ( int i = 0; i < auxCaches.length; i++ )
                {
                    ICache aux = auxCaches[i];

                    if ( aux != null )
                    {

                        if ( ( invocation == this.LOCAL_INVOKATION ) || aux.getCacheType() == aux.DISK_CACHE )
                        {
                            if ( log.isDebugEnabled() )
                            {
                                log.debug( "get(key,container,invocation) > in local block, aux.getCacheType() = " + aux.getCacheType() );
                            }

                            try
                            {
                                ce = ( ICacheElement ) aux.get( key, true );
                            }
                            catch ( IOException ex )
                            {
                                handleException( ex );
                            }
                        }

                        if ( log.isDebugEnabled() )
                        {
                            log.debug( "ce = " + ce );
                        }

                        if ( ce != null )
                        {
                            found = true;
                            // Item found in one of the auxiliary caches.
                            auxHit[i]++;

                            if ( log.isDebugEnabled() )
                            {
                                log.debug( cacheName + " -- AUX[" + i + "]-HIT for " + key );
                                log.debug( "ce.getKey() = " + ce.getKey() );
                                log.debug( "ce.getVal() = " + ce.getVal() );
                            }

                            memCache.update( ce );

                            break;
                        }
                    }
                    // end for
                }
                // end if invocation = LOCAL

            }
            else
            {
                found = true;
                ramHit++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- RAM-HIT for " + key );
                }
            }

        }
        catch ( Exception e )
        {
            log.error( e );
        }

        try
        {

            if ( !found )
            {
                // Item not found in all caches.
                miss++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- MISS for " + key );
                }
                return null;
                //throw new ObjectNotFoundException( key + " not found in cache" );
            }
        }
        catch ( Exception e )
        {
            log.error( "Error handling miss", e );
            return null;
        }

        // HUB Manages expiration
        try
        {

            if ( !ce.getElementAttributes().getIsEternal() )
            {

                long now = System.currentTimeMillis();

                // Exceeded maxLifeSeconds
                if ( ( ce.getElementAttributes().getMaxLifeSeconds() != -1 ) && ( now - ce.getElementAttributes().getCreateTime() ) > ( ce.getElementAttributes().getMaxLifeSeconds() * 1000 ) )
                {
                    if ( log.isInfoEnabled() )
                    {
                        log.info( "Exceeded maxLifeSeconds -- " + ce.getKey() );
                    }
                    this.remove( key );
                    //cache.remove( me.ce.getKey() );
                    return null;
                }
                else
                // NOT SURE IF THIS REALLY BELONGS HERE.  WHAT IS THE
                // POINT OF IDLE TIME?  SEEMS OK
                // Exceeded maxIdleTime, removal
                    if ( ( ce.getElementAttributes().getIdleTime() != -1 ) && ( now - ce.getElementAttributes().getLastAccessTime() ) > ( ce.getElementAttributes().getIdleTime() * 1000 ) )
                {
                    if ( log.isInfoEnabled() )
                    {
                        log.info( "Exceeded maxIdleTime [ ce.getElementAttributes().getIdleTime() = " + ce.getElementAttributes().getIdleTime() + " ]-- " + ce.getKey() );
                    }
                    this.remove( key );
                    //cache.remove( me.ce.getKey() );
                    return null;
                }
            }

        }
        catch ( Exception e )
        {
            log.error( "Error determining expiration period", e );
            return null;
        }

        if ( container )
        {
            return ce;
        }
        else
        {
            return ce.getVal();
        }

    }
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

     * @exception IOException
     */
    public Serializable sendAndReceive( LateralElementDescriptor led )
        throws IOException
    {
        ICacheElement ice = null;

        log.debug( "sendAndReceive led" );

        if ( led == null )
        {
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

     */
    public Serializable get( Serializable key, boolean container )
        throws IOException
    {
        MemoryElementDescriptor me = null;
        ICacheElement ce = null;
        boolean found = false;

        try
        {
            if ( log.isDebugEnabled() )
            {
                log.debug( "get: key = " + key );
            }

            me = ( MemoryElementDescriptor ) map.get( key );
            if ( log.isDebugEnabled() )
            {
                log.debug( "me =" + me );
            }

            if ( me == null )
            {

            }
            else
            {
                found = true;
                ce = me.ce;
                //ramHit++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- RAM-HIT for " + key );
                }
            }

        }
        catch ( Exception e )
        {
            log.error( e );
        }

        try
        {

            if ( !found )
            {
                // Item not found in all caches.
                //miss++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- MISS for " + key );
                }
                return null;
                //throw new ObjectNotFoundException( key + " not found in cache" );
            }
        }
        catch ( Exception e )
        {
            log.error( "Error handling miss", e );
            return null;
        }

        try
        {
            ce.getElementAttributes().setLastAccessTimeNow();
            makeFirst( me );
        }
        catch ( Exception e )
        {
            log.error( "Error making first", e );
            return null;
        }

        if ( container )
        {
            return ce;
        }
        else
        {
            return ce.getVal();
        }

    }
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

     * @exception IOException
     */
    public Serializable sendAndReceive( LateralElementDescriptor led )
        throws IOException
    {
        ICacheElement ice = null;

        log.debug( "sendAndReceive led" );

        if ( led == null )
        {
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

                for ( int i = 0; i < chunkSizeCorrected; i++ )
                {
                    // Might want to rename this "overflow" incase the hub
                    // wants to do something else.
                    Serializable last = ( Serializable ) mrulist.getLast();
                    ICacheElement ceL = ( ICacheElement ) map.get( last );
                    hub.spoolToDisk( ceL );

                    // need a more fine grained locking here
                    synchronized ( map )
                    {
View Full Code Here

Examples of org.apache.stratum.jcs.engine.behavior.ICacheElement

     */
    public Serializable get( Serializable key, boolean container )
        throws IOException
    {

        ICacheElement ce = null;
        boolean found = false;

        try
        {

            if ( log.isDebugEnabled() )
            {
                log.debug( "get> key=" + key );
                log.debug( "get> key=" + key.toString() );
            }

            ce = ( ICacheElement ) map.get( key );
            if ( log.isDebugEnabled() )
            {
                log.debug( "ce =" + ce );
            }

            if ( ce == null )
            {

            }
            else
            {
                found = true;
                ce.getElementAttributes().setLastAccessTimeNow();
                //ramHit++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- RAM-HIT for " + key );
                }
            }

        }
        catch ( Exception e )
        {
            log.error( e );
        }

        try
        {

            if ( !found )
            {
                // Item not found in all caches.
                //miss++;
                if ( log.isDebugEnabled() )
                {
                    log.debug( cacheName + " -- MISS for " + key );
                }
                return null;
                //throw new ObjectNotFoundException( key + " not found in cache" );
            }
        }
        catch ( Exception e )
        {
            log.error( "Error handling miss", e );
            return null;
        }

        try
        {
            synchronized ( lockMe )
            {
                mrulist.remove( ce.getKey() );
                mrulist.addFirst( ce.getKey() );
            }
        }
        catch ( Exception e )
        {
            log.error( "Error making first", e );
            return null;
        }

        if ( container )
        {
            return ce;
        }
        else
        {
            return ce.getVal();
        }

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.