/** * 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()); }
/** * 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()); }
@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 contains(File file) { boolean result = false; if (!isFileValid(file, "contains()")) { return result; } result = contains(file.getName()); return result; }
@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; }
/** * Check if the file is valid or not. This method checks whether the given file or the file name * of the file is valid. The method name parameter is used for debugging purposes, to output in * which method an error has occurred. * * @param file the file to be checked for validity * @param methodName the name of the method in which we check for validity of the file * @return <tt>true</tt> if the file is valid, <tt>false</tt> otherwise */ private boolean isFileValid(File file, String methodName) { if (file == null) { Log.printConcatLine(name, ".", methodName, ": Warning - the given file is null."); return false; } String fileName = file.getName(); if (fileName == null || fileName.length() == 0) { Log.printConcatLine(name, "." + methodName, ": Warning - invalid file name."); return false; } return true; }
/** * 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); } }
data[0] = file.getName();
tempFile = it.next(); size += tempFile.getSize(); if (tempFile.getName().equals(fileName)) { found = true; obj = tempFile;
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
/** * 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; }
if (contains(file.getName())) { return DataCloudTags.FILE_ADD_ERROR_EXIST_READ_ONLY;
@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; }