Package org.openstreetmap.osmosis.core.pipeline.common

Examples of org.openstreetmap.osmosis.core.pipeline.common.TaskRunner


    // replication writer, and receive sequence number updates from the
    // sequence server.
    ReplicationDataServer dataServer = new ReplicationDataServer(sequenceServer.getPort(), workingDir1, 0);

    // Start the HTTP data server.
    TaskRunner serverRunner = new TaskRunner(dataServer, "data-server");
    serverRunner.start();

    /*
     * The server starts in another thread so we need to wait until it has
     * started. We will wait until the dynamically allocated port is
     * exported via the getPort method which occurs after server startup.
     */
    timerStart = System.currentTimeMillis();
    while (dataServer.getPort() == 0 && (System.currentTimeMillis() - timerStart < 10000)) {
      Thread.sleep(10);
    }
    Assert.assertFalse("Server port was not dynamically allocated.", sequenceServer.getPort() == 0);

    // Create a HTTP replication data client receiving data from the data
    // server.
    ReplicationDataClient dataClient = new ReplicationDataClient(new InetSocketAddress(dataServer.getPort()), "");

    // Create a replication data writer to receiving data from the HTTP data
    // source.
    File workingDir2 = dataUtils.newFolder();
    dataClient.setChangeSink(new ReplicationWriter(workingDir2));

    // Start the HTTP data server and HTTP data client.
    TaskRunner clientRunner = new TaskRunner(dataClient, "data-client");
    clientRunner.start();

    // Send the test replication intervals.
    for (int i = 0; i < sequenceCount; i++) {
      source.sendSequence();
    }

    // Wait for all the data to reach the destination.
    File finalStateFile = new File(workingDir2, new ReplicationSequenceFormatter(9, 3).getFormattedName(
        sequenceCount, ".state.txt"));
    timerStart = System.currentTimeMillis();
    while (!finalStateFile.exists() && (System.currentTimeMillis() - timerStart < 10000)) {
      Thread.sleep(100);
    }

    // Verify that all of the replication sequences made it to the
    // destination.
    Assert.assertTrue("The state file for sequence " + sequenceCount + " doesn't exist.", finalStateFile.exists());

    // Shut down the pipelines.
    clientRunner.interrupt();
    serverRunner.interrupt();
    clientRunner.join();
    serverRunner.join();
    source.release();
  }
View Full Code Here


     
      // Create task runners for each of the tasks to provide thread
      // management.
      taskRunners = new ArrayList<TaskRunner>(tasks.size());
      for (int i = 0; i < tasks.size(); i++) {
        taskRunners.add(new TaskRunner(tasks.get(i), "Thread-" + taskId + "-worker" + i));
      }
     
      // Launch all of the tasks.
      for (int i = 0; i < taskRunners.size(); i++) {
        TaskRunner taskRunner;
       
        taskRunner = taskRunners.get(i);
       
        LOG.fine("Launching changeset worker + " + i + " in a new thread.");
       
        taskRunner.start();
      }
     
      // Wait for all the tasks to complete.
      tasksSuccessful = true;
      for (int i = 0; i < taskRunners.size(); i++) {
        TaskRunner taskRunner;
       
        taskRunner = taskRunners.get(i);
       
        LOG.fine("Waiting for changeset worker " + i + " to complete.");
       
        try {
          taskRunner.join();
        } catch (InterruptedException e) {
          // We are already in an error condition so log and continue.
          LOG.log(Level.WARNING, "The wait for task completion was interrupted.", e);
        }
       
        if (!taskRunner.isSuccessful()) {
          LOG.log(Level.SEVERE, "Changeset worker " + i + " failed", taskRunner.getException());
         
          tasksSuccessful = false;
        }
      }
     
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.core.pipeline.common.TaskRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.