List of usage examples for org.apache.commons.vfs2 FileType FILE
FileType FILE
To view the source code for org.apache.commons.vfs2 FileType FILE.
Click Source Link
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
public FileSystemDesignProvider(DesignReference ref, WGACore core, WGDatabase db, String path, Map<String, String> options) throws WGDesignSyncException, IOException, WGAPIException, InstantiationException, IllegalAccessException, InvalidCSConfigVersionException { super(core, db, path, options); _designReference = ref;// ww w .j a v a 2s .co m _name = "Design Directory " + getBaseFolder().getURL().toString(); _strictFCDateDetermination = true; _lookupVariants = WGUtils.getBooleanMapValue(options, OPTION_DESIGNVARIANTS, false); _variantSuffix = "." + getDB().getDbReference(); // In case of the base folder being a file (an archived design) we can set notifying to true, as there will be no updates. This enables the WGAPI to cache designs. _notifying = getFsResources().getBaseFolder().getType().equals(FileType.FILE); if (options.containsKey(OPTION_NO_BACKGROUND_CHANGES)) { _noBackgroundChanges = WGUtils.toBoolean(options.get(OPTION_NO_BACKGROUND_CHANGES), false); } else { _noBackgroundChanges = (Boolean) WGA.get(core).server() .getServerOption(WGAConfiguration.SERVEROPTION_CACHE_DESIGN_NO_BACKGROUND_CHANGES); } }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
@Override void queueFiles(FileQueueChecker fqc, NavigableSet<RemoteFile> fileQueue, FileFilter fileFilter) throws IOException, StageException { boolean done = false; int retryCounter = 0; while (!done && retryCounter < MAX_RETRIES) { try {//from ww w . jav a2 s. c o m remoteDir.refresh(); // A call to getChildren() and then refresh() is needed in order to properly refresh if files were updated // A possible bug in VFS? remoteDir.getChildren(); remoteDir.refresh(); done = true; } catch (FileSystemException fse) { // Refresh can fail due to session is down, a timeout, etc; so try getting a new connection if (retryCounter < MAX_RETRIES - 1) { LOG.info("Got FileSystemException when trying to refresh remote directory. '{}'", fse.getMessage(), fse); LOG.warn("Retrying connection to remote directory"); remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options); } else { throw new StageException(Errors.REMOTE_18, fse.getMessage(), fse); } } retryCounter++; } FileObject[] theFiles = remoteDir.getChildren(); if (conf.processSubDirectories) { theFiles = ArrayUtils.addAll(theFiles, remoteDir.findFiles(fileFilter)); } for (FileObject file : theFiles) { String path = relativizeToRoot(file.getName().getPath()); LOG.debug("Checking {}", path); if (file.getType() != FileType.FILE) { LOG.trace("Skipping {} because it is not a file", path); continue; } //check if base name matches - not full path. Matcher matcher = fileFilter.getRegex().matcher(file.getName().getBaseName()); if (!matcher.matches()) { LOG.trace("Skipping {} because it does not match the regex", path); continue; } RemoteFile tempFile = new FTPRemoteFile(path, getModTime(file), file); if (fqc.shouldQueue(tempFile)) { LOG.debug("Queuing file {} with modtime {}", tempFile.getFilePath(), tempFile.getLastModified()); // If we are done with all files, the files with the final mtime might get re-ingested over and over. // So if it is the one of those, don't pull it in. fileQueue.add(tempFile); } } }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportSender.java
/** * Send the given message over the VFS transport * * @param msgCtx the axis2 message context * @throws AxisFault on error/* ww w.ja v a 2 s.c om*/ */ public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo) throws AxisFault { if (waitForSynchronousResponse(msgCtx)) { throw new AxisFault("The VFS transport doesn't support synchronous responses. " + "Please use the appropriate (out only) message exchange pattern."); } VFSOutTransportInfo vfsOutInfo = null; if (targetAddress != null) { vfsOutInfo = new VFSOutTransportInfo(targetAddress, globalFileLockingFlag); } else if (outTransportInfo != null && outTransportInfo instanceof VFSOutTransportInfo) { vfsOutInfo = (VFSOutTransportInfo) outTransportInfo; } if (vfsOutInfo != null) { FileObject replyFile = null; try { boolean wasError = true; int retryCount = 0; int maxRetryCount = vfsOutInfo.getMaxRetryCount(); long reconnectionTimeout = vfsOutInfo.getReconnectTimeout(); boolean append = vfsOutInfo.isAppend(); while (wasError) { try { retryCount++; replyFile = fsManager.resolveFile(vfsOutInfo.getOutFileURI()); if (replyFile == null) { log.error("replyFile is null"); throw new FileSystemException("replyFile is null"); } wasError = false; } catch (FileSystemException e) { log.error("cannot resolve replyFile", e); if (maxRetryCount <= retryCount) { handleException("cannot resolve replyFile repeatedly: " + e.getMessage(), e); } } if (wasError) { try { Thread.sleep(reconnectionTimeout); } catch (InterruptedException e2) { e2.printStackTrace(); } } } if (replyFile.exists()) { if (replyFile.getType() == FileType.FOLDER) { // we need to write a file containing the message to this folder FileObject responseFile = fsManager.resolveFile(replyFile, VFSUtils.getFileName(msgCtx, vfsOutInfo)); // if file locking is not disabled acquire the lock // before uploading the file if (vfsOutInfo.isFileLockingEnabled()) { acquireLockForSending(responseFile, vfsOutInfo); if (!responseFile.exists()) { responseFile.createFile(); } populateResponseFile(responseFile, msgCtx, append, true); VFSUtils.releaseLock(fsManager, responseFile); } else { if (!responseFile.exists()) { responseFile.createFile(); } populateResponseFile(responseFile, msgCtx, append, false); } } else if (replyFile.getType() == FileType.FILE) { // if file locking is not disabled acquire the lock // before uploading the file if (vfsOutInfo.isFileLockingEnabled()) { acquireLockForSending(replyFile, vfsOutInfo); populateResponseFile(replyFile, msgCtx, append, true); VFSUtils.releaseLock(fsManager, replyFile); } else { populateResponseFile(replyFile, msgCtx, append, false); } } else { handleException("Unsupported reply file type : " + replyFile.getType() + " for file : " + vfsOutInfo.getOutFileURI()); } } else { // if file locking is not disabled acquire the lock before uploading the file if (vfsOutInfo.isFileLockingEnabled()) { acquireLockForSending(replyFile, vfsOutInfo); replyFile.createFile(); populateResponseFile(replyFile, msgCtx, append, true); VFSUtils.releaseLock(fsManager, replyFile); } else { replyFile.createFile(); populateResponseFile(replyFile, msgCtx, append, false); } } } catch (FileSystemException e) { handleException("Error resolving reply file : " + vfsOutInfo.getOutFileURI(), e); } finally { if (replyFile != null) { try { replyFile.close(); } catch (FileSystemException ignore) { } } } } else { handleException("Unable to determine out transport information to send message"); } }
From source file:de.innovationgate.wgpublisher.design.fs.DesignFileDocument.java
public InputStream getFileData(String strFile) throws WGAPIException { try {/* ww w . j a va2s . c o m*/ if (getType() != WGDocument.TYPE_FILECONTAINER) { return null; } FileObject file = getFileContainerFile(strFile); if (file == null) { return null; } if (file.getType().equals(FileType.FILE)) { return file.getContent().getInputStream(); } else { return null; } } catch (Exception e) { throw new WGBackendException("Exception reading container file data", e); } }
From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java
/** * Helper method to execute file move operation. * //from w ww.ja v a 2 s . c o m * @param file * FileObject of the file to be moved * @param toDirectoryPath * @return true if give file was a file and it was successfully moved to * destination directory. False if given file is not a file or given * destination directory is not a directory * @throws FileSystemException * If file move operation fails */ private boolean moveFile(FileObject file, String toDirectoryPath, boolean lockEnabled) throws FileSystemException { if (file.getType() == FileType.FILE) { String targetPath = toDirectoryPath + "/" + file.getName().getBaseName(); String lockFilePath = null; if (lockEnabled) { lockFilePath = createLockFile(targetPath); } FileObject newLocation = resolveFile(targetPath); try { log.debug("About to move " + fileObjectNameForDebug(file) + " to " + fileObjectNameForDebug(newLocation)); if (options.isStreamingTransferEnabled()) { streamFromFileToFile(file, resolveFile(targetPath)); } else { newLocation.copyFrom(file, Selectors.SELECT_SELF); } newLocation.close(); file.delete(); file.close(); log.debug("File moved to " + fileObjectNameForDebug(newLocation)); } finally { if (lockFilePath != null) { deleteLockFile(lockFilePath); } } return true; } else { return false; } }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * AJAX tree functions// w w w.ja va 2 s . c o m */ public String execute() { normalizeTreeRequest(); JsTreeResult result = new JsTreeResult(); final AllFileSelector ALL_FILES = new AllFileSelector(); FileSystemManager fsManager = null; FileObject rootFile = null; FileObject file = null; FileObject referenceFile = null; try { fsManager = VfsUtility.getManager(); rootFile = fsManager.resolveFile(rootPath, fsOptions); if (JsTreeRequest.OP_GET_CHILDREN.equalsIgnoreCase(requestData.getOperation())) { String parentPath = requestData.getId(); List<JsTreeNodeData> nodes = null; try { nodes = getChildNodes(rootFile, parentPath); if (requestData.isRoot() && rootNodeName != null) { // add root node JsTreeNodeData rootNode = new JsTreeNodeData(); rootNode.setData(rootNodeName); Map<String, Object> attr = new HashMap<String, Object>(); rootNode.setAttr(attr); attr.put("id", "."); attr.put("rel", "root"); attr.put("fileType", FileType.FOLDER.toString()); rootNode.setChildren(nodes); rootNode.setState(JsTreeNodeData.STATE_OPEN); nodes = new LinkedList<JsTreeNodeData>(); nodes.add(rootNode); } } catch (Exception e) { log.error("Cannot get child nodes for: " + parentPath, e); nodes = new LinkedList<JsTreeNodeData>(); } responseData = nodes; } else if (JsTreeRequest.OP_REMOVE_NODE.equalsIgnoreCase(requestData.getOperation())) { String path = requestData.getId(); try { file = rootFile.resolveFile(path, NameScope.DESCENDENT); boolean wasDeleted = false; if (file.getType() == FileType.FILE) { wasDeleted = file.delete(); } else { wasDeleted = file.delete(ALL_FILES) > 0; } result.setStatus(wasDeleted); } catch (Exception e) { result.setStatus(false); log.error("Cannot delete: " + path, e); } responseData = result; } else if (JsTreeRequest.OP_CREATE_NODE.equalsIgnoreCase(requestData.getOperation())) { String parentPath = requestData.getReferenceId(); String name = requestData.getTitle(); try { referenceFile = rootFile.resolveFile(parentPath, NameScope.DESCENDENT_OR_SELF); file = referenceFile.resolveFile(name, NameScope.CHILD); file.createFolder(); result.setStatus(true); result.setId(rootFile.getName().getRelativeName(file.getName())); } catch (Exception e) { result.setStatus(false); log.error("Cannot create folder '" + name + "' under '" + parentPath + "'", e); } responseData = result; } else if (JsTreeRequest.OP_RENAME_NODE.equalsIgnoreCase(requestData.getOperation())) { String path = requestData.getId(); String name = requestData.getTitle(); try { referenceFile = rootFile.resolveFile(path, NameScope.DESCENDENT); file = referenceFile.getParent().resolveFile(name, NameScope.CHILD); referenceFile.moveTo(file); result.setStatus(true); } catch (Exception e) { result.setStatus(false); log.error("Cannot rename '" + path + "' to '" + name + "'", e); } responseData = result; } else if (JsTreeRequest.OP_MOVE_NODE.equalsIgnoreCase(requestData.getOperation())) { String newParentPath = requestData.getReferenceId(); String originalPath = requestData.getId(); try { referenceFile = rootFile.resolveFile(originalPath, NameScope.DESCENDENT); file = rootFile.resolveFile(newParentPath, NameScope.DESCENDENT_OR_SELF) .resolveFile(referenceFile.getName().getBaseName(), NameScope.CHILD); if (requestData.isCopy()) { file.copyFrom(referenceFile, ALL_FILES); } else { referenceFile.moveTo(file); } result.setStatus(true); } catch (Exception e) { result.setStatus(false); log.error("Cannot move '" + originalPath + "' to '" + newParentPath + "'", e); } responseData = result; } } catch (FileSystemException e) { log.error("Cannot perform file operation.", e); } finally { VfsUtility.close(fsManager, file, referenceFile, rootFile); } return SUCCESS; }
From source file:hadoopInstaller.installation.Installer.java
private void getBundleHashes(FileObject file) throws FileSystemException, InstallationFatalError { String fileName = file.getName().getBaseName(); getLog().trace("HadoopInstaller.MD5.Start", fileName); //$NON-NLS-1$ if (file.getType().equals(FileType.FILE)) { try {//from ww w. j a va 2 s . co m String md5 = MD5Calculator.calculateFor(file); getFileHashes().put(fileName, md5); getLog().trace("HadoopInstaller.MD5.Success", fileName, //$NON-NLS-1$ md5); } catch (NoSuchAlgorithmException | IOException e) { throw new InstallationFatalError(e, "HadoopInstaller.MD5.Error", fileName); //$NON-NLS-1$ } } }
From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java
@Override public DeploySystem<DbEnvironment> readSystem(FileObject sourcePath) { HierarchicalConfiguration sysCfg = getConfig(sourcePath); DbPlatform systemDbPlatform = dbPlatformConfiguration.valueOf(sysCfg.getString("[@type]")); MutableList<String> sourceDirs = ListAdapter.adapt(sysCfg.getList("[@sourceDirs]")); ImmutableSet<String> acceptedExtensions = ListAdapter.adapt(sysCfg.getList("[@acceptedExtensions]")).toSet() .toImmutable();/* w w w . j a v a2 s.c o m*/ MutableList<DbEnvironment> envList = Lists.mutable.empty(); for (HierarchicalConfiguration envCfg : iterConfig(sysCfg, "environments.dbEnvironment")) { DbEnvironment dbEnv = new DbEnvironment(); FileObject rootDir = sourcePath.getType() == FileType.FILE ? sourcePath.getParent() : sourcePath; // Use coreSourcePath and additionalSourceDirs here (instead of setSourceDirs) to facilitate any external integrations dbEnv.setCoreSourcePath(rootDir); dbEnv.setAdditionalSourceDirs(sourceDirs); dbEnv.setAcceptedExtensions(acceptedExtensions); dbEnv.setCleanBuildAllowed(envCfg.getBoolean("[@cleanBuildAllowed]", false)); dbEnv.setDbHost(envCfg.getString("[@dbHost]")); dbEnv.setDbPort(envCfg.getInt("[@dbPort]", 0)); dbEnv.setDbServer(envCfg.getString("[@dbServer]")); dbEnv.setDbSchemaPrefix(envCfg.getString("[@dbSchemaPrefix]")); dbEnv.setDbSchemaSuffix(envCfg.getString("[@dbSchemaSuffix]")); dbEnv.setDbDataSourceName(envCfg.getString("[@dbDataSourceName]")); dbEnv.setJdbcUrl(envCfg.getString("[@jdbcUrl]")); MutableMap<String, String> tokens = Maps.mutable.empty(); for (HierarchicalConfiguration tok : iterConfig(envCfg, "tokens.token")) { tokens.put(tok.getString("[@key]"), tok.getString("[@value]")); } dbEnv.setTokens(tokens.toImmutable()); // Allow the groups + users to be tokenized upfront for compatibility w/ the EnvironmentInfraSetup classes Tokenizer tokenizer = new Tokenizer(dbEnv.getTokens(), dbEnv.getTokenPrefix(), dbEnv.getTokenSuffix()); dbEnv.setGroups(iterConfig(sysCfg, "groups.group").collect(convertCfgToGroup(tokenizer))); dbEnv.setUsers(iterConfig(sysCfg, "users.user").collect(convertCfgToUser(tokenizer))); if (envCfg.getString("[@driverClass]") != null) { dbEnv.setDriverClassName(envCfg.getString("[@driverClass]")); } dbEnv.setName(envCfg.getString("[@name]")); dbEnv.setDefaultUserId(envCfg.getString("[@defaultUserId]")); dbEnv.setDefaultPassword(envCfg.getString("[@defaultPassword]")); dbEnv.setDefaultTablespace(envCfg.getString("[@defaultTablespace]")); // TODO add include/exclude schemas functionality MutableList<Schema> schemaObjs = Lists.mutable.withAll(iterConfig(sysCfg, "schemas.schema")) .collect(convertCfgToSchema(systemDbPlatform)); MutableSet<String> schemasToInclude = iterString(envCfg, "includeSchemas").toSet(); MutableSet<String> schemasToExclude = iterString(envCfg, "excludeSchemas").toSet(); if (!schemasToInclude.isEmpty() && !schemasToExclude.isEmpty()) { throw new IllegalArgumentException("Environment " + dbEnv.getName() + " has includeSchemas [" + schemasToInclude + "] and excludeSchemas [" + schemasToExclude + "] defined; please only specify one of them"); } else if (!schemasToInclude.isEmpty()) { schemaObjs = schemaObjs.select(Predicates.attributeIn(Schema.TO_NAME, schemasToInclude)); } else if (!schemasToExclude.isEmpty()) { schemaObjs = schemaObjs.reject(Predicates.attributeIn(Schema.TO_NAME, schemasToExclude)); } MutableMap<String, String> schemaNameOverrides = Maps.mutable.empty(); MutableSet<String> schemaNames = schemaObjs.collect(Schema.TO_NAME).toSet(); for (HierarchicalConfiguration schemaOverride : iterConfig(envCfg, "schemaOverrides.schemaOverride")) { String schema = schemaOverride.getString("[@schema]"); if (schemaObjs.collect(Schema.TO_NAME).contains(schema)) { schemaNameOverrides.put(schema, schemaOverride.getString("[@overrideValue]")); } else { throw new IllegalArgumentException( "Schema override definition value " + schema + " is not defined in the schema list " + schemaNames + " for environment " + dbEnv.getName()); } } dbEnv.setSchemaNameOverrides(schemaNameOverrides.toImmutable()); // ensure that we only store the unique schema names here dbEnv.setSchemas(UnifiedSetWithHashingStrategy .newSet(HashingStrategies.fromFunction(Schema.TO_NAME), schemaObjs).toImmutable()); dbEnv.setPersistToFile(envCfg.getBoolean("[@persistToFile]", false)); dbEnv.setDisableAuditTracking(envCfg.getBoolean("[@disableAuditTracking]", false)); dbEnv.setRollbackDetectionEnabled(envCfg.getBoolean("[@rollbackDetectionEnabled]", sysCfg.getBoolean("[@rollbackDetectionEnabled]", true))); dbEnv.setAutoReorgEnabled( envCfg.getBoolean("[@autoReorgEnabled]", sysCfg.getBoolean("[@autoReorgEnabled]", true))); dbEnv.setInvalidObjectCheckEnabled(envCfg.getBoolean("[@invalidObjectCheckEnabled]", sysCfg.getBoolean("[@invalidObjectCheckEnabled]", true))); dbEnv.setReorgCheckEnabled( envCfg.getBoolean("[@reorgCheckEnabled]", sysCfg.getBoolean("[@reorgCheckEnabled]", true))); dbEnv.setChecksumDetectionEnabled(envCfg.getBoolean("[@checksumDetectionEnabled]", sysCfg.getBoolean("[@checksumDetectionEnabled]", false))); dbEnv.setMetadataLineReaderVersion( envCfg.getInt("[@metadataLineReaderVersion]", sysCfg.getInt("[@metadataLineReaderVersion]", dbPlatformConfiguration.getFeatureToggleVersion("metadataLineReaderVersion")))); dbEnv.setCsvVersion(envCfg.getInt("[@csvVersion]", sysCfg.getInt("[@csvVersion]", dbPlatformConfiguration.getFeatureToggleVersion("csvVersion")))); int legacyDirectoryStructureEnabledValue = envCfg.getInt("[@legacyDirectoryStructureEnabled]", sysCfg.getInt("[@legacyDirectoryStructureEnabled]", dbPlatformConfiguration.getFeatureToggleVersion("legacyDirectoryStructureEnabled"))); dbEnv.setLegacyDirectoryStructureEnabled(legacyDirectoryStructureEnabledValue == 1); // 1 == legacy, 2 == new MutableMap<String, String> extraEnvAttrs = Maps.mutable.empty(); for (String extraEnvAttr : dbPlatformConfiguration.getExtraEnvAttrs()) { String attrStr = "[@" + extraEnvAttr + "]"; extraEnvAttrs.put(extraEnvAttr, envCfg.getString(attrStr, sysCfg.getString(attrStr))); } dbEnv.setExtraEnvAttrs(extraEnvAttrs.toImmutable()); ImmutableList<HierarchicalConfiguration> envPermissions = iterConfig(envCfg, "permissions.permission"); ImmutableList<HierarchicalConfiguration> sysPermissions = iterConfig(sysCfg, "permissions.permission"); if (!envPermissions.isEmpty()) { dbEnv.setPermissions(envPermissions.collect(convertCfgToPermission(tokenizer))); } else if (!sysPermissions.isEmpty()) { dbEnv.setPermissions(sysPermissions.collect(convertCfgToPermission(tokenizer))); } DbPlatform platform; if (envCfg.getString("[@inMemoryDbType]") != null) { platform = dbPlatformConfiguration.valueOf(envCfg.getString("[@inMemoryDbType]")); } else { platform = systemDbPlatform; } dbEnv.setSystemDbPlatform(systemDbPlatform); dbEnv.setPlatform(platform); String delim = sysCfg.getString("[@dataDelimiter]"); if (delim != null) { if (delim.length() == 1) { dbEnv.setDataDelimiter(delim.charAt(0)); } else { throw new IllegalArgumentException( "dataDelimiter must be 1 character long. instead, got [" + delim + "]"); } } String nullToken = sysCfg.getString("[@nullToken]"); if (nullToken != null) { dbEnv.setNullToken(nullToken); } dbEnv.setAuditTableSql(getProperty(sysCfg, envCfg, "auditTableSql")); envList.add(dbEnv); } CollectionUtil.verifyNoDuplicates(envList, DbEnvironment.TO_NAME, "Invalid configuration from " + sourcePath + "; not expecting duplicate env names"); return new DeploySystem<DbEnvironment>(envList); }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java
/** * Search for files that match the given regex pattern and create a list * Then process each of these files and update the status of the scan on * the poll table//from w ww . j ava 2s . c om * @param entry the poll table entry for the scan * @param fileURI the file or directory to be scanned */ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { FileObject fileObject = null; //TODO : Trying to make the correct URL out of the malformed one. if (fileURI.contains("vfs:")) { fileURI = fileURI.substring(fileURI.indexOf("vfs:") + 4); } if (log.isDebugEnabled()) { log.debug("Scanning directory or file : " + VFSUtils.maskURLPassword(fileURI)); } boolean wasError = true; int retryCount = 0; int maxRetryCount = entry.getMaxRetryCount(); long reconnectionTimeout = entry.getReconnectTimeout(); while (wasError) { try { retryCount++; fileObject = fsManager.resolveFile(fileURI); if (fileObject == null) { log.error("fileObject is null"); throw new FileSystemException("fileObject is null"); } wasError = false; } catch (FileSystemException e) { if (retryCount >= maxRetryCount) { processFailure( "Repeatedly failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI), e, entry); return; } else { log.warn("Failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI) + ", in attempt " + retryCount + ", " + e.getMessage() + " Retrying in " + reconnectionTimeout + " milliseconds."); } } if (wasError) { try { Thread.sleep(reconnectionTimeout); } catch (InterruptedException e2) { log.error("Thread was interrupted while waiting to reconnect.", e2); } } } try { if (fileObject.exists() && fileObject.isReadable()) { entry.setLastPollState(PollTableEntry.NONE); FileObject[] children = null; try { children = fileObject.getChildren(); } catch (FileNotFolderException ignored) { } catch (FileSystemException ex) { log.error(ex.getMessage(), ex); } // if this is a file that would translate to a single message if (children == null || children.length == 0) { boolean isFailedRecord = false; if (entry.getMoveAfterMoveFailure() != null) { isFailedRecord = isFailedRecord(fileObject, entry); } if (fileObject.getType() == FileType.FILE && !isFailedRecord) { if (!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled() && VFSUtils.acquireLock(fsManager, fileObject))) { try { processFile(entry, fileObject); entry.setLastPollState(PollTableEntry.SUCCSESSFUL); metrics.incrementMessagesReceived(); } catch (AxisFault e) { logException("Error processing File URI : " + fileObject.getName(), e); entry.setLastPollState(PollTableEntry.FAILED); metrics.incrementFaultsReceiving(); } try { moveOrDeleteAfterProcessing(entry, fileObject); } catch (AxisFault axisFault) { logException("File object '" + fileObject.getURL().toString() + "' " + "cloud not be moved", axisFault); entry.setLastPollState(PollTableEntry.FAILED); String timeStamp = VFSUtils.getSystemTime(entry.getFailedRecordTimestampFormat()); addFailedRecord(entry, fileObject, timeStamp); } if (entry.isFileLockingEnabled()) { VFSUtils.releaseLock(fsManager, fileObject); if (log.isDebugEnabled()) { log.debug("Removed the lock file '" + fileObject.toString() + ".lock' of the file '" + fileObject.toString()); } } } else if (log.isDebugEnabled()) { log.debug("Couldn't get the lock for processing the file : " + fileObject.getName()); } else if (isFailedRecord) { if (entry.isFileLockingEnabled()) { VFSUtils.releaseLock(fsManager, fileObject); } // schedule a cleanup task if the file is there if (fsManager.resolveFile(fileObject.getURL().toString()) != null && removeTaskState == STATE_STOPPED && entry.getMoveAfterMoveFailure() != null) { workerPool.execute(new FileRemoveTask(entry, fileObject)); } if (log.isDebugEnabled()) { log.debug("File '" + fileObject.getURL() + "' has been marked as a failed" + " record, it will not process"); } } } } else { int failCount = 0; int successCount = 0; int processCount = 0; Integer iFileProcessingInterval = entry.getFileProcessingInterval(); Integer iFileProcessingCount = entry.getFileProcessingCount(); if (log.isDebugEnabled()) { log.debug("File name pattern : " + entry.getFileNamePattern()); } for (FileObject child : children) { //skipping *.lock file if (child.getName().getBaseName().endsWith(".lock")) { continue; } boolean isFailedRecord = false; if (entry.getMoveAfterMoveFailure() != null) { isFailedRecord = isFailedRecord(child, entry); } if (entry.getFileNamePattern() != null && child.getName().getBaseName().matches(entry.getFileNamePattern())) { //child's file name matches the file name pattern //now we try to get the lock and process if (log.isDebugEnabled()) { log.debug("Matching file : " + child.getName().getBaseName()); } if ((!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled() && VFSUtils.acquireLock(fsManager, child))) && !isFailedRecord) { //process the file try { if (log.isDebugEnabled()) { log.debug("Processing file :" + child); } processCount++; processFile(entry, child); successCount++; // tell moveOrDeleteAfterProcessing() file was success entry.setLastPollState(PollTableEntry.SUCCSESSFUL); metrics.incrementMessagesReceived(); } catch (Exception e) { logException("Error processing File URI : " + child.getName(), e); failCount++; // tell moveOrDeleteAfterProcessing() file failed entry.setLastPollState(PollTableEntry.FAILED); metrics.incrementFaultsReceiving(); } //skipping un-locking file if failed to do delete/move after process boolean skipUnlock = false; try { moveOrDeleteAfterProcessing(entry, child); } catch (AxisFault axisFault) { logException( "File object '" + child.getURL().toString() + "'cloud not be moved, will remain in \"locked\" state", axisFault); skipUnlock = true; failCount++; entry.setLastPollState(PollTableEntry.FAILED); String timeStamp = VFSUtils .getSystemTime(entry.getFailedRecordTimestampFormat()); addFailedRecord(entry, child, timeStamp); } // if there is a failure or not we'll try to release the lock if (entry.isFileLockingEnabled() && !skipUnlock) { VFSUtils.releaseLock(fsManager, child); } } } else if (entry.getFileNamePattern() != null && !child.getName().getBaseName().matches(entry.getFileNamePattern())) { //child's file name does not match the file name pattern if (log.isDebugEnabled()) { log.debug("Non-Matching file : " + child.getName().getBaseName()); } } else if (isFailedRecord) { //it is a failed record if (entry.isFileLockingEnabled()) { VFSUtils.releaseLock(fsManager, child); VFSUtils.releaseLock(fsManager, fileObject); } if (fsManager.resolveFile(child.getURL().toString()) != null && removeTaskState == STATE_STOPPED && entry.getMoveAfterMoveFailure() != null) { workerPool.execute(new FileRemoveTask(entry, child)); } if (log.isDebugEnabled()) { log.debug("File '" + fileObject.getURL() + "' has been marked as a failed record, it will not " + "process"); } } if (iFileProcessingInterval != null && iFileProcessingInterval > 0) { try { if (log.isDebugEnabled()) { log.debug("Put the VFS processor to sleep for : " + iFileProcessingInterval); } Thread.sleep(iFileProcessingInterval); } catch (InterruptedException ie) { log.error("Unable to set the interval between file processors." + ie); } } else if (iFileProcessingCount != null && iFileProcessingCount <= processCount) { break; } } if (failCount == 0 && successCount > 0) { entry.setLastPollState(PollTableEntry.SUCCSESSFUL); } else if (successCount == 0 && failCount > 0) { entry.setLastPollState(PollTableEntry.FAILED); } else { entry.setLastPollState(PollTableEntry.WITH_ERRORS); } } // processing of this poll table entry is complete long now = System.currentTimeMillis(); entry.setLastPollTime(now); entry.setNextPollTime(now + entry.getPollInterval()); } else if (log.isDebugEnabled()) { log.debug("Unable to access or read file or directory : " + VFSUtils.maskURLPassword(fileURI) + "." + " Reason: " + (fileObject.exists() ? (fileObject.isReadable() ? "Unknown reason" : "The file can not be read!") : "The file does not exists!")); } onPollCompletion(entry); } catch (FileSystemException e) { processFailure("Error checking for existence and readability : " + VFSUtils.maskURLPassword(fileURI), e, entry); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Determines the type of the file, returns null if the file does not exist. * //w w w .j av a 2 s . c o m * @return the file type * * @throws Exception the exception */ @Override protected FileType doGetType() throws Exception { // log.debug("relative path:" + relPath); if (this.fileInfo == null) { return FileType.IMAGINARY; } else if (this.fileInfo.isDirectory()) { return FileType.FOLDER; } else if (this.fileInfo.isFile()) { return FileType.FILE; } else if (this.fileInfo.isSoftLink()) { return FileType.FILE; // getLinkDestination().getType(); } throw new FileSystemException("vfs.provider.gsiftp/get-type.error", getName()); }