This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 123832
Collapse All | Expand All

(-)openide/util/apichanges.xml (+17 lines)
Lines 49-54 Link Here
49
    <apidef name="actions">Actions API</apidef>
49
    <apidef name="actions">Actions API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="Mutex.Wrapper">
53
        <api name="util"/>
54
        <summary>Mutex made pluggable</summary>
55
        <version major="7" minor="10"/>
56
        <date day="7" month="1" year="2008"/>
57
        <author login="mkubec"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                Added <a href="@TOP@/org/openide/util/Mutex.Wrapper.html">Mutex.Wrapper</a>
62
                that allows creators of some mutex to intercept and wrap posted actions
63
                with custom code.
64
            </p>
65
        </description> 
66
        <class package="org.openide.util" name="Mutex"/>
67
        <issue number="123832"/>
68
    </change>
52
    <change id="Utilities.isLargeFrameIcons">
69
    <change id="Utilities.isLargeFrameIcons">
53
        <api name="util"/>
70
        <api name="util"/>
54
        <summary>Obsolete method <code>Utilities.isLargeFrameIcons</code> deprecated.</summary>
71
        <summary>Obsolete method <code>Utilities.isLargeFrameIcons</code> deprecated.</summary>
(-)openide/util/nbproject/project.properties (-1 / +1 lines)
Lines 41-47 Link Here
41
javac.source=1.5
41
javac.source=1.5
42
module.jar.dir=lib
42
module.jar.dir=lib
43
43
44
spec.version.base=7.11.0
44
spec.version.base=7.12.0
45
45
46
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
46
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
47
47
(-)openide/util/src/org/openide/util/Mutex.java (+29 lines)
Lines 220-225 Link Here
220
        }
220
        }
221
    }
221
    }
222
222
223
    /** @param privileged can enter privileged states of this Mutex
224
     *  @param wrapper a factory that allows Runnables from API to be wrapped into different onces
225
     * @since 7.12
226
     */
227
    public Mutex(Privileged privileged, Wrapper wrapper) {
228
        if (privileged == null) {
229
            throw new IllegalArgumentException("privileged == null"); //NOI18N
230
        } else {
231
            init(new InternalLock());
232
            privileged.setParent(this);
233
        }
234
    }
235
223
    /** Initiates this Mutex */
236
    /** Initiates this Mutex */
224
    private void init(Object lock) {
237
    private void init(Object lock) {
225
        this.LOCK = lock;
238
        this.LOCK = lock;
Lines 1485-1490 Link Here
1485
        }
1498
        }
1486
    }
1499
    }
1487
1500
1501
    /** Factory to wrap runnables into custom ones. This can be used 
1502
     * to always do some action before and after a runnable passed to a 
1503
     * mutex method is executed.
1504
     * 
1505
     * @since 7.12
1506
     */
1507
    public static interface Wrapper {
1508
        /** Creates a custom runnable that is supposed to wrap those 
1509
         * provided by mutex API methods.
1510
         * 
1511
         * @param run runnable to wrap
1512
         * @return a custom runnable to execute custom pre and/or post action
1513
         */
1514
        public Runnable wrap(Runnable run);
1515
    }
1516
1488
    /** Provides access to Mutex's internal methods.
1517
    /** Provides access to Mutex's internal methods.
1489
     *
1518
     *
1490
     * This class can be used when one wants to avoid creating a
1519
     * This class can be used when one wants to avoid creating a
(-)openide/util/test/unit/src/org/openide/util/MutexWrapTest.java (+172 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.openide.util;
43
44
import junit.framework.Test;
45
import org.netbeans.junit.NbTestCase;
46
import org.netbeans.junit.NbTestSuite;
47
48
49
public class MutexWrapTest extends NbTestCase implements Mutex.Wrapper {
50
    Mutex.Privileged p;
51
    Mutex m;
52
    ThreadLocal<Object> IN = new ThreadLocal<Object>();
53
54
    public MutexWrapTest(java.lang.String testName) {
55
        super(testName);
56
    }
57
58
    public static Test suite() {
59
        NbTestSuite suite = new NbTestSuite(MutexWrapTest.class);
60
61
        return suite;
62
    }
63
    
64
    /** Sets up the test.
65
     */
66
    @Override
67
    protected void setUp () {
68
        p = new Mutex.Privileged ();
69
        m = new Mutex (p, this);
70
    }
71
    
72
    public void testRead() throws Exception {
73
        A arg = new A();
74
        Object ret = m.readAccess(arg);
75
        assertEquals("Return type is ok", arg, ret);
76
    }
77
    public void testWrite() throws Exception {
78
        A arg = new A();
79
        Object ret = m.writeAccess(arg);
80
        assertEquals("Return type is ok", arg, ret);
81
    }
82
    public void testExRead() throws Exception {
83
        E arg = new E();
84
        Object ret = m.readAccess(arg);
85
        assertEquals("Return type is ok", arg, ret);
86
    }
87
    public void testExWrite() throws Exception {
88
        E arg = new E();
89
        Object ret = m.writeAccess(arg);
90
        assertEquals("Return type is ok", arg, ret);
91
    }
92
    public void testPostRead() throws Exception {
93
        R arg = new R();
94
        m.postReadRequest(arg);
95
        assertTrue("Executed", arg.exec);
96
    }
97
    public void testPostReadFromWrite() throws Exception {
98
        R arg = new R();
99
        Del del = new Del();
100
        del.read = arg;
101
        m.writeAccess(del);
102
        assertTrue("Executed", arg.exec);
103
    }
104
    public void testPostWrite() throws Exception {
105
        R arg = new R();
106
        m.postWriteRequest(arg);
107
        assertTrue("Executed", arg.exec);
108
    }
109
    public void testPostWriteFromRead() throws Exception {
110
        R arg = new R();
111
        Del del = new Del();
112
        del.write = arg;
113
        m.readAccess(del);
114
        assertTrue("Executed", arg.exec);
115
    }
116
    
117
    
118
    public Runnable wrap(final Runnable run) {
119
        return new Runnable() {
120
            public void run() {
121
                Object prev = IN.get();
122
                IN.set(MutexWrapTest.this);
123
                try {
124
                    run.run();
125
                } finally {
126
                    IN.set(prev);
127
                }
128
                assertFalse("No read", m.isReadAccess());
129
                assertFalse("No write", m.isWriteAccess());
130
            }
131
        };
132
    }
133
    private class A implements Mutex.Action<Object> {
134
        boolean exec;
135
        
136
        public Object run() {
137
            exec = true;
138
            assertEquals("I am wrapped", MutexWrapTest.this, IN.get());
139
            return this;
140
        }
141
    }
142
    private class E implements Mutex.ExceptionAction<Object> {
143
        boolean exec;
144
        
145
        public Object run() {
146
            exec = true;
147
            assertEquals("I am wrapped", MutexWrapTest.this, IN.get());
148
            return this;
149
        }
150
    }
151
    private class R implements Runnable {
152
        boolean exec;
153
        
154
        public void run() {
155
            exec = true;
156
            assertEquals("I am wrapped", MutexWrapTest.this, IN.get());
157
        }
158
    }
159
    private class Del implements Runnable {
160
        Runnable write;
161
        Runnable read;
162
        
163
        public void run() {
164
            if (write != null) {
165
                m.writeAccess(write);
166
            }
167
            if (read != null) {
168
                m.writeAccess(read);
169
            }
170
        }
171
    }
172
}

Return to bug 123832