Package org.openstreetmap.osmosis.replication.common

Examples of org.openstreetmap.osmosis.replication.common.ReplicationState


    server = new ReplicationSequenceServer(0);
    server.setChangeSink(new MockReplicationDestination());

    try {
      for (int i = 0; i < 10; i++) {
        ReplicationState state = new ReplicationState();
        Map<String, Object> metaData = new HashMap<String, Object>();
        metaData.put(ReplicationState.META_DATA_KEY, state);
        server.initialize(metaData);
        Thread.sleep(10);
        server.complete();
View Full Code Here


  }


  private ReplicationState getReplicationState(long sequenceNumber) {
    PropertiesPersister persister = new PropertiesPersister(getStateFile(sequenceNumber));
    ReplicationState state = new ReplicationState();
    state.load(persister.loadMap());

    return state;
  }
View Full Code Here

 
 
  private ReplicationState download(ReplicationDownloaderConfiguration configuration, ReplicationState serverState,
      ReplicationState initialLocalState) {
    URL baseUrl;
    ReplicationState localState;
    Date maximumDownloadTimestamp;
   
    localState = initialLocalState;
   
    // Determine the location of download files.
    baseUrl = configuration.getBaseUrl();
   
    // Determine the maximum timestamp that can be downloaded.
    maximumDownloadTimestamp =
      calculateMaximumTimestamp(configuration, serverState.getTimestamp(), localState.getTimestamp());
    LOG.fine("The maximum timestamp to be downloaded is " + maximumDownloadTimestamp + ".");
   
    // Download all files and send their contents to the sink.
    while (localState.getSequenceNumber() < serverState.getSequenceNumber()) {
      File replicationFile;
      long sequenceNumber;
      ReplicationState fileReplicationState;
     
      // Check to see if our local state has already reached the maximum
      // allowable timestamp. This will typically occur if a job is run
      // again before new data becomes available, or if an implementation
      // of this class (eg. ReplicationFileMerger) is waiting for a full
      // time period of data to become available before processing.
      if (localState.getTimestamp().compareTo(maximumDownloadTimestamp) >= 0) {
        break;
      }
     
      // Calculate the next sequence number.
      sequenceNumber = localState.getSequenceNumber() + 1;
      LOG.finer("Processing replication sequence " + sequenceNumber + ".");
     
      // Get the state associated with the next file.
      fileReplicationState = serverStateReader.getServerState(baseUrl, sequenceNumber);
     
      // Ensure that the next state is within the allowable timestamp
      // range. We must stop if the next data takes us beyond the maximum
      // timestamp. This will either occur if a maximum download time
      // duration limit has been imposed, or if a time-aligned boundary
      // has been reached.
      if (fileReplicationState.getTimestamp().compareTo(maximumDownloadTimestamp) > 0) {
        // We will always allow at least one replication interval
        // through to deal with the case where a single interval exceeds
        // the maximum duration. This can happen if the source data has
        // a long time gap between two intervals due to system downtime.
        if (localState.getSequenceNumber() != initialLocalState.getSequenceNumber()) {
View Full Code Here

 
 
  private void runImpl() {
    try {
      ReplicationDownloaderConfiguration configuration;
      ReplicationState serverState;
      ReplicationState localState;
      PropertiesPersister localStatePersistor;
     
      // Instantiate utility objects.
      configuration = new ReplicationDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
     
      // Obtain the server state.
      LOG.fine("Reading current server state.");
      serverState = serverStateReader.getServerState(configuration.getBaseUrl());
     
      // Build the local state persister which is used for both loading and storing local state.
      localStatePersistor = new PropertiesPersister(new File(workingDirectory, LOCAL_STATE_FILE));
     
      // Begin processing.
      processInitialize(Collections.<String, Object>emptyMap());
     
      // If local state isn't available we need to copy server state to be the initial local state
      // then exit.
      if (localStatePersistor.exists()) {
        localState = new ReplicationState(localStatePersistor.loadMap());
       
        // Download and process the replication files.
        localState = download(configuration, serverState, localState);
       
      } else {
        localState = serverState;
       
        processInitializeState(localState);
      }
     
      // Commit downstream changes.
      processComplete();
     
      // Persist the local state.
      localStatePersistor.store(localState.store());
     
    } finally {
      processRelease();
    }
  }
View Full Code Here

    changeSink.complete();
  }


  private void invokeSinkInit() {
    replicationState = new ReplicationState();
    Map<String, Object> metaData = new HashMap<String, Object>(1);
    metaData.put(ReplicationState.META_DATA_KEY, replicationState);
    changeSink.initialize(metaData);
    sinkInitInvoked = true;
  }
View Full Code Here

  }


  private ReplicationState loadState(File stateFile) {
    PropertiesPersister persister = new PropertiesPersister(stateFile);
    ReplicationState state = new ReplicationState();
    state.load(persister.loadMap());

    return state;
  }
View Full Code Here

            invokeSinkInit();
          }

          // The first chunk contains the replication state stored in
          // properties format.
          ReplicationState serverReplicationState = loadState(chunkFile);
          if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Received replication state " + serverReplicationState.getSequenceNumber());
          }

          // Validate that the server has sent us the expected state.
          if (serverReplicationState.getSequenceNumber() != replicationState.getSequenceNumber()) {
            throw new OsmosisRuntimeException("Received sequence number "
                + serverReplicationState.getSequenceNumber() + " from server, expected "
                + replicationState.getSequenceNumber());
          }

          // Update the local state with server values.
          replicationState.setTimestamp(serverReplicationState.getTimestamp());
          replicationStateReceived = true;
         
          // If this is replication 0, then we need to finish
          // processing now because the first sequence doesn't have
          // any data.
View Full Code Here

    if (alignedDate.compareTo(initialDate) < 0) {
      alignedDate = new Date(alignedDate.getTime() + intervalLength);
    }

    // Create an initial replication state object.
    currentDataState = new ReplicationState(alignedDate, 0);

    // Write out the initial "0" state file.
    replicationStore.saveState(currentDataState);
  }
