< prev index next >

src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java

Print this page




  24  */
  25 
  26 package sun.awt.shell;
  27 
  28 import java.awt.*;
  29 import java.awt.image.BufferedImage;
  30 
  31 import java.io.File;
  32 import java.io.FileNotFoundException;
  33 import java.io.IOException;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 import java.util.*;
  37 import java.util.List;
  38 import java.util.concurrent.*;
  39 import java.util.stream.Stream;
  40 
  41 import static sun.awt.shell.Win32ShellFolder2.*;
  42 import sun.awt.OSInfo;
  43 import sun.awt.util.ThreadGroupUtils;
  44 import sun.misc.ManagedLocalsThread;
  45 // NOTE: This class supersedes Win32ShellFolderManager, which was removed
  46 //       from distribution after version 1.4.2.
  47 
  48 /**
  49  * @author Michael Martak
  50  * @author Leif Samuelsson
  51  * @author Kenneth Russell
  52  * @since 1.4
  53  */
  54 
  55 final class Win32ShellFolderManager2 extends ShellFolderManager {
  56 
  57     static {
  58         // Load library here
  59         sun.awt.windows.WToolkit.loadLibraries();
  60     }
  61 
  62     public ShellFolder createShellFolder(File file) throws FileNotFoundException {
  63         try {
  64             return createShellFolder(getDesktop(), file);


 507         }
 508     }
 509 
 510     @Override
 511     protected Invoker createInvoker() {
 512         return new ComInvoker();
 513     }
 514 
 515     private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker {
 516         private static Thread comThread;
 517 
 518         private ComInvoker() {
 519             super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>());
 520             allowCoreThreadTimeOut(false);
 521             setThreadFactory(this);
 522             final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 523                 shutdownNow();
 524                 return null;
 525             });
 526             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 527                 Thread t = new ManagedLocalsThread(
 528                         ThreadGroupUtils.getRootThreadGroup(), shutdownHook);

 529                 Runtime.getRuntime().addShutdownHook(t);
 530                 return null;
 531             });
 532         }
 533 
 534         public synchronized Thread newThread(final Runnable task) {
 535             final Runnable comRun = new Runnable() {
 536                 public void run() {
 537                     try {
 538                         initializeCom();
 539                         task.run();
 540                     } finally {
 541                         uninitializeCom();
 542                     }
 543                 }
 544             };
 545             comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
 546                 String name = "Swing-Shell";
 547                  /* The thread must be a member of a thread group
 548                   * which will not get GCed before VM exit.
 549                   * Make its parent the top-level thread group.
 550                   */
 551                 Thread thread = new ManagedLocalsThread(
 552                         ThreadGroupUtils.getRootThreadGroup(), comRun, name);

 553                 thread.setDaemon(true);
 554                 return thread;
 555             });
 556             return comThread;
 557         }
 558 
 559         public <T> T invoke(Callable<T> task) throws Exception {
 560             if (Thread.currentThread() == comThread) {
 561                 // if it's already called from the COM
 562                 // thread, we don't need to delegate the task
 563                 return task.call();
 564             } else {
 565                 final Future<T> future;
 566 
 567                 try {
 568                     future = submit(task);
 569                 } catch (RejectedExecutionException e) {
 570                     throw new InterruptedException(e.getMessage());
 571                 }
 572 




  24  */
  25 
  26 package sun.awt.shell;
  27 
  28 import java.awt.*;
  29 import java.awt.image.BufferedImage;
  30 
  31 import java.io.File;
  32 import java.io.FileNotFoundException;
  33 import java.io.IOException;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 import java.util.*;
  37 import java.util.List;
  38 import java.util.concurrent.*;
  39 import java.util.stream.Stream;
  40 
  41 import static sun.awt.shell.Win32ShellFolder2.*;
  42 import sun.awt.OSInfo;
  43 import sun.awt.util.ThreadGroupUtils;

  44 // NOTE: This class supersedes Win32ShellFolderManager, which was removed
  45 //       from distribution after version 1.4.2.
  46 
  47 /**
  48  * @author Michael Martak
  49  * @author Leif Samuelsson
  50  * @author Kenneth Russell
  51  * @since 1.4
  52  */
  53 
  54 final class Win32ShellFolderManager2 extends ShellFolderManager {
  55 
  56     static {
  57         // Load library here
  58         sun.awt.windows.WToolkit.loadLibraries();
  59     }
  60 
  61     public ShellFolder createShellFolder(File file) throws FileNotFoundException {
  62         try {
  63             return createShellFolder(getDesktop(), file);


 506         }
 507     }
 508 
 509     @Override
 510     protected Invoker createInvoker() {
 511         return new ComInvoker();
 512     }
 513 
 514     private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker {
 515         private static Thread comThread;
 516 
 517         private ComInvoker() {
 518             super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>());
 519             allowCoreThreadTimeOut(false);
 520             setThreadFactory(this);
 521             final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 522                 shutdownNow();
 523                 return null;
 524             });
 525             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 526                 Thread t = new Thread(
 527                         ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
 528                         "ShellFolder", 0, false);
 529                 Runtime.getRuntime().addShutdownHook(t);
 530                 return null;
 531             });
 532         }
 533 
 534         public synchronized Thread newThread(final Runnable task) {
 535             final Runnable comRun = new Runnable() {
 536                 public void run() {
 537                     try {
 538                         initializeCom();
 539                         task.run();
 540                     } finally {
 541                         uninitializeCom();
 542                     }
 543                 }
 544             };
 545             comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
 546                 String name = "Swing-Shell";
 547                  /* The thread must be a member of a thread group
 548                   * which will not get GCed before VM exit.
 549                   * Make its parent the top-level thread group.
 550                   */
 551                 Thread thread = new Thread(
 552                         ThreadGroupUtils.getRootThreadGroup(), comRun, name,
 553                         0, false);
 554                 thread.setDaemon(true);
 555                 return thread;
 556             });
 557             return comThread;
 558         }
 559 
 560         public <T> T invoke(Callable<T> task) throws Exception {
 561             if (Thread.currentThread() == comThread) {
 562                 // if it's already called from the COM
 563                 // thread, we don't need to delegate the task
 564                 return task.call();
 565             } else {
 566                 final Future<T> future;
 567 
 568                 try {
 569                     future = submit(task);
 570                 } catch (RejectedExecutionException e) {
 571                     throw new InterruptedException(e.getMessage());
 572                 }
 573 


< prev index next >