001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.ArrayList;
018 import java.util.Collections;
019 import java.util.List;
020
021
024 public class PortalLifecycleUtil {
025
026 public static void flushDestroys() {
027 _inFlushDestroys = true;
028
029 for (int i = _portalLifecyclesDestroy.size() - 1; i >= 0; i--) {
030 PortalLifecycle portalLifecycle = _portalLifecyclesDestroy.get(i);
031
032 portalLifecycle.portalDestroy();
033 }
034
035 _portalLifecyclesDestroy.clear();
036
037 _inFlushDestroys = false;
038 }
039
040 @SuppressWarnings("deprecation")
041 public static void flushInits() {
042 if (_portalLifecyclesInit != null) {
043 List<PortalLifecycle> portalLifecyclesInit = _portalLifecyclesInit;
044
045 _portalLifecyclesInit = null;
046
047 for (PortalLifecycle portalLifecycle : portalLifecyclesInit) {
048 portalLifecycle.portalInit();
049 }
050 }
051
052 PortalInitableUtil.flushInitables();
053 }
054
055 public static void register(PortalLifecycle portalLifecycle) {
056 register(portalLifecycle, PortalLifecycle.METHOD_ALL);
057 }
058
059 public static void register(PortalLifecycle portalLifecycle, int method) {
060 if ((method == PortalLifecycle.METHOD_ALL) ||
061 (method == PortalLifecycle.METHOD_INIT)) {
062
063 if (_portalLifecyclesInit == null) {
064 portalLifecycle.portalInit();
065 }
066 else {
067 _portalLifecyclesInit.add(portalLifecycle);
068 }
069 }
070
071 if ((method == PortalLifecycle.METHOD_ALL) ||
072 (method == PortalLifecycle.METHOD_DESTROY)) {
073
074 _portalLifecyclesDestroy.add(portalLifecycle);
075 }
076 }
077
078 public static void removeDestroy(PortalLifecycle portalLifecycle) {
079 if (!_inFlushDestroys) {
080 _portalLifecyclesDestroy.remove(portalLifecycle);
081 }
082 }
083
084 public static void reset() {
085 _inFlushDestroys = false;
086
087 if (_portalLifecyclesInit == null) {
088 _portalLifecyclesInit = Collections.synchronizedList(
089 new ArrayList<PortalLifecycle>());
090 }
091 else {
092 _portalLifecyclesInit.clear();
093 }
094
095 _portalLifecyclesDestroy.clear();
096 }
097
098 private static boolean _inFlushDestroys;
099 private static List<PortalLifecycle> _portalLifecyclesDestroy =
100 Collections.synchronizedList(new ArrayList<PortalLifecycle>());
101 private static List<PortalLifecycle> _portalLifecyclesInit =
102 Collections.synchronizedList(new ArrayList<PortalLifecycle>());
103
104 }