Lines 68-73
Link Here
|
68 |
import java.util.Queue; |
68 |
import java.util.Queue; |
69 |
import java.util.Set; |
69 |
import java.util.Set; |
70 |
import java.util.StringTokenizer; |
70 |
import java.util.StringTokenizer; |
|
|
71 |
import java.util.concurrent.ExecutionException; |
72 |
import java.util.concurrent.Future; |
73 |
import java.util.concurrent.Semaphore; |
74 |
import java.util.concurrent.TimeUnit; |
75 |
import java.util.concurrent.TimeoutException; |
76 |
import java.util.concurrent.locks.Condition; |
77 |
import java.util.concurrent.locks.Lock; |
78 |
import java.util.concurrent.locks.ReentrantLock; |
71 |
import java.util.logging.Level; |
79 |
import java.util.logging.Level; |
72 |
import java.util.logging.LogRecord; |
80 |
import java.util.logging.LogRecord; |
73 |
import java.util.logging.Logger; |
81 |
import java.util.logging.Logger; |
Lines 199-206
Link Here
|
199 |
} |
207 |
} |
200 |
} |
208 |
} |
201 |
|
209 |
|
|
|
210 |
Future<Project[]> openProjectsAPI() { |
211 |
return LOAD; |
212 |
} |
202 |
|
213 |
|
203 |
private final class LoadOpenProjects implements Runnable, LookupListener { |
214 |
|
|
|
215 |
private final class LoadOpenProjects implements Runnable, LookupListener, Future<Project[]> { |
204 |
final RequestProcessor RP = new RequestProcessor("Load Open Projects"); // NOI18N |
216 |
final RequestProcessor RP = new RequestProcessor("Load Open Projects"); // NOI18N |
205 |
final RequestProcessor.Task TASK = RP.create(this); |
217 |
final RequestProcessor.Task TASK = RP.create(this); |
206 |
private int action; |
218 |
private int action; |
Lines 209-214
Link Here
|
209 |
private List<String> recentTemplates; |
221 |
private List<String> recentTemplates; |
210 |
private Project mainProject; |
222 |
private Project mainProject; |
211 |
private Lookup.Result<FileObject> currentFiles; |
223 |
private Lookup.Result<FileObject> currentFiles; |
|
|
224 |
private int entered; |
225 |
private final Lock enteredGuard = new ReentrantLock(); |
226 |
private final Condition enteredZeroed = enteredGuard.newCondition(); |
212 |
|
227 |
|
213 |
public LoadOpenProjects(int a) { |
228 |
public LoadOpenProjects(int a) { |
214 |
action = a; |
229 |
action = a; |
Lines 321-328
Link Here
|
321 |
} |
336 |
} |
322 |
|
337 |
|
323 |
} |
338 |
} |
|
|
339 |
|
340 |
final void enter() { |
341 |
try { |
342 |
enteredGuard.lock(); |
343 |
entered++; |
344 |
} finally { |
345 |
enteredGuard.unlock(); |
324 |
} |
346 |
} |
|
|
347 |
} |
325 |
|
348 |
|
|
|
349 |
final void exit() { |
350 |
try { |
351 |
enteredGuard.lock(); |
352 |
if (--entered == 0) { |
353 |
enteredZeroed.signalAll(); |
354 |
} |
355 |
} finally { |
356 |
enteredGuard.unlock(); |
357 |
} |
358 |
|
359 |
} |
360 |
|
361 |
|
362 |
public boolean cancel(boolean mayInterruptIfRunning) { |
363 |
return false; |
364 |
} |
365 |
|
366 |
public boolean isCancelled() { |
367 |
return false; |
368 |
} |
369 |
|
370 |
public boolean isDone() { |
371 |
return TASK.isFinished() && entered == 0; |
372 |
} |
373 |
|
374 |
public Project[] get() throws InterruptedException, ExecutionException { |
375 |
TASK.waitFinished(); |
376 |
try { |
377 |
enteredGuard.lock(); |
378 |
while (entered > 0) { |
379 |
enteredZeroed.await(); |
380 |
} |
381 |
} finally { |
382 |
enteredGuard.unlock(); |
383 |
} |
384 |
return getDefault().getOpenProjects(); |
385 |
} |
386 |
|
387 |
public Project[] get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { |
388 |
long ms = unit.convert(timeout, TimeUnit.MILLISECONDS); |
389 |
if (!TASK.waitFinished(timeout)) { |
390 |
throw new TimeoutException(); |
391 |
} |
392 |
try { |
393 |
enteredGuard.lock(); |
394 |
if (entered > 0) { |
395 |
if (!enteredZeroed.await(ms, TimeUnit.MILLISECONDS)) { |
396 |
throw new TimeoutException(); |
397 |
} |
398 |
} |
399 |
} finally { |
400 |
enteredGuard.unlock(); |
401 |
} |
402 |
return getDefault().getOpenProjects(); |
403 |
} |
404 |
} |
405 |
|
326 |
public void open( Project p ) { |
406 |
public void open( Project p ) { |
327 |
open( new Project[] {p}, false ); |
407 |
open( new Project[] {p}, false ); |
328 |
} |
408 |
} |
Lines 407-412
Link Here
|
407 |
assert !Arrays.asList(projects).contains(null) : "Projects can't be null"; |
487 |
assert !Arrays.asList(projects).contains(null) : "Projects can't be null"; |
408 |
LOAD.waitFinished(); |
488 |
LOAD.waitFinished(); |
409 |
|
489 |
|
|
|
490 |
|
491 |
try { |
492 |
LOAD.enter(); |
410 |
boolean recentProjectsChanged = false; |
493 |
boolean recentProjectsChanged = false; |
411 |
int maxWork = 1000; |
494 |
int maxWork = 1000; |
412 |
int workForSubprojects = maxWork / 2; |
495 |
int workForSubprojects = maxWork / 2; |
Lines 502-508
Link Here
|
502 |
LogRecord[] addedRec = createRecord("UI_OPEN_PROJECTS", projectsToOpen.toArray(new Project[0])); // NOI18N |
585 |
LogRecord[] addedRec = createRecord("UI_OPEN_PROJECTS", projectsToOpen.toArray(new Project[0])); // NOI18N |
503 |
log(addedRec); |
586 |
log(addedRec); |
504 |
|
587 |
|
505 |
|
|
|
506 |
Mutex.EVENT.readAccess(new Action<Void>() { |
588 |
Mutex.EVENT.readAccess(new Action<Void>() { |
507 |
public Void run() { |
589 |
public Void run() { |
508 |
pchSupport.firePropertyChange( PROPERTY_OPEN_PROJECTS, oldprjs.toArray(new Project[oldprjs.size()]), |
590 |
pchSupport.firePropertyChange( PROPERTY_OPEN_PROJECTS, oldprjs.toArray(new Project[oldprjs.size()]), |
Lines 514-526
Link Here
|
514 |
return null; |
596 |
return null; |
515 |
} |
597 |
} |
516 |
}); |
598 |
}); |
|
|
599 |
} finally { |
600 |
LOAD.exit(); |
517 |
} |
601 |
} |
|
|
602 |
} |
518 |
|
603 |
|
519 |
public void close( Project projects[], boolean notifyUI ) { |
604 |
public void close( Project projects[], boolean notifyUI ) { |
520 |
LOAD.waitFinished(); |
605 |
LOAD.waitFinished(); |
521 |
if (!ProjectUtilities.closeAllDocuments (projects, notifyUI )) { |
606 |
if (!ProjectUtilities.closeAllDocuments (projects, notifyUI )) { |
522 |
return; |
607 |
return; |
523 |
} |
608 |
} |
|
|
609 |
|
610 |
try { |
611 |
LOAD.enter(); |
612 |
|
524 |
logProjects("close(): closing project: ", projects); |
613 |
logProjects("close(): closing project: ", projects); |
525 |
boolean mainClosed = false; |
614 |
boolean mainClosed = false; |
526 |
boolean someClosed = false; |
615 |
boolean someClosed = false; |
Lines 577-583
Link Here
|
577 |
} |
666 |
} |
578 |
LogRecord[] removedRec = createRecord("UI_CLOSED_PROJECTS", projects); // NOI18N |
667 |
LogRecord[] removedRec = createRecord("UI_CLOSED_PROJECTS", projects); // NOI18N |
579 |
log(removedRec); |
668 |
log(removedRec); |
|
|
669 |
} finally { |
670 |
LOAD.exit(); |
580 |
} |
671 |
} |
|
|
672 |
} |
581 |
|
673 |
|
582 |
public synchronized Project[] getOpenProjects() { |
674 |
public synchronized Project[] getOpenProjects() { |
583 |
Project projects[] = new Project[ openProjects.size() ]; |
675 |
Project projects[] = new Project[ openProjects.size() ]; |