jdk/test/java/beans/PropertyChangeSupport/Test4682386.java
author lana
Tue, 23 May 2017 21:11:42 +0000
changeset 45187 331a6542b5b8
parent 5506 202f599c92aa
permissions -rw-r--r--
Added tag jdk-10+7 for changeset d554736d963e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4682386
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests for PropertyChangeSupport refactoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Mark Davidson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.Beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.IntrospectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.JApplet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.JButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.JCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.JComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.JLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.JList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.swing.JMenuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.JProgressBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.swing.JTextArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.JTextPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.swing.JTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.swing.JToolBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.swing.JTabbedPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.JTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.JTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * This class tests the multi-threaded access to PropertyChangeSupport and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * will also use reflection to test propertyChanges on Swing components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * There is no new functionality from the implementation of this RFE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Semantically, it should be equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public class Test4682386 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final String FOO = "foo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final String BAR = "bar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final int NUM_LISTENERS = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final boolean DEBUG = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final Class[] TYPES = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            JApplet.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            JButton.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            JCheckBox.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            JComboBox.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            JLabel.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            JList.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            JMenuItem.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            JProgressBar.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            JTextArea.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            JTextPane.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            JTextField.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            JToolBar.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            JTabbedPane.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            JTree.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            JTable.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        testSwingProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // tests the multi-threaded access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        TestBean bean = new TestBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Thread add = new Thread(new AddThread(bean));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Thread remove = new Thread(new RemoveThread(bean));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        Thread prop = new Thread(new PropertyThread(bean));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        add.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        prop.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        remove.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Should be exectuted with $JAVA_HOME/lib/dt.jar in the classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * so that there will be a lot more bound properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * This test isn't really appropriate for automated testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static void testSwingProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        for (Class type : TYPES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                Object bean = Beans.instantiate(type.getClassLoader(), type.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                JComponent comp = (JComponent) bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                for (int k = 0; k < NUM_LISTENERS; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    comp.addPropertyChangeListener(new PropertyListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                for (PropertyDescriptor pd : getPropertyDescriptors(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    if (pd.isBound()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                            System.out.println("Bound property found: " + pd.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        Method read = pd.getReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        Method write = pd.getWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                            write.invoke(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                    bean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                    getValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                            pd.getPropertyType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                            read.invoke(bean)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            // do nothing - just move on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                System.out.println("Reflective method invocation Exception for " + type + " : " + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                // do nothing - just move on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    System.out.println("Exception for " + type.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                            " : " + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        System.out.println("Exec time (ms): " + (System.currentTimeMillis() - start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Gets a fake value from a type and old value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static Object getValue(Class type, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (String.class.equals(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return "test string";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            Integer i = (Integer) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return Integer.valueOf(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (value instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Boolean b = (Boolean) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return Boolean.valueOf(!b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public static PropertyDescriptor[] getPropertyDescriptors(Class type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return Introspector.getBeanInfo(type).getPropertyDescriptors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } catch (IntrospectionException exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new Error("unexpected exception", exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private static void sleep(long ms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            Thread.sleep(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } catch (InterruptedException exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private static class AddThread implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        private final TestBean bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        AddThread(TestBean bean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            this.bean = bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            for (int i = 0; i < NUM_LISTENERS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                for (int j = 0; j < 10; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    this.bean.addPropertyChangeListener(new PropertyListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    System.out.println("10 listeners added");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                sleep(25L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private static class RemoveThread implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        private final TestBean bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        RemoveThread(TestBean bean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            this.bean = bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            for (int k = 0; k < NUM_LISTENERS; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                sleep(100L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                PropertyChangeListener[] listeners = this.bean.getPropertyChangeListners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                for (int i = listeners.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    this.bean.removePropertyChangeListener(listeners[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    System.out.println(listeners.length + " listeners removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private static class PropertyThread implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        private final TestBean bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        PropertyThread(TestBean bean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            this.bean = bean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            for (int i = 0; i < NUM_LISTENERS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                boolean flag = this.bean.isFoo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                this.bean.setFoo(!flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                this.bean.setBar(Boolean.toString(flag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    System.out.println("Executed property changes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                sleep(40L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Handler for the property change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private static class PropertyListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // blank since this should execute as fast as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * A simple bean to test multi-threaded acccess to the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public static class TestBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        private boolean foo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        private String bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            this.pcs.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            this.pcs.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        public PropertyChangeListener[] getPropertyChangeListners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return this.pcs.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        public boolean isFoo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return this.foo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        public void setFoo(boolean foo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            boolean old = this.foo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            this.foo = foo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            this.pcs.firePropertyChange(FOO, old, foo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        public String getBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return this.bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        public void setBar(String bar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            String old = this.bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            this.bar = bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            this.pcs.firePropertyChange(BAR, old, bar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}