Java 类com.intellij.openapi.util.ShutDownTracker 实例源码

项目:intellij-ce-playground    文件:LocalHistoryImpl.java   
@Override
public void disposeComponent() {
  if (!isInitialized.getAndSet(false)) return;

  long period = Registry.intValue("localHistory.daysToKeep") * 1000L * 60L * 60L * 24L;

  VirtualFileManager fm = VirtualFileManager.getInstance();
  fm.removeVirtualFileListener(myEventDispatcher);
  fm.removeVirtualFileManagerListener(myEventDispatcher);
  CommandProcessor.getInstance().removeCommandListener(myEventDispatcher);


  validateStorage();
  LocalHistoryLog.LOG.debug("Purging local history...");
  myChangeList.purgeObsolete(period);
  validateStorage();

  myChangeList.close();
  LocalHistoryLog.LOG.debug("Local history storage successfully closed.");

  ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask);
}
项目:intellij-ce-playground    文件:RemoteExternalSystemCommunicationManager.java   
public RemoteExternalSystemCommunicationManager(@NotNull ExternalSystemProgressNotificationManager notificationManager) {
  myProgressManager = (ExternalSystemProgressNotificationManagerImpl)notificationManager;
  mySupport = new RemoteProcessSupport<Object, RemoteExternalSystemFacade, String>(RemoteExternalSystemFacade.class) {
    @Override
    protected void fireModificationCountChanged() {
    }

    @Override
    protected String getName(Object o) {
      return RemoteExternalSystemFacade.class.getName();
    }

    @Override
    protected RunProfileState getRunProfileState(Object o, String configuration, Executor executor) throws ExecutionException {
      return createRunProfileState(configuration);
    }
  };

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    public void run() {
      shutdown(false);
    }
  });
}
项目:intellij-ce-playground    文件:LightPlatformTestCase.java   
private static void registerShutdownHook() {
  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      ShutDownTracker.invokeAndWait(true, true, new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              closeAndDeleteProject();
            }
          });
        }
      });
    }
  });
}
项目:intellij-ce-playground    文件:SerializationManagerImpl.java   
public SerializationManagerImpl() {
  myFile.getParentFile().mkdirs();
  try {
    // we need to cache last id -> String mappings due to StringRefs and stubs indexing that initially creates stubs (doing enumerate on String)
    // and then index them (valueOf), also similar string items are expected to be enumerated during stubs processing
    myNameStorage = new PersistentStringEnumerator(myFile, true);
    myStubSerializationHelper = new StubSerializationHelper(myNameStorage);
  }
  catch (IOException e) {
    nameStorageCrashed();
    LOG.info(e);
    repairNameStorage(); // need this in order for myNameStorage not to be null
    nameStorageCrashed();
  }
  finally {
    registerSerializer(PsiFileStubImpl.TYPE);
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      @Override
      public void run() {
        performShutdown();
      }
    });
  }
}
项目:intellij-ce-playground    文件:TracingData.java   
TracingData() {
  PersistentHashMap<Integer, Integer> lkeys = null;
  try {
    lkeys = createOrOpenMap();
    flushingFuture = pool.scheduleWithFixedDelay(new Runnable() {
      @Override
      public void run() {
        if (keys.isDirty() && !keys.isClosed()) {
          keys.force();
        }
      }
    }, 5, 5, TimeUnit.SECONDS);
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      @Override
      public void run() {
        flushingFuture.cancel(false);
      }
    });
  } catch (IOException ex) {
    ex.printStackTrace();
  }
  keys = lkeys;
}
项目:intellij-ce-playground    文件:HgUtil.java   
/**
 * Returns a temporary python file that will be deleted on exit.
 *
 * Also all compiled version of the python file will be deleted.
 *
 * @param base The basename of the file to copy
 * @return The temporary copy the specified python file, with all the necessary hooks installed
 * to make sure it is completely removed at shutdown
 */
