Package org.apache.directmemory.memory.allocator

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


        logger.info( "************************************************" );
    }
   
    public void rawInsert( int megabytes, int howMany )
    {
        ByteBufferAllocator allocator = new MergingByteBufferAllocatorImpl( 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


        allocators = new ArrayList<ByteBufferAllocator>( numberOfBuffers );

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

        allocationPolicy.init( allocators );
View Full Code Here

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

            if ( buffer == null )
            {
                continue;
            }

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

            buffer.rewind();
            buffer.put( 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;
        ByteBufferAllocator allocator = null;
        int allocationNumber = 0;
        do
        {
            allocationNumber++;
            allocator = allocationPolicy.getActiveAllocator( allocator, allocationNumber );
            if ( allocator == null )
            {
                if ( returnsNullWhenFull() )
                {
                    return null;
                }
                else
                {
                    throw new BufferOverflowException();
                }
            }

            final ByteBuffer 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

        }

        // Thread safely increment and get the next buffer's index
        int i = incrementAndGetBufferIndex();

        final ByteBufferAllocator allocator = allocators.get( i );

        return allocator;
    }
View Full Code Here

TOP

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

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.