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 33750
Collapse All | Expand All

(-)loaders/src/org/openide/loaders/DataObject.java (-6 / +6 lines)
Lines 503-509 Link Here
503
    public final DataObject copy (final DataFolder f) throws IOException {
503
    public final DataObject copy (final DataFolder f) throws IOException {
504
        final DataObject[] result = new DataObject[1];
504
        final DataObject[] result = new DataObject[1];
505
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
505
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
506
        fs.runAtomicAction (new FileSystem.AtomicAction () {
506
        DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
507
                                public void run () throws IOException {
507
                                public void run () throws IOException {
508
                                    result[0] = handleCopy (f);
508
                                    result[0] = handleCopy (f);
509
                                }
509
                                }
Lines 529-535 Link Here
529
        synchronized ( synchObject() ) {
529
        synchronized ( synchObject() ) {
530
            // the object is ready to be closed
530
            // the object is ready to be closed
531
            FileSystem fs = getPrimaryFile ().getFileSystem ();
531
            FileSystem fs = getPrimaryFile ().getFileSystem ();
532
            fs.runAtomicAction (new FileSystem.AtomicAction () {
532
            DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
533
                    public void run () throws IOException {
533
                    public void run () throws IOException {
534
                        handleDelete ();
534
                        handleDelete ();
535
                        item.deregister(false);
535
                        item.deregister(false);
Lines 574-580 Link Here
574
            
574
            
575
            // executes atomic action with renaming
575
            // executes atomic action with renaming
576
            FileSystem fs = files[0].getFileSystem ();
576
            FileSystem fs = files[0].getFileSystem ();
577
            fs.runAtomicAction (new FileSystem.AtomicAction () {
577
            DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
578
                    public void run () throws IOException {
578
                    public void run () throws IOException {
579
                        files[1] = handleRename (name);
579
                        files[1] = handleRename (name);
580
                        if (files[0] != files[1])
580
                        if (files[0] != files[1])
Lines 610-616 Link Here
610
            // executes atomic action for moving
610
            // executes atomic action for moving
611
            old = getPrimaryFile ();
611
            old = getPrimaryFile ();
612
            FileSystem fs = old.getFileSystem ();
612
            FileSystem fs = old.getFileSystem ();
613
            fs.runAtomicAction (new FileSystem.AtomicAction () {
613
            DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
614
                                    public void run () throws IOException {
614
                                    public void run () throws IOException {
615
                                        FileObject mf = handleMove (df);
615
                                        FileObject mf = handleMove (df);
616
                                        item.changePrimaryFile (mf);
616
                                        item.changePrimaryFile (mf);
Lines 654-660 Link Here
654
        final DataShadow[] result = new DataShadow[1];
654
        final DataShadow[] result = new DataShadow[1];
655
655
656
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
656
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
657
        fs.runAtomicAction (new FileSystem.AtomicAction () {
657
        DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
658
                                public void run () throws IOException {
658
                                public void run () throws IOException {
659
                                    result[0] =  handleCreateShadow (f);
659
                                    result[0] =  handleCreateShadow (f);
660
                                }
660
                                }
Lines 692-698 Link Here
692
        final DataObject[] result = new DataObject[1];
692
        final DataObject[] result = new DataObject[1];
693
693
694
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
694
        FileSystem fs = f.getPrimaryFile ().getFileSystem ();
695
        fs.runAtomicAction (new FileSystem.AtomicAction () {
695
        DataObjectPool.getPOOL().runAtomicAction (fs, new FileSystem.AtomicAction () {
696
                                public void run () throws IOException {
696
                                public void run () throws IOException {
697
                                    result[0] = handleCreateFromTemplate (f, name);
697
                                    result[0] = handleCreateFromTemplate (f, name);
698
                                }
698
                                }
(-)loaders/src/org/openide/loaders/DataObjectPool.java (-1 / +11 lines)
Lines 142-147 Link Here
142
        return ret;
142
        return ret;
143
    }
143
    }
144
    
144
    
145
    
146
    //
147
    // Support for running really atomic actions
148
    //
149
    
150
    public synchronized void runAtomicAction (FileSystem fs, FileSystem.AtomicAction action) 
151
    throws java.io.IOException {
152
        fs.runAtomicAction(action);
153
    }
154
    
145
    /** Collection of all objects that has been created but their
155
    /** Collection of all objects that has been created but their
146
    * creation has not been yet notified to OperationListener.postCreate
156
    * creation has not been yet notified to OperationListener.postCreate
147
    * method.
157
    * method.
Lines 183-189 Link Here
183
    private DataObjectPool () {
193
    private DataObjectPool () {
184
    }
194
    }
185
195
186
196
    
187
197
188
    /** Checks whether there is a data object with primary file
198
    /** Checks whether there is a data object with primary file
189
    * passed thru the parameter.
199
    * passed thru the parameter.
(-)loaders/src/org/openide/loaders/DataShadow.java (-1 / +1 lines)
Lines 231-237 Link Here
231
        final FileObject fo = folder.getPrimaryFile ();
231
        final FileObject fo = folder.getPrimaryFile ();
232
        final DataShadow[] arr = new DataShadow[1];
232
        final DataShadow[] arr = new DataShadow[1];
233
233
234
        fo.getFileSystem ().runAtomicAction (new FileSystem.AtomicAction () {
234
        DataObjectPool.getPOOL().runAtomicAction (fo.getFileSystem (), new FileSystem.AtomicAction () {
235
                                                 public void run () throws IOException {
235
                                                 public void run () throws IOException {
236
                                                     FileObject file = writeOriginal (name, ext, fo, original);
236
                                                     FileObject file = writeOriginal (name, ext, fo, original);
237
                                                     DataObject obj = DataObject.find (file);
237
                                                     DataObject obj = DataObject.find (file);
(-)loaders/src/org/openide/loaders/DataTransferSupport.java (-1 / +1 lines)
Lines 165-171 Link Here
165
            nd.setInputText (name);
165
            nd.setInputText (name);
166
166
167
            if (NotifyDescriptor.OK_OPTION == DialogDisplayer.getDefault ().notify (nd)) {
167
            if (NotifyDescriptor.OK_OPTION == DialogDisplayer.getDefault ().notify (nd)) {
168
                trg.getPrimaryFile ().getFileSystem ().runAtomicAction (new FileSystem.AtomicAction () {
168
                DataObjectPool.getPOOL().runAtomicAction (trg.getPrimaryFile ().getFileSystem (), new FileSystem.AtomicAction () {
169
                            public void run () throws IOException {
169
                            public void run () throws IOException {
170
                                FileObject fo = trg.getPrimaryFile ().createData (nd.getInputText (), "ser"); // NOI18N
170
                                FileObject fo = trg.getPrimaryFile ().createData (nd.getInputText (), "ser"); // NOI18N
171
                                FileLock lock = fo.lock ();
171
                                FileLock lock = fo.lock ();
(-)loaders/src/org/openide/loaders/InstanceDataObject.java (-2 / +2 lines)
Lines 219-225 Link Here
219
        if (newFile == null) {
219
        if (newFile == null) {
220
            final FileObject[] fos = new FileObject[1];
220
            final FileObject[] fos = new FileObject[1];
221
221
222
            fo.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
222
            DataObjectPool.getPOOL().runAtomicAction (fo.getFileSystem(), new FileSystem.AtomicAction() {
223
                public void run () throws IOException {
223
                public void run () throws IOException {
224
                    String fileName;
224
                    String fileName;
225
                    if (name == null) {
225
                    if (name == null) {
Lines 1375-1381 Link Here
1375
                me.name = name;
1375
                me.name = name;
1376
                me.create = create;
1376
                me.create = create;
1377
1377
1378
                folder.getPrimaryFile().getFileSystem().runAtomicAction(me);
1378
                DataObjectPool.getPOOL().runAtomicAction (folder.getPrimaryFile().getFileSystem(), me);
1379
                me.mi = null;
1379
                me.mi = null;
1380
                me.folder = null;
1380
                me.folder = null;
1381
                me.instance = null;
1381
                me.instance = null;
(-)test/unit/src/org/openide/loaders/SeparationOfThreadsTest.java (+290 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.loaders;
15
16
import org.openide.filesystems.*;
17
import org.openide.loaders.*;
18
import java.beans.*;
19
import java.io.IOException;
20
import junit.textui.TestRunner;
21
import org.netbeans.junit.*;
22
23
/* 
24
 * Checks whether a during a modify operation (copy, move) some
25
 * other thread can get a grip on unfinished and uncostructed 
26
 * content on filesystem.
27
 *
28
 * @author Jaroslav Tulach
29
 */
30
public class SeparationOfThreadsTest extends NbTestCase {
31
    private DataFolder root;
32
    private DataFolder to;
33
    private DataObject a;
34
    private DataObject b;
35
    private DataObject res;
36
37
    /** Creates the test */
38
    public SeparationOfThreadsTest(String name) {
39
        super(name);
40
    }
41
42
    // For each test setup a FileSystem and DataObjects
43
    protected void setUp() throws Exception {
44
        String fsstruct [] = new String [] {
45
            "A.attr", 
46
            "B.attr",
47
            "dir/"
48
        };
49
        TestUtilHid.destroyLocalFileSystem (getName());
50
        FileSystem fs = TestUtilHid.createLocalFileSystem (getName(), fsstruct);
51
        root = DataFolder.findFolder (fs.getRoot ());
52
        
53
        AddLoaderManuallyHid.addRemoveLoader (ALoader.getLoader (ALoader.class), true);
54
        AddLoaderManuallyHid.addRemoveLoader (BLoader.getLoader (BLoader.class), true);
55
        
56
        to = DataFolder.findFolder (fs.findResource (fsstruct[2]));
57
        
58
        fs.findResource (fsstruct[0]).setAttribute ("A", Boolean.TRUE);
59
        
60
        a = DataObject.find (fs.findResource (fsstruct[0]));
61
        b = DataObject.find (fs.findResource (fsstruct[1]));
62
        
63
        ALoader loaderA = (ALoader)ALoader.getLoader (ALoader.class);
64
        
65
        assertEquals ("A is loaded by ALoader", loaderA, a.getLoader());
66
        assertEquals ("B is loaded by BLoader", ALoader.getLoader (BLoader.class), b.getLoader());
67
68
        
69
        synchronized (loaderA) {
70
            new Thread ((Runnable)loaderA).start ();
71
            loaderA.wait ();
72
        }
73
    }
74
    
75
    //Clear all stuff when the test finish
76
    protected void tearDown() throws Exception {
77
        ALoader loader = (ALoader)ALoader.getLoader(ALoader.class);
78
        synchronized (loader) {
79
            try {
80
                while (!loader.finished) {
81
                    loader.wait ();
82
                }
83
                
84
                assertNotNull (res);
85
                assertEquals ("The right loader synchronously", loader, res.getLoader ());
86
                
87
                if (loader.asyncError != null) {
88
                    throw loader.asyncError;
89
                }
90
                
91
                assertNotNull (loader.asyncRes);
92
                assertEquals ("It is the right loader asynchronously", loader, loader.asyncRes.getLoader());
93
                
94
            } finally {
95
                loader.asyncError = null;
96
                loader.currentThread = null;
97
                loader.current = null;
98
                loader.asyncRes = null;
99
                loader.finished = false;
100
                // clears any such flag
101
                Thread.interrupted();
102
103
104
                TestUtilHid.destroyLocalFileSystem (getName());
105
                AddLoaderManuallyHid.addRemoveLoader (ALoader.getLoader (ALoader.class), false);
106
                AddLoaderManuallyHid.addRemoveLoader (BLoader.getLoader (BLoader.class), false);
107
                
108
                // end of test
109
                loader.notify ();
110
            }            
111
        }
112
    }
113
    
114
    public static void main (String[] args) throws Exception {
115
         TestRunner.run(new NbTestSuite(SeparationOfThreadsTest.class));
116
    }    
117
118
    
119
    public void testCopy () throws Exception {
120
        res = a.copy (to);
121
    }
122
    
123
    public void testCreateFromTemplate () throws Exception {
124
        res = a.createFromTemplate (to);
125
    }
126
    public void testMove () throws Exception {
127
        a.move (to);
128
        res = a;
129
    }
130
    public void testRename () throws Exception {
131
        a.rename ("AnyThing");
132
        res = a;
133
    }
134
    
135
    //
136
    // Inner classes
137
    //
138
    
139
    public static final class ALoader extends UniFileLoader implements Runnable {
140
        DataObject asyncRes;
141
        Exception asyncError;
142
        FileObject current;
143
        Thread currentThread;
144
        boolean finished;
145
        
146
        public ALoader() {
147
            super(DataObject.class.getName());
148
        }
149
        protected void initialize() {
150
            super.initialize();
151
            getExtensions().addExtension("attr");
152
        }
153
        protected String displayName() {
154
            return getClass().getName ();
155
        }
156
        protected MultiDataObject createMultiObject(FileObject pf) throws IOException {
157
            return new MultiDataObject(pf, this);
158
        }
159
        
160
        protected org.openide.loaders.MultiDataObject.Entry createPrimaryEntry(org.openide.loaders.MultiDataObject multiDataObject, org.openide.filesystems.FileObject fileObject) {
161
            return new SlowEntry (multiDataObject, fileObject);
162
        }
163
        
164
        // 
165
        // Notification that the copy is in middle
166
        // 
167
        
168
        public void notifyCopied (FileObject current) {
169
            synchronized (this) {
170
                this.current = current;
171
                this.currentThread = Thread.currentThread ();
172
                this.notify ();
173
            }
174
            try {
175
                Thread.sleep (500);
176
            } catch (InterruptedException ex) {
177
                // is interrupted to be wake up sooner
178
            }
179
        }
180
        
181
        //
182
        // The second thread that waits for the copy operation
183
        //
184
        public void run () {
185
            DataLoader loader = this;
186
            synchronized (loader) {
187
                // continue execution in setUp
188
                loader.notify ();
189
                // wait for being notify about copying
190
                try {
191
                    loader.wait ();
192
                } catch (InterruptedException ex) {
193
                    asyncError = ex;
194
                }
195
196
                try {
197
                    asyncRes = DataObject.find (current);
198
                    currentThread.interrupt();
199
                } catch (IOException ex) {
200
                    asyncError = ex;
201
                }
202
                
203
                // notify that we have computed everything
204
                finished = true;
205
                loader.notify ();
206
                
207
                while (asyncRes != null && asyncError != null) {
208
                    try {
209
                        loader.wait ();
210
                    } catch (InterruptedException ex) {
211
                    }
212
                }
213
            }
214
        }
215
        
216
    }
217
    
218
    public static final class BLoader extends UniFileLoader {
219
        public BLoader() {
220
            super(DataObject.class.getName());
221
        }
222
        protected void initialize() {
223
            super.initialize();
224
            getExtensions().addExtension("attr");
225
        }
226
        protected String displayName() {
227
            return getClass ().getName ();
228
        }
229
        protected org.openide.filesystems.FileObject findPrimaryFile(org.openide.filesystems.FileObject fileObject) {
230
            if (Boolean.TRUE.equals (fileObject.getAttribute ("A"))) {
231
                return null;
232
            }
233
            
234
            org.openide.filesystems.FileObject retValue;
235
            
236
            retValue = super.findPrimaryFile(fileObject);
237
            return retValue;
238
        }        
239
        
240
        protected MultiDataObject createMultiObject(FileObject pf) throws IOException {
241
            return new MultiDataObject(pf, this);
242
        }
243
    }
244
    
245
    private static final class SlowEntry extends MultiDataObject.Entry {
246
        public SlowEntry (MultiDataObject obj, FileObject fo) {
247
            obj.super (fo);
248
        }
249
        
250
        private void notifyCopied (FileObject fo) {
251
            ALoader l = (ALoader)ALoader.getLoader(ALoader.class);
252
            l.notifyCopied (fo);
253
        }
254
        
255
        public org.openide.filesystems.FileObject copy(org.openide.filesystems.FileObject fileObject, String str) throws java.io.IOException {
256
            FileObject ret = fileObject.createData ("copy", "attr");
257
            notifyCopied (ret);
258
            ret.setAttribute ("A", Boolean.TRUE);
259
            return ret;
260
        }
261
        
262
        public org.openide.filesystems.FileObject createFromTemplate(org.openide.filesystems.FileObject fileObject, String str) throws java.io.IOException {
263
            FileObject ret = fileObject.createData ("createFromTemplate", "attr");
264
            notifyCopied (ret);
265
            ret.setAttribute ("A", Boolean.TRUE);
266
            return ret;
267
        }
268
        
269
        public void delete() throws java.io.IOException {
270
            throw new IOException ("Not implemented");
271
        }
272
        
273
        public org.openide.filesystems.FileObject move(org.openide.filesystems.FileObject fileObject, String str) throws java.io.IOException {
274
            FileObject ret = fileObject.createData ("move", "attr");
275
            notifyCopied (ret);
276
            ret.setAttribute ("A", Boolean.TRUE);
277
            super.getFile ().delete ();
278
            return ret;
279
        }
280
        
281
        public org.openide.filesystems.FileObject rename(String str) throws java.io.IOException {
282
            FileObject ret = getFile ().getParent ().createData ("rename", "attr");
283
            notifyCopied (ret);
284
            ret.setAttribute ("A", Boolean.TRUE);
285
            super.getFile ().delete ();
286
            return ret;
287
        }
288
        
289
    }
290
}

Return to bug 33750