Пример #1
0
  protected static int getEFlagMask(Class<?> instanceClass, String flagName) {
    Field field = ReflectUtil.getField(instanceClass, flagName);
    if (!field.isAccessible()) {
      field.setAccessible(true);
    }

    try {
      return (Integer) field.get(null);
    } catch (IllegalAccessException ex) {
      throw WrappedException.wrap(ex);
    }
  }
Пример #2
0
  public synchronized Properties getHomeProperties() {
    if (homeProperties == null) {
      homeProperties = new Properties();
      String home = System.getProperty("user.home");
      if (home != null) {
        File file = new File(home, ".cdo_config_test.properties");
        if (file.exists()) {
          FileInputStream stream = IOUtil.openInputStream(file);

          try {
            homeProperties.load(stream);
          } catch (IOException ex) {
            throw WrappedException.wrap(ex);
          } finally {
            IOUtil.close(stream);
          }
        }
      }
    }

    return homeProperties;
  }
Пример #3
0
  public RESULT get(long timeout) {
    try {
      final long stop = System.currentTimeMillis() + timeout;
      synchronized (consumerLock) {
        while (result == null) {
          try {
            final long remaining = stop - System.currentTimeMillis();
            if (remaining <= 0) {
              return null;
            }

            consumerLock.wait(Math.min(remaining, 100L));
          } catch (InterruptedException ex) {
            throw WrappedException.wrap(ex);
          }
        }

        return result;
      }
    } finally {
      producerLatch.countDown();
    }
  }
  private void populateRepository() {
    msg("Populate the repository the classic way");
    msg("Create resource");
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath(resourcePath));

    msg("Populate resource");
    Supplier supplier0 = getModel1Factory().createSupplier();
    supplier0.setName(supplierName);
    resource.getContents().add(supplier0);
    Company company0 = getModel1Factory().createCompany();
    resource.getContents().add(company0);

    try {
      msg("Commit");
      transaction.commit();
    } catch (CommitException ex) {
      throw WrappedException.wrap(ex);
    }

    session.close();
  }
Пример #5
0
  public final <CONTEXT> void run(
      ProgressDistributable<CONTEXT>[] distributables, CONTEXT context, OMMonitor monitor)
      throws RuntimeException, WrappedException {
    double[] distributionCopy;
    synchronized (this) {
      if (distribution == null) {
        distribution = new double[distributables.length];
        Arrays.fill(distribution, OMMonitor.ONE);
      } else {
        CheckUtil.checkArg(
            distribution.length == distributables.length, "distributables.length"); // $NON-NLS-1$
      }

      distributionCopy = new double[distribution.length];
      System.arraycopy(distribution, 0, distributionCopy, 0, distribution.length);
    }

    double total = OMMonitor.ZERO;
    for (int i = 0; i < distributionCopy.length; i++) {
      total += distributionCopy[i];
    }

    if (TRACER.isEnabled()) {
      StringBuilder builder = new StringBuilder("Distribution: "); // $NON-NLS-1$
      for (int i = 0; i < distributionCopy.length; i++) {
        builder.append(distributionCopy[i] * OMMonitor.HUNDRED / total);
        builder.append("%, "); // $NON-NLS-1$
      }

      builder.append("("); // $NON-NLS-1$
      builder.append(this);
      builder.append(")"); // $NON-NLS-1$
      TRACER.trace(builder.toString());
    }

    monitor.begin(total);

    try {
      double[] times = new double[distributables.length];
      for (int i = 0; i < distributables.length; i++) {
        ProgressDistributable<CONTEXT> distributable = distributables[i];
        int count = distributable.getLoopCount(context);
        double work = distributable.getLoopWork(context);

        OMMonitor distributableMonitor = monitor.fork(distributionCopy[i]);
        distributableMonitor.begin(work * count);

        try {
          long start = System.currentTimeMillis();
          for (int loop = 0; loop < count; loop++) {
            try {
              distributable.runLoop(loop, context, distributableMonitor);
            } catch (Exception ex) {
              throw WrappedException.wrap(ex);
            }
          }

          times[i] = (double) (System.currentTimeMillis() - start) / count;
        } finally {
          distributableMonitor.done();
        }
      }

      synchronized (this) {
        distribute(distribution, times);
      }
    } finally {
      monitor.done();
    }
  }