public MappedMemory(MappedByteBuffer buffer, long index) { this.buffer = buffer; this.index = index; bytes = new DirectByteBufferBytes(buffer); }
@Override public long size() { return bytes.capacity(); }
@Override public ByteBuffer sliceAsByteBuffer(ByteBuffer toReuse) { return sliceAsByteBuffer(toReuse, buffer); }
protected DirectByteBufferBytes resize(int newCapacity, boolean cleanup, boolean preserveData) { if (newCapacity != capacity()) { final ByteBuffer oldBuffer = this.buffer; final long oldAddress = this.startAddr; final long oldPosition = position(); setStartPositionAddress(((DirectBuffer) buffer).address()); this.capacityAddr = this.startAddr + newCapacity; this.limitAddr = this.capacityAddr;
protected boolean onRead(final SelectionKey key) throws IOException { try { final long action = readUpTo(8).readLong(); switch ((int) action) { case (int) ChronicleTcp.ACTION_WITH_MAPPING: return onMapping(key, readUpTo(4).readInt()); case (int) ChronicleTcp.ACTION_SUBSCRIBE: return onSubscribe(key, readUpTo(8).readLong()); case (int) ChronicleTcp.ACTION_UNSUBSCRIBE: return onUnsubscribe(key, readUpTo(8).readLong()); case (int) ChronicleTcp.ACTION_QUERY: return onQuery(key, readUpTo(8).readLong()); case (int) ChronicleTcp.ACTION_SUBMIT: return onSubmit(key, readUpTo(8).readLong(), true); case (int) ChronicleTcp.ACTION_SUBMIT_NOACK: return onSubmit(key, readUpTo(8).readLong(), false); default: throw new IOException("Unknown action received (" + action + ")"); } } catch (IOException e) { key.selector().close(); throw e; } }
public void writeAll(final DirectByteBufferBytes bb) throws IOException { writeAll(bb.buffer()); }
protected boolean onMapping(final SelectionKey key, int size) throws IOException { MappingProvider mappingProvider = (MappingProvider) key.attachment(); if (mappingProvider != null) { MappingFunction mappingFunction = readUpTo(size).readObject(MappingFunction.class); mappingProvider.withMapping(mappingFunction); } return true; }
protected DirectByteBufferBytes resize(int newCapacity, boolean cleanup, boolean preserveData) { if(newCapacity != capacity()) { final ByteBuffer oldBuffer = this.buffer; final long oldAddress = this.startAddr; final long oldPosition = position(); setStartPositionAddress(((DirectBuffer) buffer).address()); this.capacityAddr = this.startAddr + newCapacity; this.limitAddr = this.capacityAddr;
public void writeAllOrEOF(final DirectByteBufferBytes bb) throws IOException { writeAllOrEOF(bb.buffer()); }
public MappedMemory(MappedByteBuffer buffer, long index) { this.buffer = buffer; this.index = index; bytes = new DirectByteBufferBytes(buffer); }
@Override public long size() { return bytes.capacity(); }
@Override public ByteBuffer sliceAsByteBuffer(ByteBuffer toReuse) { return sliceAsByteBuffer(toReuse, buffer); }
public static IByteBufferBytes wrap(ByteBuffer buffer) { if (buffer instanceof DirectBuffer) { return new DirectByteBufferBytes(buffer); } return new ByteBufferBytes(buffer.slice()); }
public static IByteBufferBytes wrap(ByteBuffer buffer) { if (buffer instanceof DirectBuffer) { return new DirectByteBufferBytes(buffer); } return new ByteBufferBytes(buffer.slice()); }
public static IByteBufferBytes wrap(ByteBuffer buffer, int start, int capacity) { if (buffer instanceof DirectBuffer) { return new DirectByteBufferBytes(buffer, start, capacity); } return new ByteBufferBytes(buffer.slice(), start, capacity); }
public static IByteBufferBytes wrap(ByteBuffer buffer, int start, int capacity) { if (buffer instanceof DirectBuffer) { return new DirectByteBufferBytes(buffer, start, capacity); } return new ByteBufferBytes(buffer.slice(), start, capacity); }