mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Revert 'Make working with new bytes' and a couple of fixes
This commit is contained in:
@@ -18,50 +18,48 @@
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.ReadAccess;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import net.openhft.lang.io.serialization.JDKObjectSerializer;
|
||||
|
||||
import static net.openhft.chronicle.hash.impl.JavaLangBytesAccessors.uncheckedBytesAccessor;
|
||||
public abstract class CopyingInstanceData<I> extends AbstractData<I> {
|
||||
|
||||
public abstract class CopyingInstanceData<I, T> extends AbstractData<I, T> {
|
||||
private final JavaLangBytesReusableBytesStore bytesStore =
|
||||
new JavaLangBytesReusableBytesStore();
|
||||
|
||||
public static DirectBytes getBuffer(DirectBytes b, long capacity) {
|
||||
public DirectBytes getBuffer(DirectBytes b, long capacity) {
|
||||
if (b != null) {
|
||||
if (b.capacity() >= capacity) {
|
||||
return (DirectBytes) b.clear();
|
||||
} else {
|
||||
DirectStore store = (DirectStore) b.store();
|
||||
store.resize(capacity, false);
|
||||
return store.bytes();
|
||||
DirectBytes bytes = store.bytes();
|
||||
bytesStore.setBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
} else {
|
||||
return new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, capacity), true)
|
||||
.bytes();
|
||||
DirectBytes bytes = new DirectStore(JDKObjectSerializer.INSTANCE,
|
||||
Math.max(1, capacity), true).bytes();
|
||||
bytesStore.setBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return bytesStore;
|
||||
}
|
||||
|
||||
public abstract I instance();
|
||||
|
||||
public abstract DirectBytes buffer();
|
||||
|
||||
@Override
|
||||
public ReadAccess<T> access() {
|
||||
//noinspection unchecked
|
||||
return (ReadAccess<T>) uncheckedBytesAccessor(buffer()).access(buffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T handle() {
|
||||
//noinspection unchecked
|
||||
return (T) uncheckedBytesAccessor(buffer()).handle(buffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return uncheckedBytesAccessor(buffer()).offset(buffer(), 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Access;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
enum JavaLangBytesAccess implements Access<Bytes> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public byte readByte(Bytes handle, long offset) {
|
||||
return handle.readByte(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(Bytes handle, long offset) {
|
||||
return handle.readShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char readChar(Bytes handle, long offset) {
|
||||
return handle.readChar(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(Bytes handle, long offset) {
|
||||
return handle.readInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(Bytes handle, long offset) {
|
||||
return handle.readLong(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeByte(Bytes handle, long offset, byte i8) {
|
||||
handle.writeByte(offset, i8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeShort(Bytes handle, long offset, short i) {
|
||||
handle.writeShort(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChar(Bytes handle, long offset, char c) {
|
||||
handle.writeChar(offset, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInt(Bytes handle, long offset, int i) {
|
||||
handle.writeInt(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLong(Bytes handle, long offset, long i) {
|
||||
handle.writeLong(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFloat(Bytes handle, long offset, float d) {
|
||||
handle.writeFloat(offset, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDouble(Bytes handle, long offset, double d) {
|
||||
handle.writeDouble(offset, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteOrder byteOrder(Bytes handle) {
|
||||
return handle.byteOrder();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Access;
|
||||
import net.openhft.chronicle.bytes.Accessor;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
|
||||
import static net.openhft.chronicle.bytes.Access.nativeAccess;
|
||||
|
||||
public final class JavaLangBytesAccessors {
|
||||
|
||||
public static Accessor.Full<Bytes, ?> uncheckedBytesAccessor(Bytes bytes) {
|
||||
return bytes instanceof NativeBytes ? GenericBytesAccessor.INSTANCE :
|
||||
GenericBytesAccessor.INSTANCE;
|
||||
}
|
||||
|
||||
enum NativeBytesAccessor implements Accessor.Full<Bytes, Void> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Access<Void> access(Bytes source) {
|
||||
return nativeAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void handle(Bytes source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset(Bytes source, long index) {
|
||||
return source.address() + index;
|
||||
}
|
||||
}
|
||||
|
||||
enum GenericBytesAccessor implements Accessor.Full<Bytes, Bytes> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Access<Bytes> access(Bytes source) {
|
||||
return JavaLangBytesAccess.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bytes handle(Bytes source) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset(Bytes source, long index) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
private JavaLangBytesAccessors() {}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class JavaLangBytesReusableBytesStore
|
||||
implements BytesStore<JavaLangBytesReusableBytesStore, Void> {
|
||||
|
||||
private Bytes bytes;
|
||||
|
||||
public void setBytes(Bytes bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesStore<JavaLangBytesReusableBytesStore, Void> copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long capacity() {
|
||||
return bytes.capacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long address() throws UnsupportedOperationException {
|
||||
return bytes.address();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void underlyingObject() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapInt(long offset, int expected, int value) {
|
||||
return bytes.compareAndSwapInt(offset, expected, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapLong(long offset, long expected, long value) {
|
||||
return bytes.compareAndSwapLong(offset, expected, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte(long offset) {
|
||||
return bytes.readByte(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(long offset) {
|
||||
return bytes.readShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(long offset) {
|
||||
return bytes.readInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(long offset) {
|
||||
return bytes.readLong(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat(long offset) {
|
||||
return bytes.readFloat(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble(long offset) {
|
||||
return bytes.readDouble(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nativeRead(long position, long address, long size) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeByte(long offset, byte i8) {
|
||||
bytes.writeByte(offset, i8);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeShort(long offset, short i) {
|
||||
bytes.writeShort(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeInt(long offset, int i) {
|
||||
bytes.writeInt(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeOrderedInt(long offset, int i) {
|
||||
bytes.writeOrderedInt(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeLong(long offset, long i) {
|
||||
bytes.writeLong(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeOrderedLong(long offset, long i) {
|
||||
bytes.writeOrderedLong(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeFloat(long offset, float d) {
|
||||
bytes.writeFloat(offset, d);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeDouble(long offset, double d) {
|
||||
bytes.writeDouble(offset, d);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore write(long offsetInRDO,
|
||||
byte[] bs, int offset, int length) {
|
||||
bytes.write(offsetInRDO, bs, offset, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(long offsetInRDO, ByteBuffer bb, int offset, int length) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore write(long offsetInRDO,
|
||||
RandomDataInput input, long offset, long length) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nativeWrite(long address, long position, long size) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reserve() throws IllegalStateException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() throws IllegalStateException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long refCount() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package net.openhft.chronicle.hash.impl.value.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
|
||||
public interface KeyInitableData<K, T> extends Data<K, T> {
|
||||
public interface KeyInitableData<K> extends Data<K> {
|
||||
|
||||
void initKey(K key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user