View Javadoc
1   package de.spiritscorp.datasync;
2   
3   /*-
4    * 		Data Sync
5    *
6    * 		Copyright ©   2022    The Spirit
7    * 		@email                        thespirit@spiritscorp.network
8    *
9    * 		This program is free software; you can redistribute it and/or modify
10   * 		it under the terms of the GNU General Public License as published by
11   * 		the Free Software Foundation; either version 3 of the License, or
12   * 		(at your option) any later version.
13   *
14   * 		This program is distributed in the hope that it will be useful,
15   * 		but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * 		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17   * 		See the GNU General Public License for more details.
18   *
19   * 		You should have received a copy of the GNU General Public License
20   * 		along with this program. If not, see <http://www.gnu.org/licenses/>.
21   */
22  
23  /**
24   * Defines the background execution intervals and their corresponding internal
25   * validation check timers for the synchronization tasks.
26   * <p>
27   * This enum maps human-readable interval names to explicit millisecond values,
28   * allowing the background scheduler to determine when a synchronization run is due
29   * and how frequently it should verify the execution state.
30   *
31   */
32  public enum BgTime {
33  
34  	/** Execution interval of 1 minute. */
35  	MIN_1( 60_000L, "1 Minute", 5_000L),
36  
37  	/** Execution interval of 5 minutes. */
38  	MIN_5( 300_000L, "5 Minuten", 10_000L),
39  
40  	/** Execution interval of 30 minutes. */
41  	MIN_30( 1_800_000L, "30 Minuten", 60_000L),
42  
43  	/** Execution interval set to occur hourly. */
44  	HOURLY( 3_600_000L, "Stündlich", 300_000L),
45  
46  	/** Execution interval set to occur daily. */
47  	DAYLY( 86_400_000L, "Täglich", 1_800_000L),
48  
49  	/** Execution interval set to occur weekly. */
50  	WEEKLY( 604_800_000L, "Wöchentlich", 1_800_000L),
51  
52  	/** Execution interval set to occur monthly. */
53  	MONTHLY( 2_592_000_000L, "Monatlich", 1_800_000L);
54  
55  	/**
56  	 * The intervall for execute a Job
57  	 */
58  	private final long time;
59  	/**
60  	 * The name for an intervall
61  	 */
62  	private final String name;
63  	/**
64  	 * The check Time for an intervall
65  	 */
66  	private final long checkTime;
67  
68  	/**
69  	 * Internal constructor to initialize the background time configurations.
70  	 *
71  	 * @param time      the total duration of the interval represented in milliseconds
72  	 * @param name      the localized, human-readable display name of the interval
73  	 * @param checkTime the thread sleep or verification check cycle duration in milliseconds
74  	 */
75  	BgTime( final long time, final String name, final long checkTime ) {
76  		this.time = time;
77  		this.name = name;
78  		this.checkTime = checkTime;
79  	}
80  
81  	/**
82  	 * Extracts and retrieves the localized display names of all available background intervals.
83  	 * <p>
84  	 * This array is typically utilized to populate UI dropdown menus or configuration listings.
85  	 *
86  	 * @return a String array containing the human-readable names in the exact order of definition
87  	 */
88  	public static String[] getNames() {
89  		final String[] str = new String[values().length];
90  		int index = 0;
91  		for( final BgTime bg : values() ) {
92  			str[index] = bg.getName();
93  			index++;
94  		}
95  		return str;
96  	}
97  
98  	/**
99  	 * Resolves a matching background time configuration based on its localized display name.
100 	 *
101 	 * @param str the display name string to look up (e.g., "5 Minuten", "Stündlich")
102 	 * @return the matching BgTime constant, or null if no matching name is found
103 	 */
104 	public static BgTime get( final String str ) {
105 		for( final BgTime st : values() ) {
106 			if( str.equals( st.getName() ) ) return st;
107 		}
108 		return null;
109 	}
110 
111 	/**
112 	 * Gets the total execution interval duration.
113 	 *
114 	 * @return the interval time value represented in milliseconds
115 	 */
116 	public long getTime() { return time; }
117 
118 	/**
119 	 * Gets the localized display name of this interval configuration.
120 	 *
121 	 * @return the human-readable interval text
122 	 */
123 	public String getName() { return name; }
124 
125 	/**
126 	 * Gets the specific loop cycle or validation check interval duration.
127 	 *
128 	 * @return the check cycle time value represented in milliseconds
129 	 */
130 	public long getCheckTime() { return checkTime; }
131 }