BrightSide Workbench Full Report + Source Code
TaskSet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.scheduler.task;
20 
21 import java.io.IOException;
22 import java.util.Collections;
23 import java.util.Set;
24 import java.util.TreeSet;
25 import java.util.stream.Collectors;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.log.WebLoggers;
28 import org.turro.scheduler.task.settings.TaskSettings;
29 import org.turro.scheduler.task.settings.TaskSettingsSet;
30 
35 public class TaskSet extends TreeSet<AbstractTask> {
36 
37  /* Factory */
38 
39  private static final Set<AbstractTask> tasks = Collections.synchronizedSet(new TaskSet());
40 
41  public static Set<AbstractTask> load(IConstructor constructor) {
42  try {
43  tasks.clear();
45  for(TaskSettings settings : set) {
46  AbstractTask task = settings.build(constructor);
47  if(task != null) {
48  tasks.add(task);
49  }
50  }
51  return tasks;
52  } catch (IOException ex) {
53  WebLoggers.severe(TaskSet.class).exception(ex).log();
54  }
55  return Collections.EMPTY_SET;
56  }
57 
58  public static void save(Set<AbstractTask> tasks) {
59  try {
60  TaskSettingsSet settings = tasks.stream()
61  .filter(t -> !t.isSystem())
62  .map(t -> t.getSettings())
63  .collect(Collectors.toCollection(TaskSettingsSet::new));
64  settings.save();
65  } catch (IOException ex) {
66  WebLoggers.severe(TaskSet.class).exception(ex).log();
67  }
68  }
69 
70 }
static WebLoggers severe(Object entity)
Definition: WebLoggers.java:51
WebLoggers exception(Throwable throwable)
Definition: WebLoggers.java:29
static Set< AbstractTask > load(IConstructor constructor)
Definition: TaskSet.java:41
static void save(Set< AbstractTask > tasks)
Definition: TaskSet.java:58
AbstractTask build(IConstructor constructor)