Example usage for com.liferay.portal.kernel.cluster ClusterRequest createMulticastRequest

List of usage examples for com.liferay.portal.kernel.cluster ClusterRequest createMulticastRequest

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.cluster ClusterRequest createMulticastRequest.

Prototype

public static ClusterRequest createMulticastRequest(Serializable payload, boolean skipLocal) 

Source Link

Usage

From source file:com.liferay.monitoring.web.internal.portlet.action.EditSessionMVCActionCommand.java

License:Open Source License

protected void invalidateSession(ActionRequest actionRequest) throws Exception {

    String sessionId = ParamUtil.getString(actionRequest, "sessionId");

    try {/*from  w  ww.ja  va  2  s . c  om*/
        PortletSession portletSession = actionRequest.getPortletSession();

        String portletSessionId = portletSession.getId();

        if (!portletSessionId.equals(sessionId)) {
            HttpSession userSession = PortalSessionContext.get(sessionId);

            if (userSession != null) {
                userSession.invalidate();

                return;
            }

            if (!_clusterExecutor.isEnabled()) {
                return;
            }

            try {
                MethodHandler methodHandler = new MethodHandler(_invalidateSessionMethodKey, sessionId);

                ClusterRequest clusterRequest = ClusterRequest.createMulticastRequest(methodHandler, true);

                clusterRequest.setFireAndForget(true);

                _clusterExecutor.execute(clusterRequest);
            } catch (Throwable t) {
                _log.error("Unable to notify cluster ", t);
            }
        }
    } catch (Exception e) {
        _log.error("Unable to invalidate session", e);
    }
}

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);
    }/*ww  w .jav  a2  s  .com*/

    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;
    }
}