All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.core.Hazelcast Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.core;

import com.hazelcast.config.Config;
import com.hazelcast.instance.HazelcastInstanceFactory;
import com.hazelcast.instance.OutOfMemoryErrorDispatcher;

import java.util.Set;

/**
 * Factory for {@link HazelcastInstance}'s, a node in a cluster.
 */
public final class Hazelcast {

    private Hazelcast() {
    }

    /**
     * Shuts down all running Hazelcast Instances on this JVM.
     * It doesn't shutdown all members of the
     * cluster but just the ones running on this JVM.
     *
     * @see #newHazelcastInstance(Config)
     */
    public static void shutdownAll() {
        HazelcastInstanceFactory.shutdownAll();
    }

    /**
     * Creates a new HazelcastInstance (a new node in a cluster).
     * This method allows you to create and run multiple instances
     * of Hazelcast cluster members on the same JVM.
     * 

* To shutdown all running HazelcastInstances (all members on this JVM) * call {@link #shutdownAll()}. * * @param config Configuration for the new HazelcastInstance (member) * @return the new HazelcastInstance * @see #shutdownAll() * @see #getHazelcastInstanceByName(String) */ public static HazelcastInstance newHazelcastInstance(Config config) { return HazelcastInstanceFactory.newHazelcastInstance(config); } /** * Creates a new HazelcastInstance (a new node in a cluster). * This method allows you to create and run multiple instances * of Hazelcast cluster members on the same JVM. *

* To shutdown all running HazelcastInstances (all members on this JVM) * call {@link #shutdownAll()}. * * 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. *
  3. * Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file. *
  4. *
* If Hazelcast doesn't find any config file, it will start with the default configuration (hazelcast-default.xml) * located in hazelcast.jar. * * @return the new HazelcastInstance * @see #shutdownAll() * @see #getHazelcastInstanceByName(String) */ public static HazelcastInstance newHazelcastInstance() { return HazelcastInstanceFactory.newHazelcastInstance(null); } /** * Returns an existing HazelcastInstance with instanceName. *

* To shutdown all running HazelcastInstances (all members on this JVM) * call {@link #shutdownAll()}. * * @param instanceName Name of the HazelcastInstance (member) * @return an existing HazelcastInstance * @see #newHazelcastInstance(Config) * @see #shutdownAll() */ public static HazelcastInstance getHazelcastInstanceByName(String instanceName) { return HazelcastInstanceFactory.getHazelcastInstance(instanceName); } /** * Gets or creates the HazelcastInstance with a certain name. * * If a Hazelcast instance with the same name as the configuration exists, then it is returned, otherwise it is created. * * @param config the Config. * @return the HazelcastInstance * @throws NullPointerException if config is null. * @throws IllegalArgumentException if the instance name of the config is null or empty. */ public static HazelcastInstance getOrCreateHazelcastInstance(Config config) { return HazelcastInstanceFactory.getOrCreateHazelcastInstance(config); } /** * Returns all active/running HazelcastInstances on this JVM. *

* To shutdown all running HazelcastInstances (all members on this JVM) * call {@link #shutdownAll()}. * * @return all active/running HazelcastInstances on this JVM * @see #newHazelcastInstance(Config) * @see #getHazelcastInstanceByName(String) * @see #shutdownAll() */ public static Set getAllHazelcastInstances() { return HazelcastInstanceFactory.getAllHazelcastInstances(); } /** * Sets OutOfMemoryHandler to be used when an OutOfMemoryError * is caught by Hazelcast threads. * *

* Warning: OutOfMemoryHandler may not be called although JVM throws * OutOfMemoryError. * Because error may be thrown from an external (user thread) thread * and Hazelcast may not be informed about OutOfMemoryError. *

* * @param outOfMemoryHandler set when an OutOfMemoryError is caught by Hazelcast threads * * @see OutOfMemoryError * @see OutOfMemoryHandler */ public static void setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler) { OutOfMemoryErrorDispatcher.setServerHandler(outOfMemoryHandler); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy