com.aspectran.core.scheduler.service.DefaultSchedulerServiceBuilder Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2024 The Aspectran Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aspectran.core.scheduler.service;
import com.aspectran.core.context.config.SchedulerConfig;
import com.aspectran.core.service.CoreService;
import com.aspectran.core.service.ServiceStateListener;
import com.aspectran.utils.Assert;
import com.aspectran.utils.annotation.jsr305.NonNull;
import com.aspectran.utils.logging.Logger;
import com.aspectran.utils.logging.LoggerFactory;
public class DefaultSchedulerServiceBuilder {
private static final Logger logger = LoggerFactory.getLogger(DefaultSchedulerServiceBuilder.class);
@NonNull
public static DefaultSchedulerService build(CoreService parentService, SchedulerConfig schedulerConfig) {
Assert.notNull(parentService, "parentService must not be null");
Assert.notNull(schedulerConfig, "schedulerConfig must not be null");
DefaultSchedulerService schedulerService = new DefaultSchedulerService(parentService);
schedulerService.configure(schedulerConfig);
setServiceStateListener(schedulerService);
return schedulerService;
}
private static void setServiceStateListener(@NonNull final DefaultSchedulerService schedulerService) {
schedulerService.setServiceStateListener(new ServiceStateListener() {
@Override
public void started() {
}
@Override
public void stopped() {
}
@Override
public void paused(long millis) {
logger.warn(schedulerService.getServiceName() + " does not support pausing for a certain period of time");
}
@Override
public void paused() {
schedulerService.pauseAll();
}
@Override
public void resumed() {
schedulerService.resumeAll();
}
});
}
}