You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by abondar <av...@yandex.ru> on 2016/02/01 08:01:14 UTC

Client<->Server communication

There is already running Ignite cluster on remote hosts. default-config.xml
contains:
- peerClassLoadingEnabled=true
- TcpDiscoveryVmIpFinder.addresses contains list of all host IPs

I am going to create the tool which performs tasks on remote hosts.
Is the code below right way to perform such communication:

Ignition.setClientMode(true);
Ignite ignite = Ignition.start();
IgniteCompute compute = ignite.compute(ignite.cluster().forRemotes());

compute.broadcast(
 () -> {
   System.out.println("info request from client");
   final String currentDirOnRemoteHost = new File("./").getAbsolutePath();
   Ignite ignite1 = Ignition.ignite();
   ignite1.compute(ignite1.cluster().forClients()).broadcast(
      () -> {
         //sending a response to client
         System.out.println("info response: currentDirOnRemoteHost=" +
currentDirOnRemoteHost);
      }
   );
});




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Client-Server-communication-tp2788.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Client<->Server communication

Posted by Denis Magda <dm...@gridgain.com>.
Hi, 

There is no need to send a reply to the client in a way you do.

There are versions of Ignite Compute's broadcast and other methods that
return computation result to the caller.

In your particular case you can send the broadcast and process the response
this way

        Collection<String> result = compute.broadcast(new
IgniteCallable<String>() {
            @IgniteInstanceResource
            Ignite ignite;

            @Override public String call() throws Exception {
                return new File("./").getAbsolutePath();
            }
        });

        for (String res : result)
            //process result

Please refer to additional Ignite Compute examples [1] that showcase how
this API can be used in an optimal way.

[1]
https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/computegrid

Regards,
Denis



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Client-Server-communication-tp2788p2790.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.