Skip to content

Commit 33f6449

Browse files
committed
[GITFLOW]merging 'release/0.4' into 'master'
2 parents 6bc1ee7 + efa9088 commit 33f6449

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+564
-5543
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.4.0
2+
=====
3+
4+
#15 Refactor serialization to use java.nio.ByteBuffer instead of streams
5+
16
0.3.6
27
=====
38
#11 add putIfAbsentDirect() and addOrReplaceDirect()

ohc-benchmark/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.caffinitas.ohc</groupId>
77
<artifactId>ohc-parent</artifactId>
8-
<version>0.3.6</version>
8+
<version>0.4</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111

1212
<artifactId>ohc-benchmark</artifactId>
13-
<version>0.3.6</version>
13+
<version>0.4</version>
1414

1515
<name>OHC benchmark executable</name>
1616
<description>Off-Heap concurrent hash map intended to store GBs of serialized data</description>
@@ -76,12 +76,12 @@
7676
<dependency>
7777
<groupId>org.caffinitas.ohc</groupId>
7878
<artifactId>ohc-core</artifactId>
79-
<version>0.3.6</version>
79+
<version>0.4</version>
8080
</dependency>
8181
<dependency>
8282
<groupId>org.caffinitas.ohc</groupId>
8383
<artifactId>ohc-core-j8</artifactId>
84-
<version>0.3.6</version>
84+
<version>0.4</version>
8585
</dependency>
8686
<dependency>
8787
<groupId>commons-cli</groupId>

ohc-benchmark/src/main/java/org/caffinitas/ohc/benchmark/BenchmarkUtils.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
import java.io.DataInput;
1919
import java.io.DataOutput;
2020
import java.io.IOException;
21+
import java.nio.ByteBuffer;
2122

2223
import org.caffinitas.ohc.CacheSerializer;
2324

