001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.cache.cluster;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    
021    /**
022     * @author Shuyang Zhou
023     */
024    public class PortalCacheClusterLinkUtil {
025    
026            public static PortalCacheClusterLink getPortalCacheClusterLink() {
027                    PortalRuntimePermission.checkGetBeanProperty(
028                            PortalCacheClusterLinkUtil.class);
029    
030                    if (_portalCacheClusterLink == null) {
031                            if (_log.isWarnEnabled()) {
032                                    _log.warn(
033                                            "PortalCacheClusterLinkUtil has not been initialized.");
034                            }
035    
036                            return null;
037                    }
038    
039                    return _portalCacheClusterLink;
040            }
041    
042            public static long getSubmittedEventNumber() {
043                    PortalCacheClusterLink portalCacheClusterLink =
044                            getPortalCacheClusterLink();
045    
046                    if (portalCacheClusterLink == null) {
047                            return -1;
048                    }
049    
050                    return portalCacheClusterLink.getSubmittedEventNumber();
051            }
052    
053            public static void sendEvent(
054                    PortalCacheClusterEvent portalCacheClusterEvent) {
055    
056                    PortalCacheClusterLink portalCacheClusterLink =
057                            getPortalCacheClusterLink();
058    
059                    if (portalCacheClusterLink == null) {
060                            return;
061                    }
062    
063                    portalCacheClusterLink.sendEvent(portalCacheClusterEvent);
064            }
065    
066            public void setPortalCacheClusterLink(
067                    PortalCacheClusterLink portalCacheClusterLink) {
068    
069                    PortalRuntimePermission.checkSetBeanProperty(getClass());
070    
071                    _portalCacheClusterLink = portalCacheClusterLink;
072            }
073    
074            private static Log _log = LogFactoryUtil.getLog(
075                    PortalCacheClusterLinkUtil.class);
076    
077            private static PortalCacheClusterLink _portalCacheClusterLink;
078    
079    }