|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacvs.caching; /** * A watchdog class that lets to be only a specified number of commands to run at once.. * * @author Milos Kleint */ import java.util.*; import org.netbeans.modules.javacvs.commands.FileSystemCommand; public class CommandLocker extends org.netbeans.modules.javacvs.events.CommandDisplayerAdapter { private LinkedList commandList; public static final int COMMAND_NUMBER = 7; /** Creates new RefreshLocker */ public CommandLocker() { commandList = new LinkedList(); } public void showFinishedCommand() { super.showFinishedCommand(); removeFromQueue(); } public void showExecutionFailed(Exception exception) { super.showExecutionFailed(exception); removeFromQueue(); } public synchronized void removeFromQueue() { if (commandList.size() > COMMAND_NUMBER) { FileSystemCommand comm = (FileSystemCommand)commandList.get(COMMAND_NUMBER); comm.startCommand(); } // it actually doesn't matter which one is removed.. what counts is the size of the list commandList.removeFirst(); } public synchronized void addToQueueAndRun(FileSystemCommand command) { commandList.addLast(command); command.addDisplayerListener(this); if (commandList.size() <= COMMAND_NUMBER) { command.startCommand(); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.