use of net.openhft.lang.io.ByteBufferBytes in project HugeCollections-OLD by peter-lawrey.
the class TCPSocketReplicationIntValueTest method setup.
@Before
public void setup() throws IOException {
value = new IntValue$$Native();
value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
map1 = newTcpSocketShmIntValueString((byte) 1, 8076, new InetSocketAddress("localhost", 8077));
map2 = newTcpSocketShmIntValueString((byte) 2, 8077);
}
use of net.openhft.lang.io.ByteBufferBytes in project HugeCollections-OLD by peter-lawrey.
the class IntValueMapTest method test.
@Test
@Ignore
public void test() throws IOException {
final SharedHashMap<IntValue, CharSequence> map = new SharedHashMapBuilder().entries(1000).entries(20000).file(getPersistenceFile()).kClass(IntValue.class).vClass(CharSequence.class).create();
IntValue$$Native value = new IntValue$$Native();
value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
value.setValue(1);
final String expected = "test";
map.put(value, expected);
final CharSequence actual = map.get(value);
assertEquals(expected, actual);
// this will fail
map.toString();
}
use of net.openhft.lang.io.ByteBufferBytes 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);
}
Aggregations