当前位置: 首页>>代码示例>>Java>>正文


Java GenericFile类代码示例

本文整理汇总了Java中org.apache.camel.component.file.GenericFile的典型用法代码示例。如果您正苦于以下问题:Java GenericFile类的具体用法?Java GenericFile怎么用?Java GenericFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericFile类属于org.apache.camel.component.file包,在下文中一共展示了GenericFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doReleaseExclusiveReadLock

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
protected void doReleaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange) throws Exception {
    // must call super
    super.doReleaseExclusiveReadLock(operations, file, exchange);

    FileLock lock = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), FileLock.class);
    RandomAccessFile rac = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), RandomAccessFile.class);

    String target = file.getFileName();
    if (lock != null) {
        Channel channel = lock.acquiredBy();
        try {
            lock.release();
        } finally {
            // close channel as well
            IOHelper.close(channel, "while releasing exclusive read lock for file: " + target, LOG);
            IOHelper.close(rac, "while releasing exclusive read lock for file: " + target, LOG);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:FileLockExclusiveReadLockStrategy.java

示例2: begin

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {

    // must invoke super
    boolean result = super.begin(operations, endpoint, exchange, file);
    if (!result) {
        return false;
    }

    // okay we got the file then execute the begin renamer
    if (beginRenamer != null) {
        GenericFile<T> newName = beginRenamer.renameFile(exchange, file);
        GenericFile<T> to = renameFile(operations, file, newName);
        if (to != null) {
            to.bindToExchange(exchange);
        }
    }

    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:GenericFileDeleteProcessStrategy.java

示例3: rollback

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
    try {
        deleteLocalWorkFile(exchange);
        operations.releaseRetreivedFileResources(exchange);

        // moved the failed file if specifying the moveFailed option
        if (failureRenamer != null) {
            // create a copy and bind the file to the exchange to be used by the renamer to evaluate the file name
            Exchange copy = exchange.copy();
            file.bindToExchange(copy);
            // must preserve message id
            copy.getIn().setMessageId(exchange.getIn().getMessageId());
            copy.setExchangeId(exchange.getExchangeId());

            GenericFile<T> newName = failureRenamer.renameFile(copy, file);
            renameFile(operations, file, newName);
        }
    } finally {
        // must release lock last
        if (exclusiveReadLockStrategy != null) {
            exclusiveReadLockStrategy.releaseExclusiveReadLockOnRollback(operations, file, exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:GenericFileDeleteProcessStrategy.java

示例4: begin

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
    // must invoke super
    boolean result = super.begin(operations, endpoint, exchange, file);
    if (!result) {
        return false;
    }

    // okay we got the file then execute the begin renamer
    if (beginRenamer != null) {
        GenericFile<T> newName = beginRenamer.renameFile(exchange, file);
        GenericFile<T> to = renameFile(operations, file, newName);
        if (to != null) {
            to.bindToExchange(exchange);
        }
    }

    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:GenericFileRenameProcessStrategy.java

示例5: rollback

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
    try {
        operations.releaseRetreivedFileResources(exchange);

        if (failureRenamer != null) {
            // create a copy and bind the file to the exchange to be used by the renamer to evaluate the file name
            Exchange copy = exchange.copy();
            file.bindToExchange(copy);
            // must preserve message id
            copy.getIn().setMessageId(exchange.getIn().getMessageId());
            copy.setExchangeId(exchange.getExchangeId());

            GenericFile<T> newName = failureRenamer.renameFile(copy, file);
            renameFile(operations, file, newName);
        }
    } finally {
        if (exclusiveReadLockStrategy != null) {
            exclusiveReadLockStrategy.releaseExclusiveReadLockOnRollback(operations, file, exchange);
        }
        deleteLocalWorkFile(exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:GenericFileRenameProcessStrategy.java

示例6: commit

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
    try {
        if (commitRenamer != null) {
            // create a copy and bind the file to the exchange to be used by the renamer to evaluate the file name
            Exchange copy = exchange.copy();
            file.bindToExchange(copy);
            // must preserve message id
            copy.getIn().setMessageId(exchange.getIn().getMessageId());
            copy.setExchangeId(exchange.getExchangeId());

            GenericFile<T> newName = commitRenamer.renameFile(copy, file);
            renameFile(operations, file, newName);
        }
    } finally {
        // must invoke super
        super.commit(operations, endpoint, exchange, file);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:GenericFileRenameProcessStrategy.java

示例7: acquireExclusiveReadLock

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
                                        GenericFile<File> file, Exchange exchange) throws Exception {

    if (!markerFile) {
        // if not using marker file then we assume acquired
        return true;
    }

    String lockFileName = getLockFileName(file);
    LOG.trace("Locking the file: {} using the lock file name: {}", file, lockFileName);

    // create a plain file as marker filer for locking (do not use FileLock)
    boolean acquired = FileUtil.createNewFile(new File(lockFileName));

    // store read-lock state
    exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), acquired);
    exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), lockFileName);

    return acquired;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MarkerFileExclusiveReadLockStrategy.java

示例8: doReleaseExclusiveReadLock

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
protected void doReleaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange) throws Exception {
    if (!markerFile) {
        // if not using marker file then nothing to release
        return;
    }

    boolean acquired = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), false, Boolean.class);

    // only release the file if camel get the lock before
    if (acquired) {
        String lockFileName = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), String.class);
        File lock = new File(lockFileName);

        if (lock.exists()) {
            LOG.trace("Unlocking file: {}", lockFileName);
            boolean deleted = FileUtil.deleteFile(lock);
            LOG.trace("Lock file: {} was deleted: {}", lockFileName, deleted);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MarkerFileExclusiveReadLockStrategy.java

示例9: acquireExclusiveReadLock

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, Exchange exchange) throws Exception {
    // in clustered mode then another node may have processed the file so we must check here again if the file exists
    File path = file.getFile();
    if (!path.exists()) {
        return false;
    }

    // check if we can begin on this file
    String key = asKey(file);
    boolean answer = idempotentRepository.add(key);
    if (!answer) {
        // another node is processing the file so skip
        CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock. Will skip the file: " + file);
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:FileIdempotentRepositoryReadLockStrategy.java

示例10: renameFile

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
protected GenericFile<T> renameFile(GenericFileOperations<T> operations, GenericFile<T> from, GenericFile<T> to) throws IOException {
    // deleting any existing files before renaming
    try {
        operations.deleteFile(to.getAbsoluteFilePath());
    } catch (GenericFileOperationFailedException e) {
        // ignore the file does not exists
    }
    
    // make parent folder if missing
    boolean mkdir = operations.buildDirectory(to.getParent(), to.isAbsolute());
    
    if (!mkdir) {
        throw new GenericFileOperationFailedException("Cannot create directory: " + to.getParent() + " (could be because of denied permissions)");
    }

    log.debug("Renaming file: {} to: {}", from, to);
    boolean renamed = operations.renameFile(from.getAbsoluteFilePath(), to.getAbsoluteFilePath());
    if (!renamed) {
        throw new GenericFileOperationFailedException("Cannot rename file: " + from + " to: " + to);
    }

    return to;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:GenericFileProcessStrategySupport.java

示例11: createExchange

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Hello World", Exchange.FILE_NAME, "test/hello.txt");

    // get the file handle
    file = new File("target/filelanguage/test/hello.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);

    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);

    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());

    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());

    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:FileLanguageTest.java

示例12: createExchange

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Bye World", Exchange.FILE_NAME, "test/bye.def.txt");

    // get the file handle
    file = new File("target/filelanguage/test/bye.def.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);

    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);

    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());

    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());

    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:FileLanguageExtSingleTest.java

示例13: testTroubleDeletingFile

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
public void testTroubleDeletingFile() throws Exception {
    deleteCounter = 0;
    existsCounter = 0;

    @SuppressWarnings("unchecked")
    GenericFileEndpoint<Object> endpoint = context.getEndpoint("file://target/foo", GenericFileEndpoint.class);
    Exchange exchange = endpoint.createExchange();

    GenericFile<Object> file = new GenericFile<Object>();
    file.setAbsoluteFilePath("target/foo/me.txt");

    GenericFileDeleteProcessStrategy<Object> strategy = new GenericFileDeleteProcessStrategy<Object>();
    strategy.commit(new MyGenericFileOperations(), endpoint, exchange, file);

    assertEquals("Should have tried to delete file 2 times", 2, deleteCounter);
    assertEquals("Should have tried to delete file 2 times", 2, existsCounter);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:GenericFileDeleteProcessStrategyTest.java

示例14: testCannotDeleteFile

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
public void testCannotDeleteFile() throws Exception {
    deleteCounter = 0;
    existsCounter = 0;

    @SuppressWarnings("unchecked")
    GenericFileEndpoint<Object> endpoint = context.getEndpoint("file://target/foo", GenericFileEndpoint.class);
    Exchange exchange = endpoint.createExchange();

    GenericFile<Object> file = new GenericFile<Object>();
    file.setAbsoluteFilePath("target/foo/boom.txt");

    GenericFileDeleteProcessStrategy<Object> strategy = new GenericFileDeleteProcessStrategy<Object>();
    try {
        strategy.commit(new MyGenericFileOperations(), endpoint, exchange, file);
        fail("Should have thrown an exception");
    } catch (GenericFileOperationFailedException e) {
        // expected
    }

    assertEquals("Should have tried to delete file 3 times", 3, deleteCounter);
    assertEquals("Should have tried to delete file 3 times", 3, existsCounter);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:GenericFileDeleteProcessStrategyTest.java

示例15: pollDirectory

import org.apache.camel.component.file.GenericFile; //导入依赖的package包/类
@Override
protected boolean pollDirectory(String fileName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
    String currentDir = null;
    if (isStepwise()) {
        // must remember current dir so we stay in that directory after the poll
        currentDir = operations.getCurrentDirectory();
    }

    // strip trailing slash
    fileName = FileUtil.stripTrailingSeparator(fileName);

    boolean answer = doPollDirectory(fileName, null, fileList, depth);
    if (currentDir != null) {
        operations.changeCurrentDirectory(currentDir);
    }

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:SftpConsumer.java


注:本文中的org.apache.camel.component.file.GenericFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。