| career | drupal | java | mac | mysql | perl | scala | uml | unix  

JMeter example source code file (

This example JMeter source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - JMeter tags/keywords

awt, checkdirty, checkdirty, event, guipackage, hashtree, hashtree, hashtreetraverser, jmetertreenode, jmetertreenode, listedhashtree, node, override, set, testelement, testelement, util

The JMeter source code

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package org.apache.jmeter.gui.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.HashTreeTraverser;
import org.apache.jorphan.collections.ListedHashTree;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

 * Check if the TestPlan has been changed since it was last saved
public class CheckDirty extends AbstractAction implements HashTreeTraverser, ActionListener {
    private static final Logger log = LoggingManager.getLoggerForClass();

    private final Map<JMeterTreeNode, TestElement> previousGuiItems;

    private boolean checkMode = false;

    private boolean removeMode = false;

    private boolean dirty = false;

    private static final Set<String> commands = new HashSet();

    static {

    public CheckDirty() {
        previousGuiItems = new HashMap<JMeterTreeNode, TestElement>();
        ActionRouter.getInstance().addPreActionListener(ExitCommand.class, this);

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(ActionNames.EXIT)) {

     * @see Command#doAction(ActionEvent)
    public void doAction(ActionEvent e) {
        String action = e.getActionCommand();
        if (action.equals(ActionNames.SUB_TREE_SAVED)) {
            HashTree subTree = (HashTree) e.getSource();
        } else if (action.equals(ActionNames.SUB_TREE_LOADED)) {
            ListedHashTree addTree = (ListedHashTree) e.getSource();
        } else if (action.equals(ActionNames.ADD_ALL)) {
        } else if (action.equals(ActionNames.CHECK_REMOVE)) {
            GuiPackage guiPackage = GuiPackage.getInstance();
            JMeterTreeNode[] nodes = guiPackage.getTreeListener().getSelectedNodes();
            removeMode = true;
            for (int i = nodes.length - 1; i >= 0; i--) {
            removeMode = false;
        // If we are merging in another test plan, we know the test plan is dirty now
        if(action.equals(ActionNames.SUB_TREE_MERGED)) {
            dirty = true;
        else {
            dirty = false;
            checkMode = true;
            HashTree wholeTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
            checkMode = false;

     * The tree traverses itself depth-first, calling processNode for each
     * object it encounters as it goes.
    public void addNode(Object node, HashTree subTree) {
        log.debug("Node is class:" + node.getClass());
        JMeterTreeNode treeNode = (JMeterTreeNode) node;
        if (checkMode) {
            // Only check if we have not found any differences so far
            if(!dirty) {
                if (previousGuiItems.containsKey(treeNode)) {
                    if (!previousGuiItems.get(treeNode).equals(treeNode.getTestElement())) {
                        dirty = true;
                } else {
                    dirty = true;
        } else if (removeMode) {
        } else {
            previousGuiItems.put(treeNode, (TestElement) treeNode.getTestElement().clone());

     * Indicates traversal has moved up a step, and the visitor should remove
     * the top node from it's stack structure.
    public void subtractNode() {

     * Process path is called when a leaf is reached. If a visitor wishes to
     * generate Lists of path elements to each leaf, it should keep a Stack data
     * structure of nodes passed to it with addNode, and removing top items for
     * every subtractNode() call.
    public void processPath() {

     * @see Command#getActionNames()
    public Set<String> getActionNames() {
        return commands;

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
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.