2425
public final class BenchmarkUtils {
2526
public static final CacheSerializer<byte[]> serializer = new CacheSerializer<byte[]>() {
26-
public void serialize(byte[] bytes, DataOutput stream) throws IOException {
27-
stream.writeInt(bytes.length);
28-
stream.write(bytes);
27+
public void serialize(byte[] bytes, ByteBuffer buf) {
28+
buf.putInt(bytes.length);
29+
buf.put(bytes);
2930
}
3031

31-
public byte[] deserialize(DataInput stream) throws IOException {
32-
byte[] bytes = new byte[stream.readInt()];
33-
stream.readFully(bytes);
32+
public byte[] deserialize(ByteBuffer buf) {
33+
byte[] bytes = new byte[buf.getInt()];
34+
buf.get(bytes);
3435
return bytes;
3536
}
3637

@@ -41,14 +42,14 @@ public int serializedSize(byte[] t) {
4142

4243
public static final CacheSerializer<Long> longSerializer = new CacheSerializer<Long>()
4344
{
44-
public void serialize(Long val, DataOutput out) throws IOException
45+
public void serialize(Long val, ByteBuffer buf)
4546
{
46-
out.writeLong(val);
47+
buf.putLong(val);
4748
}
4849

49-
public Long deserialize(DataInput in) throws IOException
50+
public Long deserialize(ByteBuffer buf)
5051
{
51-
return in.readLong();
52+
return buf.getLong();
5253
}
5354

5455
public int serializedSize(Long value)
@@ -66,18 +67,18 @@ public KeySerializer(int keyLen)
6667
this.keyLen = keyLen;
6768
}
6869

69-
public void serialize(Long val, DataOutput out) throws IOException
70+
public void serialize(Long val, ByteBuffer buf)
7071
{
71-
out.writeLong(val);
72+
buf.putLong(val);
7273
for (int i = 0; i < keyLen; i++)
73-
out.write(0);
74+
buf.put((byte)(0 & 0xff));
7475
}
7576

76-
public Long deserialize(DataInput in) throws IOException
77+
public Long deserialize(ByteBuffer buf)
7778
{
78-
long v = in.readLong();
79+
long v = buf.getLong();
7980
for (int i = 0; i < keyLen; i++)
80-
in.readByte();
81+
buf.get();
8182
return v;
8283
}
8384

ohc-core-j8/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.caffinitas.ohc</groupId>
77
<artifactId>ohc-parent</artifactId>
8-
<version>0.3.6</version>
8+
<version>0.4</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111

1212
<artifactId>ohc-core-j8</artifactId>
13-
<version>0.3.6</version>
13+
<version>0.4</version>
1414

1515
<name>OHC core - Java8 optimization</name>
1616
<description>Off-Heap concurrent hash map intended to store GBs of serialized data</description>

ohc-core-j8/src/main/java/org/caffinitas/ohc/linked/UnsExt8.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ long getAndPutLong(long address, long offset, long value)
3131
return unsafe.getAndSetLong(null, address + offset, value);
3232
}
3333

34-
long getAndAddLong(long address, long offset, long value)
35-
{
36-
return unsafe.getAndAddLong(null, address + offset, value);
37-
}
38-
39-
int getAndPutInt(long address, long offset, int value)
40-
{
41-
return unsafe.getAndSetInt(null, address + offset, value);
42-
}
43-
4434
int getAndAddInt(long address, long offset, int value)
4535
{
4636
return unsafe.getAndAddInt(null, address + offset, value);

ohc-core-j8/src/main/java/org/caffinitas/ohc/tables/UnsExt8.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ long getAndPutLong(long address, long offset, long value)
2929
return unsafe.getAndSetLong(null, address + offset, value);
3030
}
3131

32-
long getAndAddLong(long address, long offset, long value)
33-
{
34-
return unsafe.getAndAddLong(null, address + offset, value);
35-
}
36-
37-
int getAndPutInt(long address, long offset, int value)
38-
{
39-
return unsafe.getAndSetInt(null, address + offset, value);
40-
}
41-
4232
int getAndAddInt(long address, long offset, int value)
4333
{
4434
return unsafe.getAndAddInt(null, address + offset, value);

ohc-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>org.caffinitas.ohc</groupId>
77
<artifactId>ohc-parent</artifactId>
8-
<version>0.3.6</version>
8+
<version>0.4</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111

1212
<artifactId>ohc-core</artifactId>
13-
<version>0.3.6</version>
13+
<version>0.4</version>
1414

1515
<name>OHC core</name>
1616
<description>Off-Heap concurrent hash map intended to store GBs of serialized data</description>

ohc-core/src/main/java/org/caffinitas/ohc/CacheSerializer.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,36 @@
1515
*/
1616
package org.caffinitas.ohc;
1717

18-
import java.io.DataInput;
19-
import java.io.DataOutput;
20-
import java.io.IOException;
18+
import java.nio.ByteBuffer;
2119

2220
/**
23-
* Serialize and deserialize cached data using {@link java.io.DataInput} and {@link java.io.DataOutput}.
21+
* Serialize and deserialize cached data using {@link java.nio.ByteBuffer}
2422
*/
2523
public interface CacheSerializer<T>
2624
{
2725
/**
28-
* Serialize the specified type into the specified {@code DataOutput} instance.
26+
* Serialize the specified type into the specified {@code ByteBuffer} instance.
2927
*
3028
* @param t type that needs to be serialized
31-
* @param out {@code DataOutput} into which serialization needs to happen.
29+
* @param buf {@code ByteBuffer} into which serialization needs to happen.
3230
*/
33-
public void serialize(T t, DataOutput out) throws IOException;
31+
void serialize(T t, ByteBuffer buf);
3432

3533
/**
3634
* Deserialize from the specified {@code DataInput} instance.
3735
*
38-
* @param in {@code DataInput} from which deserialization needs to happen.
36+
* @param buf {@code ByteBuffer} from which deserialization needs to happen.
3937
* @return the type that was deserialized
4038
*/
41-
public T deserialize(DataInput in) throws IOException;
39+
T deserialize(ByteBuffer buf);
4240

4341
/**
44-
* Calculate the number of bytes that will be produced by {@link #serialize(Object, java.io.DataOutput)}
42+
* Calculate the number of bytes that will be produced by {@link #serialize(Object, java.nio.ByteBuffer)}
4543
* for given object {@code t}.
4644
*
4745
* @param t object to calculate serialized size for
4846
* @return serialized size of {@code t}
4947
*/
50-
public int serializedSize(T t);
48+
int serializedSize(T t);
5149
}
5250

ohc-core/src/main/java/org/caffinitas/ohc/DirectValueAccess.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,4 @@
2929
public interface DirectValueAccess extends Closeable
3030
{
3131
ByteBuffer buffer();
32-
33-
void abort();
34-
35-
/**
36-
* Similar to {@link #close()} but returns a success result for {@link OHCache#putIfAbsentDirect(Object, long)}
37-
* and {@link OHCache#addOrReplaceDirect(Object, DirectValueAccess, long)}.
38-
*/
39-
boolean commit();
4032
}

ohc-core/src/main/java/org/caffinitas/ohc/OHCache.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,6 @@ public interface OHCache<K, V> extends Closeable
6363

6464
boolean containsKey(K key);
6565

66-
// direct access support
67-
68-
/**
69-
* Adds the key/value.
70-
* If the entry size of key/value exceeds the configured maximum entry length, any previously existing entry
71-
* for the key is removed.
72-
* The entry is visible for other methods, when the returned {@link DirectValueAccess} is closed.
73-
*/
74-
DirectValueAccess putDirect(K key, long valueLen);
75-
76-
/**
77-
* Adds the key/value if no key is present at the time the method is invoked.
78-
* If the entry size of key/value exceeds the configured maximum entry length, any previously existing entry
79-
* for the key is removed.
80-
* The entry is visible for other methods, when the returned {@link DirectValueAccess} is closed.
81-
*
82-
* @return the modifiable byte buffer or {@code null} if a matching key already exists
83-
*/
84-
DirectValueAccess putIfAbsentDirect(K k, long valueLen);
85-
86-
/**
87-
* Adds key/value if either the key is not present or the existing value matches parameter {@code old}.
88-
* If the entry size of key/value exceeds the configured maximum entry length, the old value is removed.
89-
* The entry is visible for other methods, when the returned {@link DirectValueAccess} is closed.
90-
*
91-
* @return the modifiable byte buffer or {@code null} if no matching key exists
92-
*/
93-
DirectValueAccess addOrReplaceDirect(K k, DirectValueAccess old, long valueLen);
94-
9566
/**
9667
* Returns a closeable byte buffer.
9768
* You must close the returned {@link DirectValueAccess} instance after use.
@@ -196,5 +167,5 @@ public interface OHCache<K, V> extends Closeable
196167
* disable the cache, it will continue to work but cannot add more data.
197168
* </p>
198169
*/
199-
public void setCapacity(long capacity);
170+
void setCapacity(long capacity);
200171
}

ohc-core/src/main/java/org/caffinitas/ohc/linked/AbstractDataInput.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)