private void init() { initWorkingDirectory(); File partitionsFile = createFileIfNotExists(getWorkingDirFile(PARTITIONS_FILE_NAME)); loadPartitions(partitionsFile); Map<String, Map<String, FileRelationship>> relationships = readObject(createFileIfNotExists(getWorkingDirFile(RELATIONSHIPS_FILE_NAME))); if (relationships == null) { relationships = new ConcurrentHashMap<String, Map<String, FileRelationship>>(); } this.relationships = relationships; Map<String, FileAttribute> attributes = readObject(createFileIfNotExists(getWorkingDirFile(ATTRIBUTES_FILE_NAME))); if (attributes == null) { attributes = new ConcurrentHashMap<String, FileAttribute>(); } this.attributes = attributes; Map<String, FileAttributedType> attrubtedTypes = readObject(createFileIfNotExists(getWorkingDirFile(ATTRIBUTED_TYPES__FILE_NAME))); if (attrubtedTypes == null) { attrubtedTypes = new ConcurrentHashMap<String, FileAttributedType>(); } this.attributedTypes = attrubtedTypes; if (this.configuration.isAsyncWrite()) { FILE_STORE_LOGGER.fileAsyncWriteEnabled(this.configuration.getAsyncThreadPool()); this.executorService = Executors.newFixedThreadPool(this.configuration.getAsyncThreadPool()); } }
/** * <p> * Delete the specified {@link File} instance from the filesystem. If the instance is a directory it will be deleted * recursively, otherwise only the file will be deleted. * </p> * * @param file */ public static void delete(File file) { if (file.exists()) { if (file.isDirectory()) { String[] childs = file.list(); for (String childName : childs) { File child = new File(file.getPath() + File.separator + childName); delete(child); } file.delete(); } else { file.delete(); } } }
private void loadPartitions(File partitionsFile) { this.partitions = readObject(partitionsFile); if (this.partitions == null) { if (isDebugEnabled()) { FILE_STORE_LOGGER.debugf("No partitions to load from %s", partitionsFile.getPath()); } this.partitions = new ConcurrentHashMap<String, FilePartition>(); } else { if (isDebugEnabled()) { FILE_STORE_LOGGER.debugf("Loading [%s] Partition(s) from %s", this.partitions.size(), partitionsFile.getPath()); } Set<Entry<String, FilePartition>> entrySet = this.partitions.entrySet(); for (Entry<String, FilePartition> entry : entrySet) { initPartition(entry.getKey()); } } }
private void loadPartitions(File partitionsFile) { this.partitions = readObject(partitionsFile); if (this.partitions == null) { if (isDebugEnabled()) { FILE_STORE_LOGGER.debugf("No partitions to load from %s", partitionsFile.getPath()); } this.partitions = new ConcurrentHashMap<String, FilePartition>(); } else { if (isDebugEnabled()) { FILE_STORE_LOGGER.debugf("Loading [%s] Partition(s) from %s", this.partitions.size(), partitionsFile.getPath()); } Set<Entry<String, FilePartition>> entrySet = this.partitions.entrySet(); for (Entry<String, FilePartition> entry : entrySet) { initPartition(entry.getKey()); } } }
private void init() { initWorkingDirectory(); File partitionsFile = createFileIfNotExists(getWorkingDirFile(PARTITIONS_FILE_NAME)); loadPartitions(partitionsFile); Map<String, Map<String, FileRelationship>> relationships = readObject(createFileIfNotExists(getWorkingDirFile(RELATIONSHIPS_FILE_NAME))); if (relationships == null) { relationships = new ConcurrentHashMap<String, Map<String, FileRelationship>>(); } this.relationships = relationships; Map<String, FileAttribute> attributes = readObject(createFileIfNotExists(getWorkingDirFile(ATTRIBUTES_FILE_NAME))); if (attributes == null) { attributes = new ConcurrentHashMap<String, FileAttribute>(); } this.attributes = attributes; Map<String, FileAttributedType> attrubtedTypes = readObject(createFileIfNotExists(getWorkingDirFile(ATTRIBUTED_TYPES__FILE_NAME))); if (attrubtedTypes == null) { attrubtedTypes = new ConcurrentHashMap<String, FileAttributedType>(); } this.attributedTypes = attrubtedTypes; if (this.configuration.isAsyncWrite()) { FILE_STORE_LOGGER.fileAsyncWriteEnabled(this.configuration.getAsyncThreadPool()); this.executorService = Executors.newFixedThreadPool(this.configuration.getAsyncThreadPool()); } }
/** * <p> * Delete the specified {@link File} instance from the filesystem. If the instance is a directory it will be deleted * recursively, otherwise only the file will be deleted. * </p> * * @param file */ public static void delete(File file) { if (file.exists()) { if (file.isDirectory()) { String[] childs = file.list(); for (String childName : childs) { File child = new File(file.getPath() + File.separator + childName); delete(child); } file.delete(); } else { file.delete(); } } }
File agentsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + IDENTITY_TYPES__FILE_NAME)); Map<String, Map<String, FileIdentityType>> identityTypes = readObject(agentsFile); File credentialsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + CREDENTIALS_FILE_NAME)); Map<String, Map<String, List<FileCredentialStorage>>> credentials = readObject(credentialsFile); File permissionsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + PERMISSIONS_FILE_NAME)); Map<String, List<FilePermission>> permissions = readObject(permissionsFile);
/** * <p> * Initializes the working directory. * </p> * * @return */ private void initWorkingDirectory() { String workingDir = getWorkingDir(); File workingDirectoryFile = new File(workingDir); if (workingDirectoryFile.exists()) { if (this.configuration.isAlwaysCreateFiles()) { FILE_STORE_LOGGER.fileConfigAlwaysCreateWorkingDir(workingDirectoryFile.getPath()); delete(workingDirectoryFile); } } workingDirectoryFile.mkdirs(); FILE_STORE_LOGGER.fileConfigUsingWorkingDir(workingDirectoryFile.getPath()); }
File agentsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + IDENTITY_TYPES__FILE_NAME)); Map<String, Map<String, FileIdentityType>> identityTypes = readObject(agentsFile); File credentialsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + CREDENTIALS_FILE_NAME)); Map<String, Map<String, List<FileCredentialStorage>>> credentials = readObject(credentialsFile); File permissionsFile = createFileIfNotExists(getWorkingDirFile(partitionId + File.separator + PERMISSIONS_FILE_NAME)); Map<String, List<FilePermission>> permissions = readObject(permissionsFile);
/** * <p> * Initializes the working directory. * </p> * * @return */ private void initWorkingDirectory() { String workingDir = getWorkingDir(); File workingDirectoryFile = new File(workingDir); if (workingDirectoryFile.exists()) { if (this.configuration.isAlwaysCreateFiles()) { FILE_STORE_LOGGER.fileConfigAlwaysCreateWorkingDir(workingDirectoryFile.getPath()); delete(workingDirectoryFile); } } workingDirectoryFile.mkdirs(); FILE_STORE_LOGGER.fileConfigUsingWorkingDir(workingDirectoryFile.getPath()); }