@Override
 public void initialize() throws Exception {
   String pathName = config.get().directory().get();
   if (pathName == null) {
     if (fileConfiguration != null) {
       pathName =
           new File(fileConfiguration.dataDirectory(), config.get().identity().get())
               .getAbsolutePath();
     } else {
       pathName = System.getProperty("user.dir") + "/qi4j/filestore/";
     }
   }
   File rootDirectory = new File(pathName).getAbsoluteFile();
   dataDirectory = new File(rootDirectory, "data");
   if (!dataDirectory.exists()) {
     if (!dataDirectory.mkdirs()) {
       throw new IOException("Unable to create directory " + dataDirectory);
     }
   }
   File slicesFile = new File(dataDirectory, "slices");
   if (slicesFile.exists()) {
     slices = readIntegerInFile(slicesFile);
   }
   if (slices < 1) {
     Integer slicesConf = config.get().slices().get();
     if (slicesConf == null) {
       slices = 10;
     } else {
       slices = slicesConf;
     }
     writeIntegerToFile(slicesFile, slices);
   }
 }
Example #2
0
  // START SNIPPET: refresh
  public void doSomething() {
    // Refresh Configuration before reading it.
    config.refresh();

    TravelPlanConfiguration tpConf = config.get();
    // ...
  }
  @Override
  public void activateService() throws Exception {
    configuration.refresh();
    RiakHttpEntityStoreConfiguration config = configuration.get();

    int maxConnections =
        config.maxConnections().get() == null
            ? DEFAULT_MAX_CONNECTIONS
            : config.maxConnections().get();
    int timeoutMillis = config.timeout().get();
    List<String> urls = config.urls().get();
    if (urls.isEmpty()) {
      urls.add(DEFAULT_URL);
    }
    bucketKey = config.bucket().get() == null ? DEFAULT_BUCKET_KEY : config.bucket().get();

    HTTPClusterConfig httpClusterConfig = new HTTPClusterConfig(maxConnections);
    for (String url : urls) {
      HTTPClientConfig clientConfig =
          new HTTPClientConfig.Builder().withTimeout(timeoutMillis).withUrl(url).build();
      httpClusterConfig.addClient(clientConfig);
    }
    riakClient = RiakFactory.newClient(httpClusterConfig);

    if (!riakClient.listBuckets().contains(bucketKey)) {
      riakClient.createBucket(bucketKey).execute();
    }
  }
Example #4
0
  @Override
  public void activateService() throws Exception {
    // Handle configuration defaults
    SchedulerConfiguration configuration = config.get();
    Integer workersCount = configuration.workersCount().get();
    Integer workQueueSize = configuration.workQueueSize().get();

    if (workersCount == null) {
      workersCount = DEFAULT_WORKERS_COUNT;
      LOGGER.debug(
          "Workers count absent from configuration, falled back to default: {} workers",
          DEFAULT_WORKERS_COUNT);
    }
    if (workQueueSize == null) {
      workQueueSize = DEFAULT_WORKQUEUE_SIZE;
      LOGGER.debug(
          "WorkQueue size absent from configuration, falled back to default: {}",
          DEFAULT_WORKQUEUE_SIZE);
    }

    int corePoolSize = 2;
    if (workersCount > 4) {
      corePoolSize = workersCount / 4;
    }
    // Throws IllegalArgument if corePoolSize or keepAliveTime less than zero, or if workersCount
    // less than or equal to zero, or if corePoolSize greater than workersCount.
    taskExecutor =
        new ThreadPoolExecutor(
            corePoolSize,
            workersCount,
            0,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(workQueueSize),
            threadFactory,
            rejectionHandler);
    taskExecutor.prestartAllCoreThreads();
    managementExecutor = new ScheduledThreadPoolExecutor(2, threadFactory, rejectionHandler);
    loadSchedules();
    LOGGER.debug("Activated");
  }
Example #5
0
 private void foo() {
   TravelPlanConfiguration tpConf = config.get();
   String hostName = tpConf.hostName().get();
   // ...
 }