List of usage examples for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_CANCELLED
int STATUS_CANCELLED
To view the source code for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_CANCELLED.
Click Source Link
From source file:com.liferay.exportimport.internal.background.task.LayoutStagingBackgroundTaskExecutor.java
License:Open Source License
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap(); long userId = MapUtil.getLong(settingsMap, "userId"); long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId"); long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId"); clearBackgroundTaskStatus(backgroundTask); File file = null;//from ww w .j a v a 2s . c o m MissingReferences missingReferences = null; try { ExportImportThreadLocal.setLayoutStagingInProcess(true); Group targetGroup = GroupLocalServiceUtil.fetchGroup(targetGroupId); if (targetGroup == null) { throw new NoSuchGroupException( "Target group does not exists with the primary key " + targetGroupId); } Group sourceGroup = GroupLocalServiceUtil.getGroup(sourceGroupId); if (sourceGroup.hasStagingGroup()) { Group stagingGroup = sourceGroup.getStagingGroup(); if (stagingGroup.getGroupId() == targetGroupId) { ExportImportThreadLocal.setInitialLayoutStagingInProcess(true); TrashEntryLocalServiceUtil.deleteEntries(sourceGroupId, true); } } ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_LOCAL_STARTED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout"); initThreadLocals(sourceGroupId, privateLayout); file = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration); markBackgroundTask(backgroundTask.getBackgroundTaskId(), "exported"); missingReferences = TransactionInvokerUtil.invoke(transactionConfig, new LayoutStagingImportCallable(backgroundTask.getBackgroundTaskId(), exportImportConfiguration, file, sourceGroupId, targetGroupId, userId)); ExportImportThreadLocal.setInitialLayoutStagingInProcess(false); ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent( EVENT_PUBLICATION_LAYOUT_LOCAL_SUCCEEDED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration); } catch (Throwable t) { ExportImportThreadLocal.setInitialLayoutStagingInProcess(false); ExportImportThreadLocal.setLayoutStagingInProcess(false); ExportImportLifecycleManagerUtil.fireExportImportLifecycleEvent(EVENT_PUBLICATION_LAYOUT_LOCAL_FAILED, PROCESS_FLAG_LAYOUT_STAGING_IN_PROCESS, String.valueOf(exportImportConfiguration.getExportImportConfigurationId()), exportImportConfiguration, t); if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to publish layout: " + t.getMessage()); } Group sourceGroup = GroupLocalServiceUtil.getGroup(sourceGroupId); if (sourceGroup.hasStagingGroup()) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setUserId(userId); StagingLocalServiceUtil.disableStaging(sourceGroup, serviceContext); List<BackgroundTask> queuedBackgroundTasks = BackgroundTaskManagerUtil.getBackgroundTasks( sourceGroupId, LayoutStagingBackgroundTaskExecutor.class.getName(), BackgroundTaskConstants.STATUS_QUEUED); for (BackgroundTask queuedBackgroundTask : queuedBackgroundTasks) { BackgroundTaskManagerUtil.amendBackgroundTask(queuedBackgroundTask.getBackgroundTaskId(), null, BackgroundTaskConstants.STATUS_CANCELLED, new ServiceContext()); } } deleteTempLarOnFailure(file); throw new SystemException(t); } deleteTempLarOnSuccess(file); return processMissingReferences(backgroundTask.getBackgroundTaskId(), missingReferences); }
From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java
License:Open Source License
protected void reindex(final ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Map<String, Serializable> taskContextMap = new HashMap<>(); String className = ParamUtil.getString(actionRequest, "className"); if (!ParamUtil.getBoolean(actionRequest, "blocking")) { _indexWriterHelper.reindex(themeDisplay.getUserId(), "reindex", _portalInstancesLocalService.getCompanyIds(), className, taskContextMap); return;//from w ww. ja v a2 s . c o m } final String jobName = "reindex-".concat(_portalUUID.generate()); final CountDownLatch countDownLatch = new CountDownLatch(1); MessageListener messageListener = new MessageListener() { @Override public void receive(Message message) throws MessageListenerException { int status = message.getInteger("status"); if ((status != BackgroundTaskConstants.STATUS_CANCELLED) && (status != BackgroundTaskConstants.STATUS_FAILED) && (status != BackgroundTaskConstants.STATUS_SUCCESSFUL)) { return; } if (!jobName.equals(message.getString("name"))) { return; } PortletSession portletSession = actionRequest.getPortletSession(); long lastAccessedTime = portletSession.getLastAccessedTime(); int maxInactiveInterval = portletSession.getMaxInactiveInterval(); int extendedMaxInactiveIntervalTime = (int) (System.currentTimeMillis() - lastAccessedTime + maxInactiveInterval); portletSession.setMaxInactiveInterval(extendedMaxInactiveIntervalTime); countDownLatch.countDown(); } }; _messageBus.registerMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener); try { _indexWriterHelper.reindex(themeDisplay.getUserId(), jobName, _portalInstancesLocalService.getCompanyIds(), className, taskContextMap); countDownLatch.await(ParamUtil.getLong(actionRequest, "timeout", Time.HOUR), TimeUnit.MILLISECONDS); } finally { _messageBus.unregisterMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener); } }