All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.logspace.agent.shaded.terracotta.quartz.collections.ToolkitDSHolder Maven / Gradle / Ivy
/*
* All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
*
* 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 io.logspace.agent.shaded.terracotta.quartz.collections;
import java.util.HashMap;
import java.util.Map;
import io.logspace.agent.shaded.quartz.Calendar;
import io.logspace.agent.shaded.quartz.JobKey;
import io.logspace.agent.shaded.quartz.TriggerKey;
import io.logspace.agent.shaded.terracotta.quartz.wrappers.FiredTrigger;
import io.logspace.agent.shaded.terracotta.quartz.wrappers.JobWrapper;
import io.logspace.agent.shaded.terracotta.quartz.wrappers.TriggerWrapper;
import org.terracotta.toolkit.Toolkit;
import org.terracotta.toolkit.concurrent.locks.ToolkitLock;
import org.terracotta.toolkit.internal.ToolkitInternal;
import org.terracotta.toolkit.internal.concurrent.locks.ToolkitLockTypeInternal;
import org.terracotta.toolkit.store.ToolkitConfigFields.Consistency;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.terracotta.toolkit.builder.ToolkitStoreConfigBuilder;
import org.terracotta.toolkit.collections.ToolkitSet;
import org.terracotta.toolkit.store.ToolkitConfigFields;
import org.terracotta.toolkit.store.ToolkitStore;
/**
* How JOBS mappings will look?
* JobKey(name, groupname) -> JobWrapper
* groupName -> List
* List -> allGroupNames
*/
public class ToolkitDSHolder {
private static final String JOBS_MAP_PREFIX = "_tc_quartz_jobs";
private static final String ALL_JOBS_GROUP_NAMES_SET_PREFIX = "_tc_quartz_grp_names";
private static final String PAUSED_GROUPS_SET_PREFIX = "_tc_quartz_grp_paused_names";
private static final String BLOCKED_JOBS_SET_PREFIX = "_tc_quartz_blocked_jobs";
private static final String JOBS_GROUP_MAP_PREFIX = "_tc_quartz_grp_jobs_";
private static final String TRIGGERS_MAP_PREFIX = "_tc_quartz_triggers";
private static final String TRIGGERS_GROUP_MAP_PREFIX = "_tc_quartz_grp_triggers_";
private static final String ALL_TRIGGERS_GROUP_NAMES_SET_PREFIX = "_tc_quartz_grp_names_triggers";
private static final String PAUSED_TRIGGER_GROUPS_SET_PREFIX = "_tc_quartz_grp_paused_trogger_names";
private static final String TIME_TRIGGER_SORTED_SET_PREFIX = "_tc_time_trigger_sorted_set";
private static final String FIRED_TRIGGER_MAP_PREFIX = "_tc_quartz_fired_trigger";
private static final String CALENDAR_WRAPPER_MAP_PREFIX = "_tc_quartz_calendar_wrapper";
private static final String SINGLE_LOCK_NAME_PREFIX = "_tc_quartz_single_lock";
private static final String DELIMETER = "|";
private final String jobStoreName;
protected final Toolkit toolkit;
private final AtomicReference> jobsMapReference = new AtomicReference>();
private final AtomicReference> triggersMapReference = new AtomicReference>();
private final AtomicReference> allGroupsReference = new AtomicReference>();
private final AtomicReference> allTriggersGroupsReference = new AtomicReference>();
private final AtomicReference> pausedGroupsReference = new AtomicReference>();
private final AtomicReference> blockedJobsReference = new AtomicReference>();
private final Map> jobsGroupSet = new HashMap>();
private final Map> triggersGroupSet = new HashMap>();
private final AtomicReference> pausedTriggerGroupsReference = new AtomicReference>();
private final AtomicReference> firedTriggersMapReference = new AtomicReference>();
private final AtomicReference> calendarWrapperMapReference = new AtomicReference>();
private final AtomicReference timeTriggerSetReference = new AtomicReference();
private final Map> toolkitMaps = new HashMap>();
public ToolkitDSHolder(String jobStoreName, Toolkit toolkit) {
this.jobStoreName = jobStoreName;
this.toolkit = toolkit;
}
protected final String generateName(String prefix) {
return prefix + DELIMETER + jobStoreName;
}
public SerializedToolkitStore getOrCreateJobsMap() {
String jobsMapName = generateName(JOBS_MAP_PREFIX);
SerializedToolkitStore temp = new SerializedToolkitStore(createStore(jobsMapName));
jobsMapReference.compareAndSet(null, temp);
return jobsMapReference.get();
}
protected ToolkitStore, ?> toolkitMap(String nameOfMap) {
ToolkitStore, ?> map = toolkitMaps.get(nameOfMap);
if (map != null && !map.isDestroyed()) {
return map;
} else {
map = createStore(nameOfMap);
toolkitMaps.put(nameOfMap, map);
return map;
}
}
private ToolkitStore createStore(String nameOfMap) {
ToolkitStoreConfigBuilder builder = new ToolkitStoreConfigBuilder();
return toolkit.getStore(nameOfMap, builder.consistency(Consistency.STRONG).concurrency(1).build(), null);
}
public SerializedToolkitStore getOrCreateTriggersMap() {
String triggersMapName = generateName(TRIGGERS_MAP_PREFIX);
SerializedToolkitStore temp = new SerializedToolkitStore(
createStore(triggersMapName));
triggersMapReference.compareAndSet(null, temp);
return triggersMapReference.get();
}
public ToolkitStore getOrCreateFiredTriggersMap() {
String firedTriggerMapName = generateName(FIRED_TRIGGER_MAP_PREFIX);
ToolkitStore temp = createStore(firedTriggerMapName);
firedTriggersMapReference.compareAndSet(null, temp);
return firedTriggersMapReference.get();
}
public ToolkitStore getOrCreateCalendarWrapperMap() {
String calendarWrapperName = generateName(CALENDAR_WRAPPER_MAP_PREFIX);
ToolkitStore temp = createStore(calendarWrapperName);
calendarWrapperMapReference.compareAndSet(null, temp);
return calendarWrapperMapReference.get();
}
public Set getOrCreateAllGroupsSet() {
String allGrpSetNames = generateName(ALL_JOBS_GROUP_NAMES_SET_PREFIX);
ToolkitSet temp = toolkit.getSet(allGrpSetNames, String.class);
allGroupsReference.compareAndSet(null, temp);
return allGroupsReference.get();
}
public Set getOrCreateBlockedJobsSet() {
String blockedJobsSetName = generateName(BLOCKED_JOBS_SET_PREFIX);
ToolkitSet temp = toolkit.getSet(blockedJobsSetName, JobKey.class);
blockedJobsReference.compareAndSet(null, temp);
return blockedJobsReference.get();
}
public Set getOrCreatePausedGroupsSet() {
String pausedGrpsSetName = generateName(PAUSED_GROUPS_SET_PREFIX);
ToolkitSet temp = toolkit.getSet(pausedGrpsSetName, String.class);
pausedGroupsReference.compareAndSet(null, temp);
return pausedGroupsReference.get();
}
public Set getOrCreatePausedTriggerGroupsSet() {
String pausedGrpsSetName = generateName(PAUSED_TRIGGER_GROUPS_SET_PREFIX);
ToolkitSet temp = toolkit.getSet(pausedGrpsSetName, String.class);
pausedTriggerGroupsReference.compareAndSet(null, temp);
return pausedTriggerGroupsReference.get();
}
public Set getOrCreateJobsGroupMap(String name) {
ToolkitSet set = jobsGroupSet.get(name);
if (set != null && !set.isDestroyed()) {
return set;
} else {
String nameForMap = generateName(JOBS_GROUP_MAP_PREFIX + name);
set = toolkit.getSet(nameForMap, String.class);
jobsGroupSet.put(name, set);
return set;
}
}
public void removeJobsGroupMap(String name) {
ToolkitSet set = jobsGroupSet.remove(name);
if (set != null) {
set.destroy();
}
}
public Set getOrCreateTriggersGroupMap(String name) {
ToolkitSet set = triggersGroupSet.get(name);
if (set != null && !set.isDestroyed()) {
return set;
} else {
String nameForMap = generateName(TRIGGERS_GROUP_MAP_PREFIX + name);
set = toolkit.getSet(nameForMap, String.class);
triggersGroupSet.put(name, set);
return set;
}
}
public void removeTriggersGroupMap(String name) {
ToolkitSet set = triggersGroupSet.remove(name);
if (set != null) {
set.destroy();
}
}
public Set getOrCreateAllTriggersGroupsSet() {
String allTriggersGrpsName = generateName(ALL_TRIGGERS_GROUP_NAMES_SET_PREFIX);
ToolkitSet temp = toolkit.getSet(allTriggersGrpsName, String.class);
allTriggersGroupsReference.compareAndSet(null, temp);
return allTriggersGroupsReference.get();
}
public TimeTriggerSet getOrCreateTimeTriggerSet() {
String triggerSetName = generateName(TIME_TRIGGER_SORTED_SET_PREFIX);
TimeTriggerSet set = new TimeTriggerSet(toolkit.getSortedSet(triggerSetName, TimeTrigger.class));
timeTriggerSetReference.compareAndSet(null, set);
return timeTriggerSetReference.get();
}
public ToolkitLock getLock(ToolkitLockTypeInternal lockType) {
String lockName = generateName(SINGLE_LOCK_NAME_PREFIX);
return ((ToolkitInternal) toolkit).getLock(lockName, lockType);
}
}