Exemplo n.º 1
0
  public T receive() {
    lock.lock();
    try {
      while (true) {
        DelayedMessage message = queue.peek();
        if (message == null && stopping) {
          return null;
        }
        if (message == null) {
          condition.await();
          continue;
        }

        long now = timeProvider.getCurrentTime();
        if (message.dispatchTime > now) {
          condition.awaitUntil(new Date(message.dispatchTime));
        } else {
          queue.poll();
          if (queue.isEmpty()) {
            condition.signalAll();
          }
          return message.message;
        }
      }
    } catch (InterruptedException e) {
      throw UncheckedException.asUncheckedException(e);
    } finally {
      lock.unlock();
    }
  }
  public void execute(WorkerContext workerContext) {
    LoggingManagerInternal loggingManager = createLoggingManager();
    loggingManager.setLevel(logLevel).start();

    FilteringClassLoader filteredWorkerClassLoader =
        new FilteringClassLoader(getClass().getClassLoader());
    filteredWorkerClassLoader.allowPackage("org.slf4j");
    filteredWorkerClassLoader.allowClass(Action.class);
    filteredWorkerClassLoader.allowClass(WorkerContext.class);

    ClassLoader applicationClassLoader = workerContext.getApplicationClassLoader();
    FilteringClassLoader filteredApplication = new FilteringClassLoader(applicationClassLoader);
    ObservableUrlClassLoader implementationClassLoader =
        createImplementationClassLoader(filteredWorkerClassLoader, filteredApplication);

    // Configure classpaths
    for (String sharedPackage : sharedPackages) {
      filteredApplication.allowPackage(sharedPackage);
    }
    implementationClassLoader.addURLs(implementationClassPath);

    // Deserialize the worker action
    Action<WorkerContext> action;
    try {
      ObjectInputStream instr =
          new ClassLoaderObjectInputStream(
              new ByteArrayInputStream(serializedWorkerAction), implementationClassLoader);
      action = (Action<WorkerContext>) instr.readObject();
    } catch (Exception e) {
      throw UncheckedException.asUncheckedException(e);
    }
    action.execute(workerContext);
  }
Exemplo n.º 3
0
 private Distribution getDownloadedDistribution(String gradleVersion) {
   URI distUri;
   try {
     distUri =
         new URI(
             new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion)));
   } catch (URISyntaxException e) {
     throw UncheckedException.asUncheckedException(e);
   }
   return getDistribution(distUri);
 }
Exemplo n.º 4
0
 public void stop() {
   lock.lock();
   try {
     while (queue != null && !queue.isEmpty()) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.asUncheckedException(e);
       }
     }
   } finally {
     lock.unlock();
   }
 }
Exemplo n.º 5
0
 /** Blocks until all queued messages are delivered. */
 public void stop() {
   lock.lock();
   try {
     stopping = true;
     condition.signalAll();
     while (!queue.isEmpty()) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.asUncheckedException(e);
       }
     }
   } finally {
     lock.unlock();
   }
 }
  public Connection<Object> connect() {
    Connection<Object> connection = findConnection(daemonRegistry.getIdle());
    if (connection != null) {
      return connection;
    }

    LOGGER.info("Starting Gradle daemon");
    startDaemon();
    Date expiry = new Date(System.currentTimeMillis() + 30000L);
    do {
      connection = findConnection(daemonRegistry.getIdle());
      if (connection != null) {
        return connection;
      }
      try {
        Thread.sleep(200L);
      } catch (InterruptedException e) {
        throw UncheckedException.asUncheckedException(e);
      }
    } while (System.currentTimeMillis() < expiry.getTime());

    throw new GradleException("Timeout waiting to connect to Gradle daemon.");
  }