Search in sources :

Example 1 with BytesDataLocator

use of net.openhft.chronicle.sandbox.queue.locators.shared.BytesDataLocator in project HugeCollections-OLD by peter-lawrey.

the class ConcurrentBlockingObjectQueueBuilder method create.

public BlockingQueue<E> create() throws IOException {
    final DataLocator dataLocator;
    final RingIndex ringIndex;
    if (type == Type.LOCAL) {
        ringIndex = new LocalRingIndex();
        dataLocator = new LocalDataLocator(capacity);
    } else if (type == Type.SHARED) {
        final String tmp = System.getProperty("java.io.tmpdir");
        final File file = new File(tmp + fileName);
        if (deleteOnExit)
            file.deleteOnExit();
        int ringIndexLocationsStart = 0;
        int ringIndexLocationsLen = SIZE_OF_INT * 2;
        int storeLen = capacity * align(maxSize, 4);
        final MappedStore ms = new MappedStore(file, FileChannel.MapMode.READ_WRITE, ringIndexLocationsLen + storeLen);
        final DirectBytes ringIndexSlice = ms.bytes(ringIndexLocationsStart, ringIndexLocationsLen);
        ringIndex = new SharedRingIndex(ringIndexSlice);
        // provides an index to the data in the ring buffer, the size of this index is proportional to the capacity of the ring buffer
        final DirectBytes storeSlice = ms.bytes(ringIndexLocationsLen, storeLen);
        dataLocator = new SharedLocalDataLocator(capacity, maxSize, storeSlice, clazz);
    } else if (type == Type.REMOTE_PRODUCER || type == Type.REMOTE_CONSUMER) {
        final int bufferSize = capacity * align(maxSize, 4);
        final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize).order(ByteOrder.nativeOrder());
        final ByteBufferBytes byteBufferBytes = new ByteBufferBytes(buffer);
        final BytesDataLocator<E, ByteBufferBytes> bytesDataLocator = new BytesDataLocator<E, ByteBufferBytes>(clazz, capacity, maxSize, byteBufferBytes.slice(), byteBufferBytes.slice());
        if (type == Type.REMOTE_PRODUCER) {
            final Producer producer = new Producer<E, ByteBufferBytes>(new LocalRingIndex(), bytesDataLocator, bytesDataLocator, new ServerSocketChannelProvider(port), bytesDataLocator, buffer);
            ringIndex = producer;
            dataLocator = producer;
        } else {
            ringIndex = new Consumer<ByteBufferBytes>(new LocalRingIndex(), bytesDataLocator, bytesDataLocator, new ClientSocketChannelProvider(port, host), buffer);
            dataLocator = bytesDataLocator;
        }
    } else {
        throw new IllegalArgumentException("Unsupported Type=" + type);
    }
    return new ConcurrentBlockingObjectQueue<E>(ringIndex, dataLocator);
}
Also used : SharedLocalDataLocator(net.openhft.chronicle.sandbox.queue.locators.shared.SharedLocalDataLocator) LocalDataLocator(net.openhft.chronicle.sandbox.queue.locators.local.LocalDataLocator) DataLocator(net.openhft.chronicle.sandbox.queue.locators.DataLocator) BytesDataLocator(net.openhft.chronicle.sandbox.queue.locators.shared.BytesDataLocator) ClientSocketChannelProvider(net.openhft.chronicle.sandbox.queue.locators.shared.remote.channel.provider.ClientSocketChannelProvider) SharedRingIndex(net.openhft.chronicle.sandbox.queue.locators.shared.SharedRingIndex) DirectBytes(net.openhft.lang.io.DirectBytes) ServerSocketChannelProvider(net.openhft.chronicle.sandbox.queue.locators.shared.remote.channel.provider.ServerSocketChannelProvider) SharedRingIndex(net.openhft.chronicle.sandbox.queue.locators.shared.SharedRingIndex) LocalRingIndex(net.openhft.chronicle.sandbox.queue.locators.local.LocalRingIndex) RingIndex(net.openhft.chronicle.sandbox.queue.locators.RingIndex) ByteBuffer(java.nio.ByteBuffer) Producer(net.openhft.chronicle.sandbox.queue.locators.shared.remote.Producer) SharedLocalDataLocator(net.openhft.chronicle.sandbox.queue.locators.shared.SharedLocalDataLocator) ByteBufferBytes(net.openhft.lang.io.ByteBufferBytes) SharedLocalDataLocator(net.openhft.chronicle.sandbox.queue.locators.shared.SharedLocalDataLocator) LocalDataLocator(net.openhft.chronicle.sandbox.queue.locators.local.LocalDataLocator) LocalRingIndex(net.openhft.chronicle.sandbox.queue.locators.local.LocalRingIndex) BytesDataLocator(net.openhft.chronicle.sandbox.queue.locators.shared.BytesDataLocator) File(java.io.File) MappedStore(net.openhft.lang.io.MappedStore)

Aggregations

File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 DataLocator (net.openhft.chronicle.sandbox.queue.locators.DataLocator)1 RingIndex (net.openhft.chronicle.sandbox.queue.locators.RingIndex)1 LocalDataLocator (net.openhft.chronicle.sandbox.queue.locators.local.LocalDataLocator)1 LocalRingIndex (net.openhft.chronicle.sandbox.queue.locators.local.LocalRingIndex)1 BytesDataLocator (net.openhft.chronicle.sandbox.queue.locators.shared.BytesDataLocator)1 SharedLocalDataLocator (net.openhft.chronicle.sandbox.queue.locators.shared.SharedLocalDataLocator)1 SharedRingIndex (net.openhft.chronicle.sandbox.queue.locators.shared.SharedRingIndex)1 Producer (net.openhft.chronicle.sandbox.queue.locators.shared.remote.Producer)1 ClientSocketChannelProvider (net.openhft.chronicle.sandbox.queue.locators.shared.remote.channel.provider.ClientSocketChannelProvider)1 ServerSocketChannelProvider (net.openhft.chronicle.sandbox.queue.locators.shared.remote.channel.provider.ServerSocketChannelProvider)1 ByteBufferBytes (net.openhft.lang.io.ByteBufferBytes)1 DirectBytes (net.openhft.lang.io.DirectBytes)1 MappedStore (net.openhft.lang.io.MappedStore)1