001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.scheduler.config;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.scheduler.SchedulerEngineHelperUtil;
020    import com.liferay.portal.kernel.scheduler.SchedulerEntry;
021    import com.liferay.portal.kernel.util.BasePortalLifecycle;
022    import com.liferay.portal.kernel.util.PortalLifecycle;
023    
024    /**
025     * @author Shuyang Zhou
026     * @author Tina Tian
027     */
028    public class DefaultSchedulingConfigurator
029            extends AbstractSchedulingConfigurator {
030    
031            public void configure() {
032                    if (schedulerEntries.isEmpty()) {
033                            return;
034                    }
035    
036                    SchedulingConfiguratorLifecycle schedulingConfiguratorLifecycle =
037                            new SchedulingConfiguratorLifecycle();
038    
039                    schedulingConfiguratorLifecycle.registerPortalLifecycle(
040                            PortalLifecycle.METHOD_INIT);
041            }
042    
043            private static Log _log = LogFactoryUtil.getLog(
044                    DefaultSchedulingConfigurator.class);
045    
046            private class SchedulingConfiguratorLifecycle extends BasePortalLifecycle {
047    
048                    @Override
049                    protected void doPortalDestroy() throws Exception {
050                    }
051    
052                    @Override
053                    protected void doPortalInit() throws Exception {
054                            for (SchedulerEntry schedulerEntry : schedulerEntries) {
055                                    try {
056                                            SchedulerEngineHelperUtil.schedule(
057                                                    schedulerEntry, storageType, null, exceptionsMaxSize);
058                                    }
059                                    catch (Exception e) {
060                                            _log.error("Unable to schedule " + schedulerEntry, e);
061                                    }
062                            }
063                    }
064    
065            }
066    
067    }