Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.google.lms.portal.commons.api.lifecyle.listener;
- import com.liferay.portal.instance.lifecycle.BasePortalInstanceLifecycleListener;
- import com.liferay.portal.kernel.cluster.ClusterMasterExecutor;
- import com.liferay.portal.kernel.concurrent.ConcurrentHashSet;
- import com.liferay.portal.kernel.exception.PortalException;
- import com.liferay.portal.kernel.log.Log;
- import com.liferay.portal.kernel.log.LogFactoryUtil;
- import com.liferay.portal.kernel.model.Company;
- import java.util.Set;
- import org.osgi.service.component.annotations.Reference;
- /**
- * @author Igor Arouca
- */
- public abstract class ClusterableBasePortalInstanceLifecycleListener
- extends BasePortalInstanceLifecycleListener {
- @Override
- public void portalInstanceRegistered(Company company) throws Exception {
- if (company == null) {
- throw new IllegalStateException(
- ">>> Cannot update group status keys: portal instance not " +
- "initialized yet");
- }
- _registeredCompanyIds.add(company.getCompanyId());
- refreshPortalInstance(company.getCompanyId());
- }
- @Override
- public void portalInstanceUnregistered(Company company) throws Exception {
- _registeredCompanyIds.remove(company.getCompanyId());
- }
- protected void activate() {
- for (long companyId : _registeredCompanyIds) {
- try {
- refreshPortalInstance(companyId);
- }
- catch (Exception e) {
- _log.error(
- ">>> Failed to refresh portal instance for companyId: " +
- companyId,
- e);
- }
- }
- }
- protected abstract void doRefreshPortalInstance(long companyId)
- throws PortalException;
- protected void refreshPortalInstance(long companyId)
- throws PortalException {
- if (!_clusterMasterExecutor.isMaster()) {
- return;
- }
- doRefreshPortalInstance(companyId);
- }
- private static final Log _log = LogFactoryUtil.getLog(
- ClusterableBasePortalInstanceLifecycleListener.class);
- @Reference
- private ClusterMasterExecutor _clusterMasterExecutor;
- private Set<Long> _registeredCompanyIds = new ConcurrentHashSet<>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement