001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }