Package org.apache.directmemory.memory.allocator

Examples of org.apache.directmemory.memory.allocator.Allocator


        allocators = new ArrayList<Allocator>( numberOfBuffers );

        for ( int i = 0; i < numberOfBuffers; i++ )
        {
            final Allocator allocator = instanciateByteBufferAllocator( i, size );
            allocators.add( allocator );
        }

        allocationPolicy.init( allocators );
View Full Code Here


        throws IOException
    {
        Iterator<Allocator> iterator = allocators.iterator();
        while ( iterator.hasNext() )
        {
            Allocator allocator = iterator.next();
            allocator.close();
            iterator.remove();
        }
        used.set( 0 );
    }
View Full Code Here

    @Override
    public Pointer<V> store( byte[] payload, long expiresIn )
    {
        Pointer<V> p = null;
        Allocator allocator = null;
        int allocationNumber = 0;
        do
        {
            allocationNumber++;
            allocator = allocationPolicy.getActiveAllocator( allocator, allocationNumber );
            if ( allocator == null )
            {
                if ( returnsNullWhenFull() )
                {
                    return null;
                }
                else
                {
                    throw new BufferOverflowException();
                }
            }
            final MemoryBuffer buffer = allocator.allocate( payload.length );

            if ( buffer == null )
            {
                continue;
            }

            p = instanciatePointer( buffer, allocator.getNumber(), expiresIn, NEVER_EXPIRES );

            buffer.writerIndex( 0 );
            buffer.writeBytes( payload );

            used.addAndGet( payload.length );
View Full Code Here

    public <T extends V> Pointer<V> allocate( final Class<T> type, final int size, final long expiresIn,
                                              final long expires )
    {

        Pointer<V> p = null;
        Allocator allocator = null;
        int allocationNumber = 0;
        do
        {
            allocationNumber++;
            allocator = allocationPolicy.getActiveAllocator( allocator, allocationNumber );
            if ( allocator == null )
            {
                if ( returnsNullWhenFull() )
                {
                    return null;
                }
                else
                {
                    throw new BufferOverflowException();
                }
            }

            final MemoryBuffer buffer = allocator.allocate( size );

            if ( buffer == null )
            {
                continue;
            }

            p = instanciatePointer( buffer, allocator.getNumber(), expiresIn, NEVER_EXPIRES );

            used.addAndGet( size );
        }
        while ( p == null );
View Full Code Here

        logger.info( "************************************************" );
    }
   
    public void rawInsert( int megabytes, int howMany )
    {
        Allocator allocator = new MergingByteBufferAllocator( 1, megabytes * 1024 * 1024 );
        assertNotNull( allocator );
        int size = allocator.getCapacity() / ( howMany );
        size -= size / 100 * 1;
        logger.info( "payload size=" + size );
        logger.info( "entries=" + howMany );

        logger.info( "starting..." );

        long start = System.currentTimeMillis();

        for ( int i = 0; i < howMany; i++ )
        {
            allocator.allocate( size );
        }

        logger.info( "...done in " + ( System.currentTimeMillis() - start ) + " msecs." );
        logger.info( "---------------------------------" );
        dump( allocator );
View Full Code Here

TOP

Related Classes of org.apache.directmemory.memory.allocator.Allocator

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.