3 Ekim 2021 Pazar

IgniteCompute Arayüzü - Distributed Computing

Giriş
Şu satırı dahil ederiz
import org.apache.ignite.IgniteCompute;
Distributed Computing içindir. Ignite cluster üzerinde bir iş çalıştırabilir ve sonuçları kaydedebiliriz.

constrcutor
Örnek - All Servers
Açıklaması şöyle
Each instance of the compute interface is associated with a set of nodes on which the tasks are executed. When called without arguments, ignite.compute() returns the compute interface that is associated with all server nodes.
Şöyle yaparız
IgniteCache<Integer, String> cache = ignite.cache("myCache");

IgniteCompute compute = ignite.compute();
Sanrım şu kodla aynı şey
ClusterGroup grp = ignite.cluster().forServers();
IgniteCompute ignieCompute = ignite.compute(grp);
Örnek - All Remotes
Açıklaması şöyle
In the following example, the compute interface is bound to the remote nodes only, i.e. all nodes except for the one that runs this code.
Şöyle yaparız
IgniteCache<Integer, String> cache = ignite.cache("myCache");

IgniteCompute compute = ignite.compute(ignite.cluster().forRemotes());
affinityRun metodu
Açıklaması şöyle
The affinityCall(…​) and affinityRun(…​) methods guarantee that the data for the given key or partition is present on the target node for the duration of the task.
Örnek
Şöyle yaparız
IgniteCache<Integer, String> cache = ignite.cache("myCache");

IgniteCompute compute = ignite.compute();

int key = 1;

// This closure will execute on the remote node where
// data for the given 'key' is located.
compute.affinityRun("myCache", key, () -> {
  // Peek is a local memory lookup.
  System.out.println("Co-located [key= " + key + ",value=" + cache.localPeek(key) + ']');
});
Örnek
Şöyle yaparız
public class MyIgniteRunnable implements IgniteRunnable {

  private Sting value;
  private String key;

  public MyIgniteRunnable(String key, String value){
    this.key = key;
    this.value = value;
  }

  @Override
  public void run () {
    IgniteCache<String, String> cache = Ignition.localIgnite().getOrCreateCache("cache");
    String previous = cache.get(key);
    String result;
    //process previous and value
    cache.put(key, result);
  }
}

Ignite ignite = ...;
String key = ...;
String value = ...;
IgniteCompute compute = ignite.compute();
compute.affinityRun("cache", key, new MyIgniteRunnable(key, value));

call metodu - Callable Task İçindir
Örnek ver

run metodu - Runnable Task İçindir
Şöyle yaparız
igniteCompute.run(() ->  System.out.println("Task Executed"));



Hiç yorum yok:

Yorum Gönder

Ignite Transaction Kullanımı

Giriş Bir tablo 3 tane atomicity değerinden birisine sahip olabilir. 1. ATOMIC 2. TRANSACTIONAL 3. TRANSACTIONAL_SNAPSHOT ATOMIC Açıklaması ...