Example usage for com.liferay.portal.util PortalInstances getCompanyIds

List of usage examples for com.liferay.portal.util PortalInstances getCompanyIds

Introduction

In this page you can find the example usage for com.liferay.portal.util PortalInstances getCompanyIds.

Prototype

public static long[] getCompanyIds() 

Source Link

Usage

From source file:com.liferay.portlet.admin.action.EditServerAction.java

License:Open Source License

protected void reindex(ActionRequest actionRequest) throws Exception {
    String portletId = ParamUtil.getString(actionRequest, "portletId");

    long[] companyIds = PortalInstances.getCompanyIds();

    if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
        MessageValuesThreadLocal.setValue(ClusterLinkUtil.CLUSTER_FORWARD_MESSAGE, true);
    }//from ww  w . ja  v  a  2  s. c  o  m

    if (Validator.isNull(portletId)) {
        for (long companyId : companyIds) {
            try {
                LuceneIndexer indexer = new LuceneIndexer(companyId);

                indexer.reindex();
            } catch (Exception e) {
                _log.error(e, e);
            }
        }
    } else {
        Portlet portlet = PortletLocalServiceUtil.getPortletById(companyIds[0], portletId);

        if (portlet == null) {
            return;
        }

        List<Indexer> indexers = portlet.getIndexerInstances();

        if (indexers == null) {
            return;
        }

        for (Indexer indexer : indexers) {
            for (long companyId : companyIds) {
                ShardUtil.pushCompanyService(companyId);

                try {
                    SearchEngineUtil.deletePortletDocuments(companyId, portletId);

                    indexer.reindex(new String[] { String.valueOf(companyId) });
                } catch (Exception e) {
                    _log.error(e, e);
                }

                ShardUtil.popCompanyService();
            }
        }
    }

    if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
        Address localClusterNodeAddress = ClusterExecutorUtil.getLocalClusterNodeAddress();

        ClusterRequest clusterRequest = ClusterRequest.createMulticastRequest(
                new MethodHandler(_loadIndexesFromClusterMethodKey, companyIds, localClusterNodeAddress), true);

        ClusterExecutorUtil.execute(clusterRequest);

        return;
    }
}

From source file:org.lsug.quota.web.internal.portlet.ServerQuotaWebPortlet.java

License:Open Source License

@Activate
protected void activate(Map<String, Object> properties) {
    long[] companyIds = PortalInstances.getCompanyIds();

    for (long companyId : companyIds) {
        try {//from  w  ww  .  j  ava 2  s  .  com
            doRun(companyId);
        } catch (Exception e) {
            LOGGER.error(e);
        }
    }
}