@Override public double deleteFile(File file) { double result = 0.0; // check if the file is valid or not if (!isFileValid(file, "deleteFile()")) { return result; } double seekTime = getSeekTime(file.getSize()); double transferTime = getTransferTime(file.getSize()); // check if the file is in the storage if (contains(file)) { fileList.remove(file); // remove the file HD nameList.remove(file.getName()); // remove the name from name list currentSize -= file.getSize(); // decrement the current HD space result = seekTime + transferTime; // total time file.setTransactionTime(result); } return result; }
/** * Clone the current file and make the new file as a <b>master</b> copy as well. * * @return a clone of the current file (as a master copy) or <tt>null</tt> if an error occurs */ public File makeMasterCopy() { File file = makeCopy(); if (file != null) { file.setMasterCopy(true); } return file; }
@Override public File deleteFile(String fileName) { if (fileName == null || fileName.length() == 0) { return null; } Iterator<File> it = fileList.iterator(); File file = null; while (it.hasNext()) { file = it.next(); String name = file.getName(); // if a file is found then delete if (fileName.equals(name)) { double result = deleteFile(file); file.setTransactionTime(result); break; } else { file = null; } } return file; }
@Override public boolean renameFile(File file, String newName) { // check whether the new filename is conflicting with existing ones // or not boolean result = false; if (contains(newName)) { return result; } // replace the file name in the file (physical) list File obj = getFile(file.getName()); if (obj == null) { return result; } else { obj.setName(newName); } // replace the file name in the name list Iterator<String> it = nameList.iterator(); while (it.hasNext()) { String name = it.next(); if (name.equals(file.getName())) { file.setTransactionTime(0); nameList.remove(name); nameList.add(newName); result = true; break; } } return result; }
/** * Adds a file into the resource's storage before the experiment starts. If the file is a master * file, then it will be registered to the RC when the experiment begins. * * @param file a DataCloud file * @return a tag number denoting whether this operation is a success or not */ public int addFile(File file) { if (file == null) { return DataCloudTags.FILE_ADD_ERROR_EMPTY; } if (contains(file.getName())) { return DataCloudTags.FILE_ADD_ERROR_EXIST_READ_ONLY; } // check storage space first if (getStorageList().size() <= 0) { return DataCloudTags.FILE_ADD_ERROR_STORAGE_FULL; } Storage tempStorage = null; int msg = DataCloudTags.FILE_ADD_ERROR_STORAGE_FULL; for (int i = 0; i < getStorageList().size(); i++) { tempStorage = getStorageList().get(i); if (tempStorage.getAvailableSpace() >= file.getSize()) { tempStorage.addFile(file); msg = DataCloudTags.FILE_ADD_SUCCESSFUL; break; } } return msg; }
file.setMasterCopy(true); // set the file into a master copy int sentFrom = ((Integer) pack[1]).intValue(); // get sender ID data[0] = file.getName();
@Override public boolean hasPotentialAvailableSpace(int fileSize) { if (fileSize <= 0) { return false; } // check if enough space left if (getAvailableSpace() > fileSize) { return true; } Iterator<File> it = fileList.iterator(); File file = null; int deletedFileSize = 0; // if not enough space, then if want to clear/delete some files // then check whether it still have space or not boolean result = false; while (it.hasNext()) { file = it.next(); if (!file.isReadOnly()) { deletedFileSize += file.getSize(); } if (deletedFileSize > fileSize) { result = true; break; } } return result; }
/** * Makes a copy of this file. * * @return a clone of the current file (as a replica) or <tt>null</tt> if an error occurs */ private File makeCopy() { File file = null; try { file = new File(name, attribute.getFileSize()); FileAttribute fileAttr = file.getFileAttribute(); attribute.copyValue(fileAttr); fileAttr.setMasterCopy(false); // set this file to replica } catch (Exception e) { file = null; } return file; }
/** * Checks whether the datacenter has the given file. * * @param file a file to be searched * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ protected boolean contains(File file) { if (file == null) { return false; } return contains(file.getName()); }
/** * Clone the current file and set the cloned one as a <b>replica</b>. * * @return a clone of the current file (as a replica) or <tt>null</tt> if an error occurs */ public File makeReplica() { return makeCopy(); }
/** * Copy constructor that creates a clone from a source file and set the given file * as a <b>replica</b>. * * @param file the source file to create a copy and that will be set as a replica * @throws ParameterException This happens when the source file is <tt>null</tt> */ public File(File file) throws ParameterException { if (file == null) { throw new ParameterException("File(): Error - file is null."); } // copy the attributes into the file FileAttribute fileAttr = file.getFileAttribute(); attribute.copyValue(fileAttr); fileAttr.setMasterCopy(false); // set this file to replica }
/** * Process data add. * * @param ev the ev * @param ack the ack */ protected void processDataAdd(SimEvent ev, boolean ack) { if (ev == null) { return; } Object[] pack = (Object[]) ev.getData(); if (pack == null) { return; } File file = (File) pack[0]; // get the file file.setMasterCopy(true); // set the file into a master copy int sentFrom = ((Integer) pack[1]).intValue(); // get sender ID /****** * // DEBUG Log.printLine(super.get_name() + ".addMasterFile(): " + file.getName() + * " from " + CloudSim.getEntityName(sentFrom)); *******/ Object[] data = new Object[3]; data[0] = file.getName(); int msg = addFile(file); // add the file if (ack) { data[1] = Integer.valueOf(-1); // no sender id data[2] = Integer.valueOf(msg); // the result of adding a master file sendNow(sentFrom, DataCloudTags.FILE_ADD_MASTER_RESULT, data); } }
@Override public double addFile(File file) { double time = super.addFile(file); time += networkLatency; time += file.getSize() * bandwidth; return time; }
/** * Checks whether the resource has the given file. * * @param file a file to be searched * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ protected boolean contains(File file) { if (file == null) { return false; } return contains(file.getName()); }
if (file.getSize() + currentSize > capacity) { Log.printConcatLine(name, ".addFile(): Warning - not enough space to store ", file.getName()); return result; if (!contains(file.getName())) { double seekTime = getSeekTime(file.getSize()); double transferTime = getTransferTime(file.getSize()); nameList.add(file.getName()); // add the name to the name list currentSize += file.getSize(); // increment the current HD size file.setTransactionTime(result); return result;
@Override public double deleteFile(File file) { double time = super.deleteFile(file); time += networkLatency; time += file.getSize() * bandwidth; return time; }
@Override public boolean contains(File file) { boolean result = false; if (!isFileValid(file, "contains()")) { return result; } result = contains(file.getName()); return result; }
size += tempFile.getSize(); if (tempFile.getName().equals(fileName)) { found = true; obj = tempFile; obj = fileList.get(index); double seekTime = getSeekTime(size); double transferTime = getTransferTime(obj.getSize()); obj.setTransactionTime(seekTime + transferTime);