All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dangdang.ddframe.job.cloud.scheduler.producer.TransientProducerRepository Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
/*
 * Copyright 1999-2015 dangdang.com.
 * 

* 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.dangdang.ddframe.job.cloud.scheduler.producer; import org.quartz.JobKey; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; /** * 瞬时作业生成器数据访问对象. * * @author caohao * @author zhangliang */ class TransientProducerRepository { private final ConcurrentHashMap> cronTasks = new ConcurrentHashMap<>(256, 1); //TODO 并发优化 synchronized void put(final JobKey jobKey, final String jobName) { remove(jobName); if (cronTasks.containsKey(jobKey)) { List taskList = cronTasks.get(jobKey); if (!taskList.contains(jobName)) { taskList.add(jobName); } } else { List taskList = new CopyOnWriteArrayList<>(); taskList.add(jobName); cronTasks.put(jobKey, taskList); } } synchronized void remove(final String jobName) { for (Entry> each : cronTasks.entrySet()) { JobKey jobKey = each.getKey(); List jobNames = each.getValue(); jobNames.remove(jobName); if (jobNames.isEmpty()) { cronTasks.remove(jobKey); } } } List get(final JobKey jobKey) { return cronTasks.containsKey(jobKey) ? cronTasks.get(jobKey) : Collections.emptyList(); } boolean containsKey(final JobKey jobKey) { return cronTasks.containsKey(jobKey); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy