use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.
the class CIBuildTrigger method startTriggerThreads.
private void startTriggerThreads() {
if (job == null)
return;
if (providerUpdated) {
log.info("Saving job since messaging provider was migrated...");
try {
job.save();
} catch (IOException e) {
log.warning("Exception while trying to save job: " + e.getMessage());
}
}
if (job instanceof AbstractProject) {
AbstractProject<?, ?> aJob = (AbstractProject<?, ?>) job;
if (aJob.isDisabled()) {
log.info("Job '" + job.getFullName() + "' is disabled, not subscribing.");
return;
}
}
try {
synchronized (locks.computeIfAbsent(job.getFullName(), o -> new ArrayList<>())) {
if (stopTriggerThreads(job.getFullName()) == null && providers != null) {
List<CITriggerThread> threads = locks.get(job.getFullName());
int instance = 1;
for (ProviderData pd : providers) {
JMSMessagingProvider provider = GlobalCIConfiguration.get().getProvider(pd.getName());
if (provider == null) {
log.log(Level.SEVERE, "Failed to locate JMSMessagingProvider with name " + pd.getName() + ". You must update the job configuration. Trigger not started.");
return;
}
CITriggerThread thread = CITriggerThreadFactory.createCITriggerThread(provider, pd, job.getFullName(), this, instance);
log.info("Starting thread (" + thread.getId() + ") for '" + job.getFullName() + "'.");
thread.start();
threads.add(thread);
instance++;
}
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "Unhandled exception in trigger start.", e);
}
}
use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.
the class CIBuildTrigger method stopTriggerThreads.
private List<CITriggerThread> stopTriggerThreads(String fullName, List<CITriggerThread> comparisonThreads) {
synchronized (locks.computeIfAbsent(fullName, o -> new ArrayList<>())) {
List<CITriggerThread> threads = locks.get(fullName);
// If threads are the same we have start/stop sequence, so don't bother stopping.
if (comparisonThreads != null && threads.size() == comparisonThreads.size()) {
for (CITriggerThread thread : threads) {
for (int i = 0; i < comparisonThreads.size(); i++) {
if (thread.equals(comparisonThreads.get(i))) {
log.info("Already have thread " + thread.getId() + "...");
comparisonThreads.remove(i);
break;
}
}
}
if (comparisonThreads.size() == 0) {
return threads;
}
}
for (CITriggerThread thread : threads) {
try {
log.info("Stopping thread (" + thread.getId() + ") for '" + fullName + "'.");
thread.shutdown();
} catch (Exception e) {
log.log(Level.SEVERE, "Unhandled exception in trigger stop.", e);
}
}
// Just in case.
threads.clear();
log.fine("Removed thread lock for '" + fullName + "'.");
}
return null;
}
use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.
the class CIBuildTrigger method getComparisonThreads.
private List<CITriggerThread> getComparisonThreads() {
if (providers != null && job != null) {
List<CITriggerThread> threads = new ArrayList<>();
int instance = 1;
for (ProviderData pd : providers) {
JMSMessagingProvider provider = GlobalCIConfiguration.get().getProvider(pd.getName());
// The thread is never started.
if (provider == null)
throw new NullPointerException("No such provider configured for name: '" + pd.getName() + "' on job named '" + job.getFullName() + "'");
CITriggerThread thread = new CITriggerThread(provider, pd, job.getFullName(), null, instance);
threads.add(thread);
instance++;
}
return threads;
}
return null;
}
Aggregations