/hazelcast/src/main/java/com/hazelcast/core/Hazelcast.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 680 lines · 185 code · 39 blank · 456 comment · 17 complexity · 4f52cf2605f098a00d0a536b903e0523 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.core;
  17. import com.hazelcast.config.Config;
  18. import com.hazelcast.logging.LoggingService;
  19. import com.hazelcast.partition.PartitionService;
  20. import java.util.Collection;
  21. import java.util.Set;
  22. import java.util.concurrent.ExecutorService;
  23. import java.util.concurrent.atomic.AtomicReference;
  24. /**
  25. * Factory for all of the Hazelcast data and execution components such as
  26. * maps, queues, multimaps, topics and executor service.
  27. * <p/>
  28. * If not started already, Hazelcast member (HazelcastInstance) will start
  29. * automatically if any of the functions is called on Hazelcast.
  30. */
  31. @SuppressWarnings("SynchronizationOnStaticField")
  32. public final class Hazelcast {
  33. @Deprecated
  34. private static final AtomicReference<HazelcastInstance> defaultInstance = new AtomicReference<HazelcastInstance>();
  35. @Deprecated
  36. private static final Object initLock = new Object();
  37. @Deprecated
  38. private static Config defaultConfig = null;
  39. private Hazelcast() {
  40. }
  41. /**
  42. * Initializes the default Hazelcast instance with the specified configuration.
  43. * This method should be called before calling any other methods.
  44. *
  45. * @param config configuration for this Hazelcast instance.
  46. * @return the default instance
  47. * @throws IllegalStateException if this instance is already initialized
  48. *
  49. * @deprecated as of version 2.2
  50. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  51. * @see #getHazelcastInstanceByName(String)
  52. * @see #getAllHazelcastInstances()
  53. */
  54. @Deprecated
  55. public static HazelcastInstance init(Config config) {
  56. if (defaultInstance.get() != null) {
  57. throw new IllegalStateException("Default Hazelcast instance is already initialized.");
  58. }
  59. synchronized (initLock) {
  60. if (defaultInstance.get() != null) {
  61. throw new IllegalStateException("Default Hazelcast instance is already initialized.");
  62. }
  63. defaultConfig = config;
  64. HazelcastInstance defaultInstanceObject = com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy(config);
  65. defaultInstance.set(defaultInstanceObject);
  66. return defaultInstanceObject;
  67. }
  68. }
  69. /**
  70. * Returns the default Hazelcast instance, starts it with the default
  71. * configuration, if not already started.
  72. *
  73. * @return the default Hazelcast instance
  74. *
  75. * @deprecated as of version 2.2
  76. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  77. * @see #getHazelcastInstanceByName(String)
  78. * @see #getAllHazelcastInstances()
  79. */
  80. @Deprecated
  81. public static HazelcastInstance getDefaultInstance() {
  82. HazelcastInstance defaultInstanceObject = defaultInstance.get();
  83. if (defaultInstanceObject == null
  84. || !defaultInstanceObject.getLifecycleService().isRunning()) {
  85. synchronized (initLock) {
  86. defaultInstanceObject = defaultInstance.get();
  87. if (defaultInstanceObject == null
  88. || !defaultInstanceObject.getLifecycleService().isRunning()) {
  89. defaultInstanceObject = com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy(defaultConfig);
  90. defaultInstance.set(defaultInstanceObject);
  91. return defaultInstanceObject;
  92. } else {
  93. return defaultInstanceObject;
  94. }
  95. }
  96. } else {
  97. return defaultInstanceObject;
  98. }
  99. }
  100. /**
  101. * Returns the distributed queue instance with the specified name.
  102. *
  103. * @param name name of the distributed queue
  104. * @return distributed queue instance with the specified name
  105. *
  106. * @deprecated as of version 2.2
  107. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  108. * @see HazelcastInstance#getQueue(String)
  109. */
  110. @Deprecated
  111. public static <E> IQueue<E> getQueue(String name) {
  112. return getDefaultInstance().getQueue(name);
  113. }
  114. /**
  115. * Returns the distributed topic instance with the specified name.
  116. *
  117. * @param name name of the distributed topic
  118. * @return distributed topic instance with the specified name
  119. *
  120. * @deprecated as of version 2.2
  121. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  122. * @see HazelcastInstance#getTopic(String)
  123. */
  124. @Deprecated
  125. public static <E> ITopic<E> getTopic(String name) {
  126. return getDefaultInstance().getTopic(name);
  127. }
  128. /**
  129. * Returns the distributed set instance with the specified name.
  130. *
  131. * @param name name of the distributed set
  132. * @return distributed set instance with the specified name
  133. *
  134. * @deprecated as of version 2.2
  135. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  136. * @see HazelcastInstance#getSet(String)
  137. */
  138. @Deprecated
  139. public static <E> ISet<E> getSet(String name) {
  140. return getDefaultInstance().getSet(name);
  141. }
  142. /**
  143. * Returns the distributed list instance with the specified name.
  144. *
  145. * @param name name of the distributed list
  146. * @return distributed list instance with the specified name
  147. *
  148. * @deprecated as of version 2.2
  149. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  150. * @see HazelcastInstance#getList(String)
  151. */
  152. @Deprecated
  153. public static <E> IList<E> getList(String name) {
  154. return getDefaultInstance().getList(name);
  155. }
  156. /**
  157. * Returns the distributed map instance with the specified name.
  158. *
  159. * @param name name of the distributed map
  160. * @return distributed map instance with the specified name
  161. *
  162. * @deprecated as of version 2.2
  163. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  164. * @see HazelcastInstance#getMap(String)
  165. */
  166. @Deprecated
  167. public static <K, V> IMap<K, V> getMap(String name) {
  168. return getDefaultInstance().getMap(name);
  169. }
  170. /**
  171. * Returns the distributed multimap instance with the specified name.
  172. *
  173. * @param name name of the distributed multimap
  174. * @return distributed multimap instance with the specified name
  175. *
  176. * @deprecated as of version 2.2
  177. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  178. * @see HazelcastInstance#getMultiMap(String)
  179. */
  180. @Deprecated
  181. public static <K, V> MultiMap<K, V> getMultiMap(String name) {
  182. return getDefaultInstance().getMultiMap(name);
  183. }
  184. /**
  185. * Returns the distributed lock instance for the specified key object.
  186. * The specified object is considered to be the key for this lock.
  187. * So keys are considered equals cluster-wide as long as
  188. * they are serialized to the same byte array such as String, long,
  189. * Integer.
  190. * <p/>
  191. * Locks are fail-safe. If a member holds a lock and some of the
  192. * members go down, cluster will keep your locks safe and available.
  193. * Moreover, when a member leaves the cluster, all the locks acquired
  194. * by this dead member will be removed so that these locks can be
  195. * available for live members immediately.
  196. * <pre>
  197. * Lock lock = Hazelcast.getLock("PROCESS_LOCK");
  198. * lock.lock();
  199. * try {
  200. * // process
  201. * } finally {
  202. * lock.unlock();
  203. * }
  204. * </pre>
  205. *
  206. * @param key key of the lock instance
  207. * @return distributed lock instance for the specified key.
  208. *
  209. * @deprecated as of version 2.2
  210. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  211. * @see HazelcastInstance#getLock(Object)
  212. */
  213. @Deprecated
  214. public static ILock getLock(Object key) {
  215. return getDefaultInstance().getLock(key);
  216. }
  217. /**
  218. * Returns the Cluster that this Hazelcast instance is part of.
  219. * Cluster interface allows you to add listener for membership
  220. * events and learn more about the cluster that this Hazelcast
  221. * instance is part of.
  222. *
  223. * @return cluster that this Hazelcast instance is part of
  224. *
  225. * @deprecated as of version 2.2
  226. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  227. * @see HazelcastInstance#getCluster()
  228. */
  229. @Deprecated
  230. public static Cluster getCluster() {
  231. return getDefaultInstance().getCluster();
  232. }
  233. /**
  234. * Returns the default distributed executor service. Executor
  235. * service enables you to run your <tt>Runnable</tt>s and <tt>Callable</tt>s
  236. * on the Hazelcast cluster.
  237. *
  238. * Note that it don't support invokeAll/Any and don't have standard shutdown behavior
  239. *
  240. * @return distributed executor service of this Hazelcast instance
  241. *
  242. * @deprecated as of version 2.2
  243. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  244. * @see HazelcastInstance#getExecutorService()
  245. */
  246. @Deprecated
  247. public static ExecutorService getExecutorService() {
  248. return getDefaultInstance().getExecutorService();
  249. }
  250. /**
  251. * Returns the distributed executor service for the given
  252. * name.
  253. *
  254. * @param name name of the executor service
  255. * @return executor service for the given name
  256. *
  257. * @deprecated as of version 2.2
  258. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  259. * @see HazelcastInstance#getExecutorService(String)
  260. */
  261. @Deprecated
  262. public static ExecutorService getExecutorService(String name) {
  263. return getDefaultInstance().getExecutorService(name);
  264. }
  265. /**
  266. * Returns the transaction instance associated with the current thread,
  267. * creates a new one if it wasn't already.
  268. * <p/>
  269. * Transaction doesn't start until you call <tt>transaction.begin()</tt> and
  270. * if a transaction is started then all transactional Hazelcast operations
  271. * are automatically transactional.
  272. * <pre>
  273. * Map map = Hazelcast.getMap("mymap");
  274. * Transaction txn = Hazelcast.getTransaction();
  275. * txn.begin();
  276. * try {
  277. * map.put ("key", "value");
  278. * txn.commit();
  279. * }catch (Exception e) {
  280. * txn.rollback();
  281. * }
  282. * </pre>
  283. * Isolation is always <tt>REPEATABLE_READ</tt> . If you are in
  284. * a transaction, you can read the data in your transaction and the data that
  285. * is already committed and if not in a transaction, you can only read the
  286. * committed data. Implementation is different for queue and map/set. For
  287. * queue operations (offer,poll), offered and/or polled objects are copied to
  288. * the next member in order to safely commit/rollback. For map/set, Hazelcast
  289. * first acquires the locks for the write operations (put, remove) and holds
  290. * the differences (what is added/removed/updated) locally for each transaction.
  291. * When transaction is set to commit, Hazelcast will release the locks and
  292. * apply the differences. When rolling back, Hazelcast will simply releases
  293. * the locks and discard the differences. Transaction instance is attached
  294. * to the current thread and each Hazelcast operation checks if the current
  295. * thread holds a transaction, if so, operation will be transaction aware.
  296. * When transaction is committed, rolled back or timed out, it will be detached
  297. * from the thread holding it.
  298. *
  299. * @return transaction for the current thread
  300. *
  301. * @deprecated as of version 2.2
  302. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  303. * @see HazelcastInstance#getTransaction()
  304. */
  305. @Deprecated
  306. public static Transaction getTransaction() {
  307. return getDefaultInstance().getTransaction();
  308. }
  309. /**
  310. * Creates cluster-wide atomic long. Hazelcast AtomicNumber is a distributed
  311. * implementation of <tt>java.util.concurrent.atomic.AtomicLong</tt>.
  312. *
  313. * @param name of the AtomicNumber proxy
  314. * @return AtomicNumber proxy instance
  315. *
  316. * @deprecated as of version 2.2
  317. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  318. * @see HazelcastInstance#getAtomicNumber(String)
  319. */
  320. @Deprecated
  321. public static AtomicNumber getAtomicNumber(String name) {
  322. return getDefaultInstance().getAtomicNumber(name);
  323. }
  324. /**
  325. * Creates a cluster-wide CountDownLatch. Hazelcast ICountDownLatch is a distributed
  326. * implementation of <tt>java.util.concurrent.CountDownLatch</tt>.
  327. *
  328. * @param name of the distributed CountDownLatch
  329. * @return ICountDownLatch proxy instance
  330. *
  331. * @deprecated as of version 2.2
  332. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  333. * @see HazelcastInstance#getCountDownLatch(String)
  334. */
  335. @Deprecated
  336. public static ICountDownLatch getCountDownLatch(String name) {
  337. return getDefaultInstance().getCountDownLatch(name);
  338. }
  339. /**
  340. * Creates a cluster-wide semaphore. Hazelcast ISemaphore is a distributed
  341. * implementation of <tt>java.util.concurrent.Semaphore</tt>.
  342. *
  343. * @param name of the distributed Semaphore
  344. * @return ISemaphore proxy instance
  345. *
  346. * @deprecated as of version 2.2
  347. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  348. * @see HazelcastInstance#getSemaphore(String)
  349. */
  350. @Deprecated
  351. public static ISemaphore getSemaphore(String name) {
  352. return getDefaultInstance().getSemaphore(name);
  353. }
  354. /**
  355. * Creates cluster-wide unique IDs. Generated IDs are long type primitive values
  356. * between <tt>0</tt> and <tt>Long.MAX_VALUE</tt> . Id generation occurs almost at the speed of
  357. * <tt>AtomicLong.incrementAndGet()</tt> . Generated IDs are unique during the life
  358. * cycle of the cluster. If the entire cluster is restarted, IDs start from <tt>0</tt> again.
  359. *
  360. * @param name
  361. * @return IdGenerator proxy instance
  362. *
  363. * @deprecated as of version 2.2
  364. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  365. * @see HazelcastInstance#getIdGenerator(String)
  366. */
  367. @Deprecated
  368. public static IdGenerator getIdGenerator(String name) {
  369. return getDefaultInstance().getIdGenerator(name);
  370. }
  371. /**
  372. * Detaches this member from the cluster.
  373. * It doesn't shutdown the entire cluster, it shuts down
  374. * this local member only.
  375. *
  376. * @see HazelcastInstance#getLifecycleService()
  377. * @see LifecycleService#shutdown()
  378. * @deprecated as of version 1.9
  379. */
  380. @Deprecated
  381. public static void shutdown() {
  382. synchronized (initLock) {
  383. if (defaultInstance.get() != null) {
  384. getDefaultInstance().shutdown();
  385. defaultInstance.set(null);
  386. }
  387. }
  388. }
  389. /**
  390. * Shuts down all running Hazelcast Instances on this JVM, including the
  391. * default one if it is running. It doesn't shutdown all members of the
  392. * cluster but just the ones running on this JVM.
  393. *
  394. * @see #newHazelcastInstance(Config)
  395. */
  396. public static void shutdownAll() {
  397. com.hazelcast.impl.FactoryImpl.shutdownAll();
  398. synchronized (initLock) {
  399. defaultInstance.set(null);
  400. }
  401. }
  402. /**
  403. * Detaches this member from the cluster first and then restarts it
  404. * as a new member.
  405. *
  406. * @see HazelcastInstance##getLifecycleService()
  407. * @see LifecycleService#restart()
  408. * @deprecated as of version 1.9
  409. */
  410. @Deprecated
  411. public static void restart() {
  412. synchronized (initLock) {
  413. if (defaultInstance.get() != null) {
  414. getLifecycleService().restart();
  415. } else {
  416. getDefaultInstance();
  417. }
  418. }
  419. }
  420. /**
  421. * Returns all queue, map, set, list, topic, lock, multimap
  422. * instances created by Hazelcast.
  423. *
  424. * @return the collection of instances created by Hazelcast.
  425. *
  426. * @deprecated as of version 2.2
  427. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  428. * @see HazelcastInstance#getInstances()
  429. */
  430. @Deprecated
  431. public static Collection<Instance> getInstances() {
  432. return getDefaultInstance().getInstances();
  433. }
  434. /**
  435. * Add a instance listener which will be notified when a
  436. * new instance such as map, queue, multimap, topic, lock is
  437. * added or removed.
  438. *
  439. * @param instanceListener instance listener
  440. *
  441. * @deprecated as of version 2.2
  442. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  443. * @see HazelcastInstance#addInstanceListener(InstanceListener)
  444. */
  445. @Deprecated
  446. public static void addInstanceListener(InstanceListener instanceListener) {
  447. getDefaultInstance().addInstanceListener(instanceListener);
  448. }
  449. /**
  450. * Removes the specified instance listener. Returns silently
  451. * if specified instance listener doesn't exist.
  452. *
  453. * @param instanceListener instance listener to remove
  454. *
  455. * @deprecated as of version 2.2
  456. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  457. * @see HazelcastInstance#removeInstanceListener(InstanceListener)
  458. */
  459. @Deprecated
  460. public static void removeInstanceListener(InstanceListener instanceListener) {
  461. getDefaultInstance().removeInstanceListener(instanceListener);
  462. }
  463. /**
  464. * Creates a new HazelcastInstance (a new node in a cluster).
  465. * This method allows you to create and run multiple instances
  466. * of Hazelcast cluster members on the same JVM.
  467. * <p/>
  468. * To shutdown all running HazelcastInstances (all members on this JVM)
  469. * call {@link #shutdownAll()}.
  470. *
  471. * @param config Configuration for the new HazelcastInstance (member)
  472. * @return new HazelcastInstance
  473. * @see #shutdownAll()
  474. * @see #getHazelcastInstanceByName(String)
  475. */
  476. public static HazelcastInstance newHazelcastInstance(Config config) {
  477. return com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy(config);
  478. }
  479. /**
  480. * Creates a new HazelcastInstance (a new node in a cluster).
  481. * This method allows you to create and run multiple instances
  482. * of Hazelcast cluster members on the same JVM.
  483. * <p/>
  484. * To shutdown all running HazelcastInstances (all members on this JVM)
  485. * call {@link #shutdownAll()}.
  486. *
  487. * Hazelcast will look into two places for the configuration file:
  488. * <ol>
  489. * <li>
  490. * System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path.
  491. * Example: -Dhazelcast.config=C:/myhazelcast.xml.
  492. * </li>
  493. * <li>
  494. * Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.
  495. * </li>
  496. * </ol>
  497. * If Hazelcast doesn't find any config file, it will happily start with default configuration (hazelcast-default.xml)
  498. * located in hazelcast.jar.
  499. *
  500. * @return new HazelcastInstance
  501. * @see #shutdownAll()
  502. * @see #getHazelcastInstanceByName(String)
  503. */
  504. public static HazelcastInstance newHazelcastInstance() {
  505. return com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy(null);
  506. }
  507. /**
  508. * Creates a new HazelcastInstance Lite Member (a new node in a cluster).
  509. * This method allows you to create and run multiple instances
  510. * of Hazelcast cluster members on the same JVM.
  511. * <p/>
  512. * To shutdown all running HazelcastInstances (all members on this JVM)
  513. * call {@link #shutdownAll()}.
  514. *
  515. * Hazelcast will look into two places for the configuration file:
  516. * <ol>
  517. * <li>
  518. * System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path.
  519. * Example: -Dhazelcast.config=C:/myhazelcast.xml.
  520. * </li>
  521. * <li>
  522. * Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.
  523. * </li>
  524. * </ol>
  525. * If Hazelcast doesn't find any config file, it will happily start with default configuration (hazelcast-default.xml)
  526. * located in hazelcast.jar.
  527. *
  528. * @return new HazelcastInstance
  529. * @see #shutdownAll()
  530. * @see #getHazelcastInstanceByName(String)
  531. */
  532. public static HazelcastInstance newLiteMemberHazelcastInstance() {
  533. return com.hazelcast.impl.FactoryImpl.newHazelcastInstanceProxy(null, true);
  534. }
  535. /**
  536. * Returns an existing HazelcastInstance with instanceName.
  537. * <p/>
  538. * To shutdown all running HazelcastInstances (all members on this JVM)
  539. * call {@link #shutdownAll()}.
  540. *
  541. * @param instanceName Name of the HazelcastInstance (member)
  542. * @return HazelcastInstance
  543. * @see #newHazelcastInstance(Config)
  544. * @see #shutdownAll()
  545. */
  546. public static HazelcastInstance getHazelcastInstanceByName(String instanceName) {
  547. return com.hazelcast.impl.FactoryImpl.getHazelcastInstanceProxy(instanceName);
  548. }
  549. /**
  550. * Returns all active/running HazelcastInstances on this JVM.
  551. * <p/>
  552. * To shutdown all running HazelcastInstances (all members on this JVM)
  553. * call {@link #shutdownAll()}.
  554. *
  555. * @return all HazelcastInstances
  556. * @see #newHazelcastInstance(Config)
  557. * @see #getHazelcastInstanceByName(String)
  558. * @see #shutdownAll()
  559. */
  560. public static Set<HazelcastInstance> getAllHazelcastInstances() {
  561. return com.hazelcast.impl.FactoryImpl.getAllHazelcastInstanceProxies();
  562. }
  563. /**
  564. * Returns the configuration of this Hazelcast instance.
  565. *
  566. * @return configuration of this Hazelcast instance
  567. *
  568. * @deprecated as of version 2.2
  569. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  570. * @see HazelcastInstance#getConfig()
  571. */
  572. @Deprecated
  573. public static Config getConfig() {
  574. return getDefaultInstance().getConfig();
  575. }
  576. /**
  577. * Returns the partition service of this Hazelcast instance.
  578. * PartitionService allows you to introspect current partitions in the
  579. * cluster, partition owner members and listen for partition migration events.
  580. *
  581. * @return partition service
  582. *
  583. * @deprecated as of version 2.2
  584. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  585. * @see HazelcastInstance#getPartitionService()
  586. */
  587. @Deprecated
  588. public static PartitionService getPartitionService() {
  589. return getDefaultInstance().getPartitionService();
  590. }
  591. /**
  592. * Returns the logging service of this Hazelcast instance.
  593. * LoggingService allows you to listen for LogEvents
  594. * generated by Hazelcast runtime. You can log the events somewhere
  595. * or take action base on the message.
  596. *
  597. * @return logging service
  598. *
  599. * @deprecated as of version 2.2
  600. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  601. * @see HazelcastInstance#getLoggingService()
  602. */
  603. @Deprecated
  604. public static LoggingService getLoggingService() {
  605. return getDefaultInstance().getLoggingService();
  606. }
  607. /**
  608. * Returns the lifecycle service for this instance. LifecycleService allows you
  609. * to shutdown, restart, pause and resume this HazelcastInstance and listen for
  610. * the lifecycle events.
  611. *
  612. * @return lifecycle service
  613. *
  614. * @deprecated as of version 2.2
  615. * @see #newHazelcastInstance(com.hazelcast.config.Config)
  616. * @see HazelcastInstance#getLifecycleService()
  617. */
  618. @Deprecated
  619. public static LifecycleService getLifecycleService() {
  620. return getDefaultInstance().getLifecycleService();
  621. }
  622. /**
  623. * Sets <tt>OutOfMemoryHandler</tt> to be used when an <tt>OutOfMemoryError</tt>
  624. * is caught by Hazelcast threads.
  625. *
  626. * <p>
  627. * <b>Warning: </b> <tt>OutOfMemoryHandler</tt> may not be called although JVM throws
  628. * <tt>OutOfMemoryError</tt>.
  629. * Because error may be thrown from an external (user thread) thread
  630. * and Hazelcast may not be informed about <tt>OutOfMemoryError</tt>.
  631. * </p>
  632. *
  633. * @param outOfMemoryHandler
  634. *
  635. * @see OutOfMemoryError
  636. * @see OutOfMemoryHandler
  637. */
  638. public static void setOutOfMemoryHandler(OutOfMemoryHandler outOfMemoryHandler) {
  639. com.hazelcast.impl.OutOfMemoryErrorDispatcher.setHandler(outOfMemoryHandler);
  640. }
  641. }