Giriş
Şu satırı dahil ederiz
import com.hazelcast.core.Hazelcast;
bootstrappedInstance metodu
Bence bu metodun tek amacı Jet Job içinde kullanmak.
Örnek
Şöyle yaparız. Böylece Job client içinden de yüklense, member içinden de yüklense çalışabilir.
Pipeline pipeline = ... HazelcastInstance hz = Hazelcast.bootstrappedInstance(); hz.getJet().newJob(pipeline);
getAllHazelcastInstances metodu
Şöyle yaparız
Set<HazelcastInstance> instances = Hazelcast.getAllHazelcastInstances(); HazelcastInstance hz = instances.stream().findFirst().get(); Map map = hz.getMap("mapName"); // shared distributed map
getOrCreateHazelcastInstance metodu
İmzası şöyle
public static HazelcastInstance getOrCreateHazelcastInstance();
Şöyle yaparız
import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IAtomicReference; import com.hazelcast.core.IFunction; Config config = new Config(); config.setInstanceName("HAZELCAST_INSTANCE"); HazelcastInstance hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config); IAtomicReference<String> atomicReference = hazelcastInstance.getAtomicReference("TEST"); String item = "A"; System.out.println("Item: " + atomicReference.alterAndGet(new MyFunction(item)));
getHazelcastInstanceByName metodu
Eğer ismi belirtilen instance'ı bulamazsa null döner.
Örnek
Şöyle yaparız
// You can also create a named Hazelcast member. // In this case, you should set instanceName of Config object as shown below Config config = new Config(); config.setInstanceName( "my-instance" ); Hazelcast.newHazelcastInstance( config ); // To retrieve an existing Hazelcast member by its name, use the following Hazelcast.getHazelcastInstanceByName( "my-instance" );
newHazelcastInstance metodu
Yeni member başlatır. Açıklaması şöyle. Yani gömülü bile olsa hazelcast.xml dosyasını belirtmek mümkün.
Hazelcast will look into two places for the configuration file:1. System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path. Example:-Dhazelcast.config=C:/myhazelcast.xml.2. Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.3. If Hazelcast doesn't find any config file, it will start with the default configuration (hazelcast-default.xml) located in hazelcast.jar.
Metodun için şöyle. Yani Config.load() çağrısı yapıyor. Bu yüzden hazelcast.xml içindeki değerler ortam değişkenleri tarafından ezilebilir. Configuration Builder ve Configuration Loader farklı şeyler
public static HazelcastInstance newHazelcastInstance() { return HazelcastInstanceFactory.newHazelcastInstance(null); } public static HazelcastInstance newHazelcastInstance(Config config) { if (config == null) { config = Config.load(); } return newHazelcastInstance( config, config.getInstanceName(), new DefaultNodeContext() ); }
Örnek
Şöyle yaparız
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
shutdownAll metodu
İmzası şöyle
public static void shutdownAll();
Aynı JVM içinde başlatılan tüm HazelcastInstance nesnelerini kapatır
Hiç yorum yok:
Yorum Gönder