View Full Code Here

  /**
   * Calculate the replication lag and print it to stdout
   */
  private void getLag() {
    ReplicationDownloaderConfiguration configuration;
    ReplicationState serverState;
    ReplicationState localState;
    PropertiesPersister localStatePersistor;
   
    // Instantiate utility objects.
    configuration = new ReplicationDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
   
    // Obtain the server state.
    LOG.fine("Reading current server state.");
    serverState = serverStateReader.getServerState(configuration.getBaseUrl());
   
    // Build the local state persister which is used for both loading and storing local state.
    localStatePersistor = new PropertiesPersister(new File(workingDirectory, LOCAL_STATE_FILE));
   
    // If local state isn't available we need to fail because no lag can be calculated.
    if (!localStatePersistor.exists()) {
      throw new OsmosisRuntimeException("Can't read local state.");
    }
   
    // fetch the local state from the file
    localState = new ReplicationState(localStatePersistor.loadMap());
   
    // extract the time of the local and the remote state files
    long local = localState.getTimestamp().getTime();
    long server = serverState.getTimestamp().getTime();
   
    // we assume the server being before the local state while calculating the difference
    long lag = (server - local) / 1000;
   
View Full Code Here

  /**
   * Sends a replication sequence containing dummy data to the destination.
   */
  public void sendSequence() {
    // Initialise the replication stream.
    ReplicationState state = new ReplicationState();
    Map<String, Object> metaData = new HashMap<String, Object>(1);
    metaData.put(ReplicationState.META_DATA_KEY, state);
    changeSink.initialize(metaData);

    // Send the change data unless this is sequence 0 where no data is
    // allowed. We'll only send a single record for simplicity.
    if (state.getSequenceNumber() > 0) {
      // We'll do a create action on the first replication pass, and modify subsequently.
      ChangeAction action;
      if (state.getSequenceNumber() == 1) {
        action = ChangeAction.Create;
      } else {
        action = ChangeAction.Modify;
      }
     
      // Create a change record which data derived from the
      // replication sequence number itself.
      ChangeContainer change = new ChangeContainer(new NodeContainer(new Node(new CommonEntityData(10,
          (int) state.getSequenceNumber(), new Date(state.getSequenceNumber() * 1000), new OsmUser(11,
              "test"), state.getSequenceNumber() * 2), state.getSequenceNumber() * 3,
          state.getSequenceNumber() * 4)), action);
     
      // Send the record downstream.
      changeSink.process(change);
    }
   
    state.setTimestamp(new Date(state.getSequenceNumber() * 1000));
   
    changeSink.complete();
  }
 
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.replication.common.ReplicationState

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.