HAZELCAST WITH JPPF, CONFIGURATION

34 views
Skip to first unread message

omsvit123

unread,
Dec 21, 2009, 8:21:56 AM12/21/09
to Hazelcast
Hello everyone,
First question:
I'm sharing a map with hazelcast between different nodes of JPPF. This
is the source code:
/-------------------------------------------------------------------------------------------/
package javaapplication47;

import java.util.concurrent.atomic.AtomicBoolean;
import org.jppf.node.NodeRunner;
import com.hazelcast.core.*;
import java.io.Serializable;
import org.jppf.server.protocol.JPPFRunnable;

// Sample task using a Hazelcast distributed queue.
public class Tarea implements EntryListener, Serializable {

private AtomicBoolean conditionReached = new AtomicBoolean(false);

@JPPFRunnable
public void run(int i) throws InterruptedException {
System.out.println("Entrando" + i);
try {
getMap().addEntryListener(this, true);
if (!getMap().isEmpty()) {
return;
}
if (!conditionReached.get()) {
Thread.sleep(20);
System.out.println("Numero" + i);
// if condition is reached by this task
if (i == 5000) {
// put an item in the queue to notify other tasks
and nodes
conditionReached.set(true);
getMap().put("CondicionAtomica",
conditionReached);
}
}
} finally {
getMap().removeEntryListener(this);
}
}

protected IMap<String, AtomicBoolean> getMap() {
String key = "mapaDistribuido";
//Obtenemos el mapa distribuido
IMap<String, AtomicBoolean> mapaDistribuido = (IMap<String,
AtomicBoolean>) NodeRunner.getPersistentData(key);
if (mapaDistribuido == null) {
mapaDistribuido = Hazelcast.getMap(key);
NodeRunner.setPersistentData(key, mapaDistribuido);
}
return mapaDistribuido;
}

public void entryAdded(EntryEvent arg0) {
conditionReached.set(true);
}

public void entryRemoved(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

public void entryUpdated(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

public void entryEvicted(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
/---------------------------------------------------------------------------------/


Everything works fine when I run two nodes on the same machine.
The problem is when I use another computer, hazelcast not detect
members of the nodes thats run in the new machine.
Why can it be? How can I fix this programacticaly?

***********************************************

Second question:
How can I delete the shared map, once the execution of the program is
finish.

Thank you in advance,

Talip Ozturk

unread,
Dec 25, 2009, 1:18:30 AM12/25/09
to hazelcast
> Everything works fine when I run two nodes on the same machine.
> The problem is when I use another computer, hazelcast not detect
> members of the nodes thats run in the new machine.
> Why can it be? How can I fix this programacticaly?

Did you check if multicast is enabled on the machines and network?
Did you also try cluster via TCP/IP only?
http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigFullTcpIp

> Second question:
> How can I delete the shared map, once the execution of the program is
> finish.

Map sharedMap = Hazelcast.getMap("mysharedmap");
sharedMap.destroy();

omsvit123

unread,
Dec 25, 2009, 8:29:36 AM12/25/09
to Hazelcast
> > Everything works fine when I run two nodes on the same machine.
> > The problem is when I use another computer, hazelcast not detect
> > members of the nodes thats run in the new machine.
> > Why can it be? How can I fix this programacticaly?
>
> Did you check if multicast is enabled on the machines and network?
> Did you also try cluster via TCP/IP only?http://code.google.com/docreader/#p=hazelcast&s=hazelcast&t=ConfigFul...

I preferred to leave the default settings. Mainly for a reason:
1 .- The nodes can be connected JPPF randomly. In other words, need
not be all conectandos at first. At minute 0 of execution can be 10
nodes connected, and at 1 minute, 50 nodes.

I looked at the configuration file, and multicast is enabled.
How can I check if the multicast is enable in the network?
The TCP/IP I think that in my case could not use it, for the reason
that I explained to you.
If I am confused on something please let me know.

Any piece of code might prove helpful.

Thank you very much for answering so fast.

Talip Ozturk

unread,
Dec 26, 2009, 6:45:29 PM12/26/09
to hazelcast
Your system admin guy should be able to answer if machines can
send/receive multicast.

1. multicast routing should be enabled on the machines.
on linux "route add -net 224.0.0.0 netmask 224.0.0.0 eth0"

2. turn off the firewalls on the machines (or make sure firewall
doesn't block multicast)
on linux "service iptables stop" (better talk to your system admin to
configure it in a way that it can receive multicast)
on windows look for windows firewall and also check if you have other
security software disabling multicast.

3. multicast should be enabled on the switch that machines are connected to.
talk to your network guy for this.

also google for multicast troubleshooting.

if you cannot get it to work then create an issue for it at
http://code.google.com/p/hazelcast/issues/list

-talip

> --
>
> You received this message because you are subscribed to the Google Groups "Hazelcast" group.
> To post to this group, send email to haze...@googlegroups.com.
> To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.
>
>
>

omsvit123

unread,
Jan 3, 2010, 5:30:20 PM1/3/10
to Hazelcast
Sorry for the inconvenience but I have another problem .What happens
is that If you start the program at second time, conditionReached
stays true (for the entryListener). And I wish it would be false,
every time when you start the program. How can I do it? an example
code would be nice.

Talip Ozturk

unread,
Jan 4, 2010, 2:18:06 AM1/4/10
to hazelcast
On Mon, Jan 4, 2010 at 12:30 AM, omsvit123 <omsv...@terra.es> wrote:
>What happens
> is that If you start the program at second time,

you mean you completely shutdown your program and start it again?

> conditionReached
> stays true (for the entryListener). And I wish it would be false,
> every time when you start the program. How can I do it? an example
> code would be nice.

we don't have conditionReached variable. if you shutdown and started
your application how come your conditionReached variable stays true?
Obviously I am missing something.

-talip

omsvit123

unread,
Jan 4, 2010, 5:02:16 PM1/4/10
to Hazelcast
> you mean you completely shutdown your program and start it again?
Yes it is.

First of all sorry for my explanation, my English is very bad.

If you look at my first post, you can see the code of which I speak.

I think the problem is in the EntryListener. In the method "run" when
i = 800 all nodes detect this and leave the program early and this is
all correct.
The problem is whe I run it at second time, because all nodes finish
their execution quickly before reaching 800.
The second problem I have is: When parallel execution is finish, what
I want is to turn off hazelcast. But it do not work correctly.
Here is the complete code:
public class Main {

public static void main(String[] args) {

JPPFClient client = null;


try {
client = new JPPFClient();

JPPFJob job = new JPPFJob();
Tarea t = new Tarea();

for (int i = 1; i <= 1000; i++) {
job.addTask(t, i);
}

List<JPPFTask> results = client.submit(job);


} catch (Exception e) {
e.printStackTrace();
} finally {
//This not work properly
System.out.println("Apagando...");
Hazelcast.shutdownAll();
System.out.println("Apagado");
client.close();
System.exit(0);
}
}
}

public class Tarea implements EntryListener, Serializable {

private AtomicBoolean conditionReached = new AtomicBoolean(false);

@JPPFRunnable
public void run(int i) throws InterruptedException {
System.out.println("Entrando" + i);
try {
getMap().addEntryListener(this, true);
if (!getMap().isEmpty()) {
return;
}
if (!conditionReached.get()) {

System.out.println("Numero" + i);


// if condition is reached by this task

if (i == 500) {
System.out.println("Encontrado");


// put an item in the queue to notify other tasks
and nodes
conditionReached.set(true);
getMap().put("CondicionAtomica",
conditionReached);
}
}
} finally {
getMap().removeEntryListener(this);
}
}


protected IMap<String, AtomicBoolean> getMap() {
String key = "mapaDistribuido";
//Obtenemos el mapa distribuido
IMap<String, AtomicBoolean> mapaDistribuido = (IMap<String,
AtomicBoolean>) NodeRunner.getPersistentData(key);
if (mapaDistribuido == null) {
mapaDistribuido = Hazelcast.getMap(key);
NodeRunner.setPersistentData(key, mapaDistribuido);
}
return mapaDistribuido;
}

public void entryAdded(EntryEvent arg0) {
conditionReached.set(true);
}

public void entryRemoved(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

public void entryUpdated(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

public void entryEvicted(EntryEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
}


Thanks for your patience

Talip Ozturk

unread,
Jan 4, 2010, 5:24:54 PM1/4/10
to hazelcast
Hard to say what you are running into. I don't know much about JPPF
but I can try it for you. Can you please come up with complete test
code that I can run very easily? Please send it to me directly (talip
at hazelcast dot com)

-talip

omsvit123

unread,
Jan 4, 2010, 8:27:25 PM1/4/10
to Hazelcast

Thanks so much. I've long attempted to resolve this error. I'll make a
zip file with everything. Only you have to have Apache Ant installed.
Thanks for answering so fast, your help will mean the advancement of
my project.
Reply all
Reply to author
Forward
0 new messages