@Nullable
public static File getTemporaryPythonFile(String base) {
  try {
    final File file = copyResourceToTempFile(base, ".py");
    final String fileName = file.getName();
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      public void run() {
        File[] files = file.getParentFile().listFiles(new FilenameFilter() {
          public boolean accept(File dir, String name) {
            return name.startsWith(fileName);
          }
        });
        if (files != null) {
          for (File file1 : files) {
            file1.delete();
          }
        }
      }
    });
    return file;
  } catch (IOException e) {
    return null;
  }
}
项目:tools-idea    文件:LocalHistoryImpl.java   
@Override
public void disposeComponent() {
  if (!isInitialized.getAndSet(false)) return;

  int period = Registry.intValue("localHistory.daysToKeep") * 1000 * 60 * 60 * 24;

  VirtualFileManager fm = VirtualFileManager.getInstance();
  fm.removeVirtualFileListener(myEventDispatcher);
  fm.removeVirtualFileManagerListener(myEventDispatcher);
  CommandProcessor.getInstance().removeCommandListener(myEventDispatcher);


  validateStorage();
  LocalHistoryLog.LOG.info("Purging local history...");
  myChangeList.purgeObsolete(period);
  validateStorage();

  myChangeList.close();
  LocalHistoryLog.LOG.info("Local history storage successfully closed.");

  ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask);
}
项目:tools-idea    文件:LightPlatformTestCase.java   
private static void registerShutdownHook() {
  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      ShutDownTracker.invokeAndWait(true, true, new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              closeAndDeleteProject();
            }
          });
        }
      });
    }
  });
}
项目:tools-idea    文件:SerializationManagerImpl.java   
public SerializationManagerImpl() {
  myFile.getParentFile().mkdirs();
  try {
    // we need to cache last id -> String mappings due to StringRefs and stubs indexing that initially creates stubs (doing enumerate on String)
    // and then index them (valueOf), also similar string items are expected to be enumerated during stubs processing
    myNameStorage = new PersistentStringEnumerator(myFile, true);
    myStubSerializationHelper = new StubSerializationHelper(myNameStorage);
  }
  catch (IOException e) {
    nameStorageCrashed();
    LOG.info(e);
    repairNameStorage(); // need this in order for myNameStorage not to be null
    nameStorageCrashed();
  }
  finally {
    registerSerializer(PsiFileStubImpl.TYPE);
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      @Override
      public void run() {
        performShutdown();
      }
    });
  }
}
项目:tools-idea    文件:MavenServerManager.java   
public MavenServerManager() {
  super(null);

  mySupport = new RemoteProcessSupport<Object, MavenServer, Object>(MavenServer.class) {
    @Override
    protected void fireModificationCountChanged() {
    }

    @Override
    protected String getName(Object file) {
      return MavenServerManager.class.getSimpleName();
    }

    @Override
    protected RunProfileState getRunProfileState(Object target, Object configuration, Executor executor) throws ExecutionException {
      return createRunProfileState();
    }
  };

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    public void run() {
      shutdown(false);
    }
  });
}
项目:tools-idea    文件:HgUtil.java   
/**
 * Returns a temporary python file that will be deleted on exit.
 *
 * Also all compiled version of the python file will be deleted.
 *
 * @param base The basename of the file to copy
 * @return The temporary copy the specified python file, with all the necessary hooks installed
 * to make sure it is completely removed at shutdown
 */
