no.bekk.dbscheduler.ui.util.Caching Maven / Gradle / Ivy
Show all versions of db-scheduler-ui Show documentation
/*
* Copyright (C) Bekk
*
* 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 no.bekk.dbscheduler.ui.util;
import com.github.kagkarlsson.scheduler.ScheduledExecution;
import com.github.kagkarlsson.scheduler.ScheduledExecutionsFilter;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.TaskInstanceId;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import no.bekk.dbscheduler.ui.model.LogModel;
import no.bekk.dbscheduler.ui.model.TaskDetailsRequestParams;
import no.bekk.dbscheduler.ui.service.LogLogic;
import org.springframework.stereotype.Component;
@Component
public class Caching {
private final Map taskStatusCache = new ConcurrentHashMap<>();
private final List> taskDataCache = new ArrayList<>();
private final Map logCache = new ConcurrentHashMap<>();
public List> getExecutionsFromCacheOrDB(
boolean isRefresh, Scheduler scheduler) {
if (isRefresh || !taskDataCache.isEmpty()) {
List> executions =
getExecutionsFromDBWithoutUpdatingCache(scheduler);
updateCache(executions);
return executions;
} else {
return taskDataCache;
}
}
public List> getExecutionsFromDBWithoutUpdatingCache(
Scheduler scheduler) {
List> executions = scheduler.getScheduledExecutions();
executions.addAll(
scheduler.getScheduledExecutions(ScheduledExecutionsFilter.all().withPicked(true)));
return executions;
}
public void updateCache(List> executions) {
taskStatusCache.clear();
taskDataCache.clear();
taskDataCache.addAll(executions);
for (ScheduledExecution