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,
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();
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.
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.
>
>
>
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
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