Package org.platformlayer.ops.cas

Source Code of org.platformlayer.ops.cas.OpsCasObjectBase

package org.platformlayer.ops.cas;

import java.io.File;

import org.slf4j.*;
import org.platformlayer.cas.CasLocation;
import org.platformlayer.cas.CasStore;
import org.platformlayer.cas.CasStoreObjectBase;
import org.platformlayer.cas.CasTarget;
import org.platformlayer.ops.OpsException;
import org.platformlayer.ops.OpsTarget;
import org.platformlayer.ops.cas.filesystem.FilesystemCasObject;
import org.platformlayer.ops.cas.filesystem.FilesystemCasStore;

import com.fathomdb.hash.Md5Hash;

public abstract class OpsCasObjectBase extends CasStoreObjectBase {
  static final Logger log = LoggerFactory.getLogger(OpsCasObjectBase.class);

  public OpsCasObjectBase(CasStore store, Md5Hash hash) {
    super(store, hash);
  }

  @Override
  public void copyTo(CasTarget destTarget, File destPath, CasStore stagingStore) throws OpsException {
    CasLocation srcLocation = getLocation();
    CasLocation destLocation = destTarget.getLocation();

    int distance = srcLocation.estimateDistance(destLocation);
    log.info("Estimated distance from " + srcLocation + " to " + destLocation + " => " + distance);

    if (distance == 0) {
      log.info("Distance was zero; copying directly");
      this.copyTo0(OpsCasTarget.getTarget(destTarget), destPath);
      return;
    }

    if (stagingStore != null) {
      log.info("Staging object " + this + " to " + stagingStore);

      FilesystemCasObject staged = ((FilesystemCasStore) stagingStore).copyToStaging(this);

      staged.copyTo(destTarget, destPath, null);
    } else {
      log.info("Copying object from " + this + " to " + destTarget);

      this.copyTo0(OpsCasTarget.getTarget(destTarget), destPath);
    }
  }

  public abstract void copyTo0(OpsTarget destTarget, File destPath) throws OpsException;
}
TOP

Related Classes of org.platformlayer.ops.cas.OpsCasObjectBase

TOP
Copyright © 2018 www.massapi.com. 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.