mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -46,7 +46,10 @@ Click here to get the [Latest Version Number](http://search.maven.org/#search%7C
|
||||
* [Identifier](https://github.com/OpenHFT/Chronicle-Map#identifier)
|
||||
* [Port](https://github.com/OpenHFT/Chronicle-Map#port)
|
||||
* [Heart Beat Interval](https://github.com/OpenHFT/Chronicle-Map#heart-beat-interval)
|
||||
* [Clustering](https://github.com/OpenHFT/Chronicle-Map#cluster)
|
||||
* [Clustering](https://github.com/OpenHFT/Chronicle-Map#cluster)
|
||||
|
||||
#### Miscellaneous
|
||||
|
||||
* [Known Issues](https://github.com/OpenHFT/Chronicle-Map#known-issues)
|
||||
* [Stackoverflow](http://stackoverflow.com/tags/chronicle/info)
|
||||
* [Development Tasks - JIRA] (https://higherfrequencytrading.atlassian.net/browse/HCOLL)
|
||||
@@ -54,8 +57,10 @@ Click here to get the [Latest Version Number](http://search.maven.org/#search%7C
|
||||
|
||||
#### Examples
|
||||
|
||||
* [Replicating data between process on different servers with TCP/IP Replication](https://github.com/OpenHFT/Chronicle-Map#example--replicating-data-between-process-on-different-servers)
|
||||
* [Replicating data between process on different servers with UDP] (https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#example--replicating-data-between-process-on-different-servers-using-udp)
|
||||
* [Hello World - A map which stores data off heap](https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#example--simple-hello-world)
|
||||
* [Sharing the map between two ( or more ) processes on the same computer](https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#example--sharing-the-map-on-two--or-more--processes-on-the-same-machine)
|
||||
* [Replicating data between process on different servers with TCP/IP Replication](https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#example--replicating-data-between-process-on-different-servers-via-tcp)
|
||||
* [Replicating data between process on different servers with UDP] (https://github.com/OpenHFT/Chronicle-Map/blob/master/README.md#example--replicating-data-between-process-on-different-servers-using-udp)
|
||||
|
||||
|
||||
#### Performance Topics
|
||||
@@ -593,6 +598,45 @@ will run out of space between 1 and 2 million entries.
|
||||
You should set the .entries(..) and .entrySize(..) to those you require.
|
||||
|
||||
|
||||
# Example : Simple Hello World
|
||||
|
||||
This simple chronicle map, works just like ConcurrentHashMap but stores its data off-heap. If you want to use Chronicle Map to share data between java process you should look at the next exampl
|
||||
|
||||
``` java
|
||||
Map<Integer, CharSequence> map = ChronicleMapBuilder.of(Integer.class,
|
||||
CharSequence.class).create();
|
||||
|
||||
map.put(1, "hello world");
|
||||
System.out.println(map.get(1));
|
||||
|
||||
```
|
||||
|
||||
# Example : Sharing the map on two ( or more ) processes on the same machine
|
||||
|
||||
Lets assume that we had two server, lets call them server1 and server2, if we wished to share a map
|
||||
between them, this is how we could set it up
|
||||
|
||||
``` java
|
||||
|
||||
// --- RUN ON ONE JAVA PROCESS ( BUT ON THE SAME SERVER )
|
||||
{
|
||||
File file = new File("a-new-file-on-your-sever");
|
||||
Map<Integer, CharSequence> map1 = ChronicleMapBuilder.of(Integer.class,
|
||||
CharSequence.class).create(file); // this has to be the same file as used by map 2
|
||||
map1.put(1, "hello world");
|
||||
}
|
||||
|
||||
// --- RUN ON THE OTHER JAVA PROCESS ( BUT ON THE SAME SERVER )
|
||||
{
|
||||
File file = new File("a-new-file-on-your-sever"); // this has to be the same file as used by map 1
|
||||
Map<Integer, CharSequence> map1 = ChronicleMapBuilder.of(Integer.class,
|
||||
CharSequence.class).create(file);
|
||||
|
||||
System.out.println(map1.get(1));
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# Example : Replicating data between process on different servers via TCP
|
||||
|
||||
Lets assume that we had two server, lets call them server1 and server2, if we wished to share a map
|
||||
@@ -617,7 +661,7 @@ Map map2;
|
||||
|
||||
map1 = map1Builder.create();
|
||||
}
|
||||
// ---------- SERVER2 2 on the same server as ----------
|
||||
// ---------- SERVER2 on the same server as ----------
|
||||
|
||||
{
|
||||
TcpReplicationConfig tcpConfig = TcpReplicationConfig.of(8077)
|
||||
|
||||
@@ -823,7 +823,8 @@ public class ChronicleMapBuilder<K, V> implements Cloneable {
|
||||
|
||||
public ChronicleMap<K, V> create() throws IOException {
|
||||
VanillaChronicleMap<K, ?, ?, V, ?, ?> map = newMap();
|
||||
BytesStore bytesStore = new DirectStore(objectSerializer(), map.sizeInBytes(), true);
|
||||
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
|
||||
map.sizeInBytes(), true);
|
||||
map.createMappedStoreAndSegments(bytesStore);
|
||||
return establishReplication(map);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
|
||||
long createMappedStoreAndSegments(File file) throws IOException {
|
||||
return createMappedStoreAndSegments(new MappedStore(file, FileChannel.MapMode.READ_WRITE,
|
||||
sizeInBytes(), objectSerializer));
|
||||
sizeInBytes(), JDKObjectSerializer.INSTANCE));
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.map.serialization;
|
||||
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import net.openhft.lang.io.serialization.JDKObjectSerializer;
|
||||
import net.openhft.chronicle.map.threadlocal.StatefulCopyable;
|
||||
|
||||
final class DirectBytesBuffer implements StatefulCopyable<DirectBytesBuffer> {
|
||||
|
||||
private final Object identity;
|
||||
private DirectBytes buffer;
|
||||
|
||||
DirectBytesBuffer(Object identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
private Bytes buffer(long maxSize) {
|
||||
DirectBytes buf;
|
||||
if ((buf = buffer) != null) {
|
||||
if (maxSize <= buf.capacity()) {
|
||||
return buf.clear();
|
||||
} else {
|
||||
DirectStore store = (DirectStore) buf.store();
|
||||
store.resize(maxSize, false);
|
||||
return buffer = store.bytes();
|
||||
}
|
||||
} else {
|
||||
return buffer = new DirectStore(JDKObjectSerializer.INSTANCE, maxSize, false).bytes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object stateIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectBytesBuffer copy() {
|
||||
return new DirectBytesBuffer(identity);
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ import java.io.IOException;
|
||||
*/
|
||||
public class TestBooleanValues {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
/**
|
||||
* see issue http://stackoverflow.com/questions/26219313/strange-npe-from-chronicle-map-toy-code
|
||||
*/
|
||||
@Test
|
||||
public void testTestBooleanValues() throws IOException, InterruptedException {
|
||||
ChronicleMap<Integer, Boolean> map = ChronicleMapBuilder.of(Integer.class, Boolean.class).create();
|
||||
ChronicleMap<Integer, Boolean> map =
|
||||
ChronicleMapBuilder.of(Integer.class, Boolean.class).create();
|
||||
map.put(7, true);
|
||||
Boolean currentValue = map.get(7); // IllegalStateException here
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user