001    /**
002     * Copyright (c) 2000-2013 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            @Override
032            public void configure() {
033                    if (schedulerEntries.isEmpty()) {
034                            return;
035                    }
036    
037                    SchedulingConfiguratorLifecycle schedulingConfiguratorLifecycle =
038                            new SchedulingConfiguratorLifecycle();
039    
040                    schedulingConfiguratorLifecycle.registerPortalLifecycle(
041                            PortalLifecycle.METHOD_INIT);
042            }
043    
044            private static Log _log = LogFactoryUtil.getLog(
045                    DefaultSchedulingConfigurator.class);
046    
047            private class SchedulingConfiguratorLifecycle extends BasePortalLifecycle {
048    
049                    @Override
050                    protected void doPortalDestroy() throws Exception {
051                    }
052    
053                    @Override
054                    protected void doPortalInit() throws Exception {
055                            for (SchedulerEntry schedulerEntry : schedulerEntries) {
056                                    try {
057                                            SchedulerEngineHelperUtil.schedule(
058                                                    schedulerEntry, storageType, null, exceptionsMaxSize);
059                                    }
060                                    catch (Exception e) {
061                                            _log.error("Unable to schedule " + schedulerEntry, e);
062                                    }
063                            }
064                    }
065    
066            }
067    
068    }