/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.trash.web.internal.messaging; import com.liferay.portal.kernel.messaging.BaseMessageListener; import com.liferay.portal.kernel.messaging.DestinationNames; import com.liferay.portal.kernel.messaging.Message; import com.liferay.portal.kernel.module.framework.ModuleServiceLifecycle; import com.liferay.portal.kernel.scheduler.SchedulerEngineHelper; import com.liferay.portal.kernel.scheduler.SchedulerEntry; import com.liferay.portal.kernel.scheduler.SchedulerEntryImpl; import com.liferay.portal.kernel.scheduler.TimeUnit; import com.liferay.portal.kernel.scheduler.Trigger; import com.liferay.portal.kernel.scheduler.TriggerFactory; import com.liferay.portal.util.PropsValues; import com.liferay.trash.kernel.service.TrashEntryLocalService; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; /** * Provides a scheduled task to empty the Recycly Bin when the maximum Recycle * Bin entry age has been exceeded. The maximum Recycle Bin entry age is defined * by the <code>trash.entries.max.age</code> property (in minutes). The * scheduled task uses the <code>trash.entry.check.interval</code> property to * define the execution interval (in minutes). * * @author Eudaldo Alonso */ @Component(immediate = true, service = CheckEntryMessageListener.class) public class CheckEntryMessageListener extends BaseMessageListener { @Activate protected void activate() { Class<?> clazz = getClass(); String className = clazz.getName(); Trigger trigger = _triggerFactory.createTrigger( className, className, null, null, PropsValues.TRASH_ENTRY_CHECK_INTERVAL, TimeUnit.MINUTE); SchedulerEntry schedulerEntry = new SchedulerEntryImpl( className, trigger); _schedulerEngineHelper.register( this, schedulerEntry, DestinationNames.SCHEDULER_DISPATCH); } @Deactivate protected void deactivate() { _schedulerEngineHelper.unregister(this); } @Override protected void doReceive(Message message) throws Exception { _trashEntryLocalService.checkEntries(); } @Reference(target = ModuleServiceLifecycle.PORTAL_INITIALIZED, unbind = "-") protected void setModuleServiceLifecycle( ModuleServiceLifecycle moduleServiceLifecycle) { } @Reference(unbind = "-") protected void setSchedulerEngineHelper( SchedulerEngineHelper schedulerEngineHelper) { _schedulerEngineHelper = schedulerEngineHelper; } @Reference(unbind = "-") protected void setTrashEntryLocalService( TrashEntryLocalService trashEntryLocalService) { _trashEntryLocalService = trashEntryLocalService; } @Reference(unbind = "-") protected void setTriggerFactory(TriggerFactory triggerFactory) { } private SchedulerEngineHelper _schedulerEngineHelper; private TrashEntryLocalService _trashEntryLocalService; @Reference private TriggerFactory _triggerFactory; }