@Nullable
public static File getTemporaryPythonFile(String base) {
  try {
    final File file = copyResourceToTempFile(base, ".py");
    final String fileName = file.getName();
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      public void run() {
        File[] files = file.getParentFile().listFiles(new FilenameFilter() {
          public boolean accept(File dir, String name) {
            return name.startsWith(fileName);
          }
        });
        if (files != null) {
          for (File file1 : files) {
            file1.delete();
          }
        }
      }
    });
    return file;
  } catch (IOException e) {
    return null;
  }
}
项目:consulo    文件:RemoteExternalSystemCommunicationManager.java   
public RemoteExternalSystemCommunicationManager(@Nonnull ExternalSystemProgressNotificationManager notificationManager) {
  myProgressManager = (ExternalSystemProgressNotificationManagerImpl)notificationManager;
  mySupport = new RemoteProcessSupport<Object, RemoteExternalSystemFacade, String>(RemoteExternalSystemFacade.class) {
    @Override
    protected void fireModificationCountChanged() {
    }

    @Override
    protected String getName(Object o) {
      return RemoteExternalSystemFacade.class.getName();
    }

    @Override
    protected RunProfileState getRunProfileState(Object o, String configuration, Executor executor) throws ExecutionException {
      return createRunProfileState();
    }
  };

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    public void run() {
      shutdown(false);
    }
  });
}
项目:consulo    文件:SerializationManagerImpl.java   
public SerializationManagerImpl() {
  myFile.getParentFile().mkdirs();
  try {
    // we need to cache last id -> String mappings due to StringRefs and stubs indexing that initially creates stubs (doing enumerate on String)
    // and then index them (valueOf), also similar string items are expected to be enumerated during stubs processing
    myNameStorage = new PersistentStringEnumerator(myFile, true);
    myStubSerializationHelper = new StubSerializationHelper(myNameStorage);
  }
  catch (IOException e) {
    nameStorageCrashed();
    LOG.info(e);
    repairNameStorage(); // need this in order for myNameStorage not to be null
    nameStorageCrashed();
  }
  finally {
    registerSerializer(PsiFileStubImpl.TYPE);
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      @Override
      public void run() {
        performShutdown();
      }
    });
  }
}
项目:consulo    文件:ContentHashesSupport.java   
static void initContentHashesEnumerator() throws IOException {
  if (ourHashesWithFileType != null) return;
  synchronized (ContentHashesSupport.class) {
    if (ourHashesWithFileType != null) return;
    final File hashEnumeratorFile = new File(IndexInfrastructure.getPersistentIndexRoot(), "hashesWithFileType");
    try {
      ContentHashesUtil.HashEnumerator hashEnumerator = new ContentHashesUtil.HashEnumerator(hashEnumeratorFile, null);
      FlushingDaemon.everyFiveSeconds(ContentHashesSupport::flushContentHashes);
      ShutDownTracker.getInstance().registerShutdownTask(ContentHashesSupport::flushContentHashes);
      ourHashesWithFileType = hashEnumerator;
    }
    catch (IOException ex) {
      IOUtil.deleteAllFilesStartingWith(hashEnumeratorFile);
      throw ex;
    }
  }
}
项目:intellij-ce-playground    文件:LocalHistoryImpl.java   
@Override
public void initComponent() {
  if (!ApplicationManager.getApplication().isUnitTestMode() && ApplicationManager.getApplication().isHeadlessEnvironment()) return;

  myShutdownTask = new Runnable() {
    @Override
    public void run() {
      disposeComponent();
    }
  };
  ShutDownTracker.getInstance().registerShutdownTask(myShutdownTask);

  initHistory();
  isInitialized.set(true);
}
项目:intellij-ce-playground    文件:PersistentFSImpl.java   
public PersistentFSImpl(@NotNull MessageBus bus) {
  myEventBus = bus;
  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      performShutdown();
    }
  });
}
项目:intellij-ce-playground    文件:NativeFileWatcherImpl.java   
private void startupProcess(boolean restart) throws IOException {
  if (myIsShuttingDown) {
    return;
  }
  if (ShutDownTracker.isShutdownHookRunning()) {
    myIsShuttingDown = true;
    return;
  }

  if (myStartAttemptCount++ > MAX_PROCESS_LAUNCH_ATTEMPT_COUNT) {
    notifyOnFailure(ApplicationBundle.message("watcher.failed.to.start"), null);
    return;
  }

  if (restart) {
    shutdownProcess();
  }

  LOG.info("Starting file watcher: " + myExecutable);
  ProcessBuilder processBuilder = new ProcessBuilder(myExecutable.getAbsolutePath());
  Process process = processBuilder.start();
  myProcessHandler = new MyProcessHandler(process);
  myProcessHandler.addProcessListener(new MyProcessAdapter());
  myProcessHandler.startNotify();

  if (restart) {
    List<String> recursive = myRecursiveWatchRoots;
    List<String> flat = myFlatWatchRoots;
    if (recursive.size() + flat.size() > 0) {
      setWatchRoots(recursive, flat, true);
    }
  }
}
项目:intellij-ce-playground    文件:StartupUtil.java   
private synchronized static boolean lockSystemFolders(String[] args) {
  if (ourLock != null) {
    throw new AssertionError();
  }

  ourLock = new SocketLock(PathManager.getConfigPath(), PathManager.getSystemPath());

  SocketLock.ActivateStatus status;
  try {
    status = ourLock.lock(args);
  }
  catch (Exception e) {
    Main.showMessage("Cannot Lock System Folders", e);
    return false;
  }

  if (status == SocketLock.ActivateStatus.NO_INSTANCE) {
    ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
      @Override
      public void run() {
        ourLock.dispose();
      }
    });
    return true;
  }
  else if (Main.isHeadless() || status == SocketLock.ActivateStatus.CANNOT_ACTIVATE) {
    String message = "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time.";
    Main.showMessage("Too Many Instances", message, true);
  }

  return false;
}
项目:intellij-ce-playground    文件:ContentHashesSupport.java   
static void initContentHashesEnumerator() throws IOException {
  if (ourHashesWithFileType != null) return;
  synchronized (ContentHashesSupport.class) {
    if (ourHashesWithFileType != null) return;
    ContentHashesUtil.HashEnumerator hashEnumerator = null;
    final File hashEnumeratorFile = new File(IndexInfrastructure.getPersistentIndexRoot(), "hashesWithFileType");
    try {
      hashEnumerator = new ContentHashesUtil.HashEnumerator(hashEnumeratorFile, null);
      FlushingDaemon.everyFiveSeconds(new Runnable() {
        @Override
        public void run() {
          flushContentHashes();
        }
      });
      ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
        @Override
        public void run() {
          flushContentHashes();
        }
      });
      ourHashesWithFileType = hashEnumerator;
    } catch (IOException ex) {
      IOUtil.deleteAllFilesStartingWith(hashEnumeratorFile);
      throw ex;
    }
  }
}
项目:intellij-ce-playground    文件:Maven3ServerIndexerImpl.java   
public Maven3ServerIndexerImpl(Maven3ServerEmbedder embedder) throws RemoteException {
  myEmbedder = embedder;

  myIndexer = myEmbedder.getComponent(NexusIndexer.class);
  myUpdater = myEmbedder.getComponent(IndexUpdater.class);
  myArtifactContextProducer = myEmbedder.getComponent(ArtifactContextProducer.class);

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      release();
    }
  });
}
项目:intellij-ce-playground    文件:MavenServerManager.java   
public MavenServerManager() {
  super(null);

  final File pluginFileOrDir = new File(PathUtil.getJarPathForClass(MavenServerManager.class));
  final String root = pluginFileOrDir.getParent();

  if (pluginFileOrDir.isDirectory()) {
    File parentFile = getMavenPluginParentFile();
    myBundledMaven2Home = new File(parentFile, "maven2-server-impl/lib/maven2");
    myBundledMaven3Home = new File(parentFile, "maven30-server-impl/lib/maven3");
  }
  else {
    myBundledMaven2Home = new File(root, "maven2");
    myBundledMaven3Home = new File(root, "maven3");
  }

  mySupport = new RemoteProcessSupport<Object, MavenServer, Object>(MavenServer.class) {
    @Override
    protected void fireModificationCountChanged() {
    }

    @Override
    protected String getName(Object file) {
      return MavenServerManager.class.getSimpleName();
    }

    @Override
    protected RunProfileState getRunProfileState(Object target, Object configuration, Executor executor) {
      return createRunProfileState();
    }
  };

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      shutdown(false);
    }
  });
}
项目:intellij-ce-playground    文件:Maven2ServerIndexerImpl.java   
public Maven2ServerIndexerImpl() throws RemoteException {
  myEmbedder = Maven2ServerEmbedderImpl.create(new MavenServerSettings());

  myIndexer = myEmbedder.getComponent(NexusIndexer.class);
  myUpdater = myEmbedder.getComponent(IndexUpdater.class);
  myArtifactContextProducer = myEmbedder.getComponent(ArtifactContextProducer.class);

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      release();
    }
  });
}
项目:aem-ide-tooling-4-intellij    文件:ConsoleLogProjectTracker.java   
private void doPrintNotification(@NotNull final Notification notification, @NotNull final ConsoleLogConsole console) {
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new DumbAwareRunnable() {
        @Override
        public void run() {
            if(!ShutDownTracker.isShutdownHookRunning() && !myProject.isDisposed()) {
                ApplicationManager.getApplication().runReadAction(new Runnable() {
                    public void run() {
                        console.doPrintNotification(notification);
                    }
                });
            }
        }
    });
}
项目:tools-idea    文件:LocalHistoryImpl.java   
@Override
public void initComponent() {
  if (!ApplicationManager.getApplication().isUnitTestMode() && ApplicationManager.getApplication().isHeadlessEnvironment()) return;

  myShutdownTask = new Runnable() {
    @Override
    public void run() {
      disposeComponent();
    }
  };
  ShutDownTracker.getInstance().registerShutdownTask(myShutdownTask);

  initHistory();
  isInitialized.set(true);
}
项目:tools-idea    文件:ExternalSystemFacadeManager.java   
public ExternalSystemFacadeManager(@NotNull ExternalSystemSettingsManager settingsManager,
                                   @NotNull ExternalSystemProgressNotificationManager notificationManager)
{
  mySettingsManager = settingsManager;
  myProgressManager = (ExternalSystemProgressNotificationManagerImpl)notificationManager;
  mySupport = new RemoteProcessSupport<Object, RemoteExternalSystemFacade, String>(RemoteExternalSystemFacade.class) {
    @Override
    protected void fireModificationCountChanged() {
    }

    @Override
    protected String getName(Object o) {
      return RemoteExternalSystemFacade.class.getName();
    }

    @Override
    protected RunProfileState getRunProfileState(Object o, String configuration, Executor executor) throws ExecutionException {
      return createRunProfileState();
    }
  };

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    public void run() {
      shutdown(false);
    }
  });
}
项目:tools-idea    文件:TrailingSpacesStripper.java   
public static boolean stripIfNotCurrentLine(Document document, boolean inChangedLinesOnly) {
  if (document instanceof DocumentWindow) {
    document = ((DocumentWindow)document).getDelegate();
  }
  if (!(document instanceof DocumentImpl)) {
    return true;
  }
  DataContext dataContext = DataManager.getInstance().getDataContext(IdeFocusManager.getGlobalInstance().getFocusOwner());
  boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting
  Editor activeEditor = isDisposeInProgress ? null : PlatformDataKeys.EDITOR.getData(dataContext);

  // when virtual space enabled, we can strip whitespace anywhere
  boolean isVirtualSpaceEnabled = activeEditor == null || activeEditor.getSettings().isVirtualSpace();

  VisualPosition visualCaret = activeEditor == null ? null : activeEditor.getCaretModel().getVisualPosition();
  int caretLine = activeEditor == null ? -1 : activeEditor.getCaretModel().getLogicalPosition().line;
  int caretOffset = activeEditor == null ? -1 : activeEditor.getCaretModel().getOffset();

  final Project project = activeEditor == null ? null : activeEditor.getProject();
  boolean markAsNeedsStrippingLater = ((DocumentImpl)document).stripTrailingSpaces(project, inChangedLinesOnly, isVirtualSpaceEnabled,
                                                                                   caretLine, caretOffset);

  if (!ShutDownTracker.isShutdownHookRunning() && activeEditor != null) {
    activeEditor.getCaretModel().moveToVisualPosition(visualCaret);
  }
  return !markAsNeedsStrippingLater;
}
项目:tools-idea    文件:PersistentFSImpl.java   
public PersistentFSImpl(@NotNull final MessageBus bus) {
  myEventsBus = bus;
  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      performShutdown();
    }
  });
}
项目:tools-idea    文件:Maven3ServerIndexerImpl.java   
public Maven3ServerIndexerImpl() throws RemoteException {
  myEmbedder = new Maven3ServerEmbedderImpl(new MavenServerSettings());

  myIndexer = myEmbedder.getComponent(NexusIndexer.class);
  myUpdater = myEmbedder.getComponent(IndexUpdater.class);
  myArtifactContextProducer = myEmbedder.getComponent(ArtifactContextProducer.class);

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      release();
    }
  });
}
项目:tools-idea    文件:Maven2ServerIndexerImpl.java   
public Maven2ServerIndexerImpl() throws RemoteException {
  myEmbedder = Maven2ServerEmbedderImpl.create(new MavenServerSettings());

  myIndexer = myEmbedder.getComponent(NexusIndexer.class);
  myUpdater = myEmbedder.getComponent(IndexUpdater.class);
  myArtifactContextProducer = myEmbedder.getComponent(ArtifactContextProducer.class);

  ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
    @Override
    public void run() {
      release();
    }
  });
}
项目:consulo    文件:LocalHistoryImpl.java   
@Override
public void initComponent() {
  if (!ApplicationManager.getApplication().isUnitTestMode() && ApplicationManager.getApplication().isHeadlessEnvironment()) return;

  myShutdownTask = () -> doDispose();
  ShutDownTracker.getInstance().registerShutdownTask(myShutdownTask);

  initHistory();
  isInitialized.set(true);
}
项目:consulo    文件:LocalHistoryImpl.java   
private void doDispose() {
  if (!isInitialized.getAndSet(false)) return;

  long period = Registry.intValue("localHistory.daysToKeep") * 1000L * 60L * 60L * 24L;

  myConnection.disconnect();
  myConnection = null;

  LocalHistoryLog.LOG.debug("Purging local history...");
  myChangeList.purgeObsolete(period);
  myChangeList.close();
  LocalHistoryLog.LOG.debug("Local history storage successfully closed.");

  ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask);
}
项目:consulo    文件:NativeFileWatcherImpl.java   
private void startupProcess(boolean restart) throws IOException {
  if (myIsShuttingDown) {
    return;
  }
  if (ShutDownTracker.isShutdownHookRunning()) {
    myIsShuttingDown = true;
    return;
  }

  if (myStartAttemptCount++ > MAX_PROCESS_LAUNCH_ATTEMPT_COUNT) {
    notifyOnFailure(ApplicationBundle.message("watcher.failed.to.start"), null);
    return;
  }

  if (restart) {
    shutdownProcess();
  }

  LOG.info("Starting file watcher: " + myExecutable);
  ProcessBuilder processBuilder = new ProcessBuilder(myExecutable.getAbsolutePath());
  Process process = processBuilder.start();
  myProcessHandler = new MyProcessHandler(process, myExecutable.getName());
  myProcessHandler.startNotify();

  if (restart) {
    List<String> recursive = myRecursiveWatchRoots;
    List<String> flat = myFlatWatchRoots;
    if (recursive.size() + flat.size() > 0) {
      setWatchRoots(recursive, flat, true);
    }
  }
}
项目:consulo    文件:StartupUtil.java   
@Nonnull
private synchronized static ActivationResult lockSystemFolders(String[] args) {
  if (ourSocketLock != null) {
    throw new AssertionError();
  }

  ourSocketLock = new SocketLock(PathManager.getConfigPath(), PathManager.getSystemPath());

  SocketLock.ActivateStatus status;
  try {
    status = ourSocketLock.lock(args);
  }
  catch (Exception e) {
    Main.showMessage("Cannot Lock System Folders", e);
    return ActivationResult.FAILED;
  }

  if (status == SocketLock.ActivateStatus.NO_INSTANCE) {
    ShutDownTracker.getInstance().registerShutdownTask(() -> {
      //noinspection SynchronizeOnThis
      synchronized (StartupUtil.class) {
        ourSocketLock.dispose();
        ourSocketLock = null;
      }
    });
    return ActivationResult.STARTED;
  }
  else if (status == SocketLock.ActivateStatus.ACTIVATED) {
    //noinspection UseOfSystemOutOrSystemErr
    System.out.println("Already running");
    return ActivationResult.ACTIVATED;
  }
  else if (Main.isHeadless() || status == SocketLock.ActivateStatus.CANNOT_ACTIVATE) {
    String message = "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time.";
    Main.showMessage("Too Many Instances", message, true);
  }

  return ActivationResult.FAILED;
}
项目:tools-idea    文件:BuiltInServerManagerImpl.java   
private Future<?> startServerInPooledThread() {
  Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode() && !enabledInUnitTestMode) {
    return null;
  }

  if (!started.compareAndSet(false, true)) {
    return null;
  }

  return application.executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      int defaultPort = getDefaultPort();
      int workerCount = 1;
      // if user set special port number for some service (eg built-in web server), we should slightly increase worker count
      if (Runtime.getRuntime().availableProcessors() > 1) {
        for (CustomPortServerManager customPortServerManager : CustomPortServerManager.EP_NAME.getExtensions()) {
          if (customPortServerManager.getPort() != defaultPort) {
            workerCount = 2;
            break;
          }
        }
      }

      try {
        server = new BuiltInServer(workerCount);
      }
      catch (ChannelException e) {
        LOG.info(e);
        String groupDisplayId = "Built-in Server";
        Notifications.Bus.register(groupDisplayId, NotificationDisplayType.STICKY_BALLOON);
        new Notification(groupDisplayId, "Internal HTTP server disabled",
                         "Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operate with errors. " +
                         "Please check your firewall settings and restart " + ApplicationNamesInfo.getInstance().getFullProductName(),
                         NotificationType.ERROR).notify(null);
        return;
      }

      Disposer.register(ApplicationManager.getApplication(), server);
      ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
        @Override
        public void run() {
          if (!Disposer.isDisposed(server)) {
            // something went wrong
            Disposer.dispose(server);
          }
        }
      });

      detectedPortNumber = server.start(defaultPort, PORTS_COUNT, true);
      if (detectedPortNumber == -1) {
        LOG.info("built-in server cannot be started, cannot bind to port");
      }
      else {
        LOG.info("built-in server started, port " + detectedPortNumber);
      }
    }
  });
}
项目:consulo    文件:DumbServiceImpl.java   
private void runBackgroundProcess(@Nonnull final ProgressIndicator visibleIndicator) {
  if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS)) return;

  ProgressSuspender suspender = ProgressSuspender.markSuspendable(visibleIndicator, "Indexing paused");
  myCurrentSuspender = suspender;
  suspendIfRequested(suspender);

  final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
  final Thread self = Thread.currentThread();
  try {
    shutdownTracker.registerStopperThread(self);

    if (visibleIndicator instanceof ProgressIndicatorEx) {
      ((ProgressIndicatorEx)visibleIndicator).addStateDelegate(new AppIconProgress());
    }

    DumbModeTask task = null;
    while (true) {
      Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, visibleIndicator);
      if (pair == null) break;

      task = pair.first;
      ProgressIndicatorEx taskIndicator = pair.second;
      if (visibleIndicator instanceof ProgressIndicatorEx) {
        taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() {
          @Override
          protected void delegateProgressChange(@Nonnull IndicatorAction action) {
            super.delegateProgressChange(action);
            action.execute((ProgressIndicatorEx)visibleIndicator);
          }
        });
      }
      try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks")) {
        runSingleTask(task, taskIndicator);
      }
    }
  }
  catch (Throwable unexpected) {
    LOG.error(unexpected);
  }
  finally {
    shutdownTracker.unregisterStopperThread(self);
    myCurrentSuspender = null;
  }
}
项目:consulo    文件:PersistentFSImpl.java   
public PersistentFSImpl(@Nonnull MessageBus bus) {
  myEventBus = bus;
  ShutDownTracker.getInstance().registerShutdownTask(() -> performShutdown());
}