Skip to content

Instantly share code, notes, and snippets.

View enesakar's full-sized avatar

Enes Akar enesakar

View GitHub Profile
<aws enabled="true">
<access-key>YOUR_ACCESS_KEY</access-key>
<secret-key>YOUR_SECRET_KEY</secret-key>
</aws>
public static void main(String[] args) {
Map mymap = Hazelcast.getMap("mymap");
try {
while (true) {
for (int i = 0; i < 1000; i++) {
mymap.put(System.currentTimeMillis(), new Byte[100000]);
Thread.sleep(1);
}
System.out.println("Current Map Size:" + mymap.size());
}
Config cfg = new FileSystemXmlConfig("C:\\java\\hazelcast.xml");
Hazelcast.init(cfg);
<map name="default">
<backup-count>1</backup-count>
<time-to-live-seconds>0</time-to-live-seconds>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="cluster_wide_map_size">3000</max-size>
<eviction-percentage>25</eviction-percentage>
<merge-policy>hz.ADD_NEW_ENTRY</merge-policy>
</map>
<map name="default">
<backup-count>1</backup-count>
<time-to-live-seconds>10</time-to-live-seconds>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="cluster_wide_map_size">0</max-size>
<eviction-percentage>25</eviction-percentage>
<merge-policy>hz.ADD_NEW_ENTRY</merge-policy>
</map>
@enesakar
enesakar / gist:2005322
Created March 9, 2012 06:19
hazelcast eviction example
public static void main(String[] args) throws FileNotFoundException {
try {
Config cfg = new FileSystemXmlConfig("C:\\java\\hazelcast.xml");
Hazelcast.init(cfg);
Map mymap = Hazelcast.getMap("mymap");
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 1000; i++) {
mymap.put(System.currentTimeMillis(), new Byte[100000]);
Thread.sleep(1);
public static void main(String[] args) throws FileNotFoundException {
try {
// Config cfg = new FileSystemXmlConfig("C:\\java\\hazelcast.xml");
// Hazelcast.init(cfg);
IMap mymap = Hazelcast.getMap("mymap");
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 1000; i++) {
if (i % 2 == 0)
mymap.put(System.currentTimeMillis(), new Byte[100000], 10, TimeUnit.SECONDS);
@enesakar
enesakar / gist:2290803
Created April 3, 2012 10:07
Use hazelcast map with Grails/Groovy
def map = hazelService.map("customers")
map.put("john", new Customer(name: "John", age: 27))
map["mike"] = new Customer(name: "Mike", age: 27)
// try putting with timeout
map.tryPut("alex", new Customer(name: "Alex", age: 23), 1, TimeUnit.SECONDS)
// put object with TTL (time to live)
map.put("mary", new Customer(name: "Mary", age: 45), 100, TimeUnit.SECONDS)
println map.size()
println map["mary"].age
class Customer implements Serializable {
String name
Integer age
static constraints = {
}
String toString() {
"name:${name}, age:${age}"
}
}
class Server1Controller {
def hazelService
def index = {
def cs = new Customer()
cs.name = "tom"
cs.age = 20
def customers = hazelService.queue("customers")
customers << cs