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

hudson.model.RunnerStack Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * 
 *    Kohsuke Kawaguchi
 *
 *
 *******************************************************************************/ 

package hudson.model;

import hudson.model.Run.Runner;

import java.util.Stack;
import java.util.Map;
import java.util.WeakHashMap;

/**
 * Keeps track of {@link Runner}s that are currently executing on the given
 * thread (that can be either an {@link Executor} or threads that are
 * impersonating one.)
 *
 * @author Kohsuke Kawaguchi
 * @since 1.319
 */
final class RunnerStack {

    private final Map> stack = new WeakHashMap>();

    synchronized void push(Runner r) {
        Executor e = Executor.currentExecutor();
        Stack s = stack.get(e);
        if (s == null) {
            stack.put(e, s = new Stack());
        }
        s.push(r);
    }

    synchronized void pop() {
        Executor e = Executor.currentExecutor();
        Stack s = stack.get(e);
        s.pop();
        if (s.isEmpty()) {
            stack.remove(e);
        }
    }

    synchronized Runner peek() {
        return stack.get(Executor.currentExecutor()).peek();
    }
    static final RunnerStack INSTANCE = new RunnerStack();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy