List of usage examples for org.apache.commons.transaction.file FileResourceManager FileResourceManager
public FileResourceManager(String storeDir, String workDir, boolean urlEncodePath, LoggerFacade logger)
From source file:com.anrisoftware.globalpom.fileresourcemanager.FileResourceManagerProvider.java
@Override public FileResourceManager get() { String workDir = createTmpDir(); boolean urlEncodePath = false; final ByteArrayOutputStream stream = new ByteArrayOutputStream(1024); PrintWriter printWriter = new PrintWriter(stream) { @Override/* w w w.j a v a 2 s .c om*/ public void flush() { super.flush(); log.logFileResourceMessage(stream.toString()); } }; LoggerFacade logger = new PrintWriterLogger(printWriter, "", debug); return new FileResourceManager(storeDir, workDir, urlEncodePath, logger); }
From source file:com.openmeap.file.FileOperationManagerImplTest.java
/** * Creates the working/store directories, sets up the logger, and creates the FileOperationManager. * @throws IOException//from ww w. j av a 2s . c o m */ @BeforeClass public static void setUp() throws IOException { org.apache.log4j.BasicConfigurator.configure(); org.apache.log4j.Logger.getLogger("org.apache.commons").setLevel(Level.OFF); org.apache.log4j.Logger.getLogger("Locking").setLevel(Level.OFF); org.apache.log4j.Logger.getLogger("com.openmeap").setLevel(Level.TRACE); new File(STOREDIR).mkdir(); new File(WORKDIR).mkdir(); File f = new File(STOREDIR + File.separator + TEST_FILE); OutputStream stream = new BufferedOutputStream(new FileOutputStream(f)); InputStream inputStream = new ByteArrayInputStream(TEST_TEXT.getBytes()); try { Utils.pipeInputStreamIntoOutputStream(inputStream, stream); } finally { if (stream != null) { stream.close(); } } mgr = new FileOperationManagerImpl(); FileResourceManager resMgr = new FileResourceManager(STOREDIR, WORKDIR, false, new SLF4JLoggerFacade(LoggerFactory.getLogger("org.apache.commons.transaction.file"))); mgr.setFileResourceManager(resMgr); }
From source file:de.thorstenberger.examServer.dao.AbstractTransactionalFileIO.java
/** * Create a new file transaction manager for the given directory. * * @param path//from ww w .j a va 2 s. co m * directory */ private synchronized void initFileTransactionsForDirectory(final String path) { if (resourceManagers.get(path) == null) { resourceManagers.put(path, new FileResourceManager(path, path + "_dirty", false, new CommonsLoggingLogger(log))); try { resourceManagers.get(path).start(); } catch (final ResourceManagerSystemException ex) { throw new TaskModelPersistenceException(ex); } } }
From source file:com.openmeap.file.FileOperationManagerImpl.java
private void _setup() throws FileOperationException { if (fileResourceManager != null) { return;/*from w ww . j ava 2 s . co m*/ } GlobalSettings settings = (GlobalSettings) modelService.findByPrimaryKey(GlobalSettings.class, 1L); if (settings.getTemporaryStoragePath() == null || !new File(settings.getTemporaryStoragePath()).exists()) { String msg = "The storage path has not been set in GlobalSettings. Use the settings page to fix this."; logger.error(msg); throw new FileOperationException(msg); } FileResourceManager resMgr = new FileResourceManager(settings.getTemporaryStoragePath(), settings.getTemporaryStoragePath() + "/tmp", false, new SLF4JLoggerFacade(LoggerFactory.getLogger(FileResourceManager.class))); fileResourceManager = resMgr; }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XADir.java
/** * Constructor to create objects that represent a transactional directory. * <p>//from w w w. j a v a2s. co m * The constructor checks if the <code>storeDir</code> is a directory or not. * If it is not then {@link org.jboss.jbossts.fileio.xalib.txdirs.exceptions.NotDirectoryException} * exception is thrown. Otherwise, a new <code>FileResourceManager</code> object * is created to allow access to transactional methods (e.g. start, commit, rollback * a transaction) * * @param storeDir directory where main data should go after commit * @exception org.jboss.jbossts.fileio.xalib.txdirs.exceptions.NotDirectoryException * if the <code>storeDir</code> is not a directory * @exception org.apache.commons.transaction.file.ResourceManagerException * if an error in the <code>FileResourceManager</code> occurs */ public XADir(File storeDir) throws IOException, ResourceManagerException { if (!storeDir.exists()) { storeDir.mkdir(); } else { if (!storeDir.isDirectory()) throw new NotDirectoryException("The file given is not a directory."); } length = storeDir.list().length; String workDir = storeDir.getCanonicalPath() + "/" + Globals.WORK_DIR_NAME; freMngr = new FileResourceManager(storeDir.getCanonicalPath(), workDir, false, new PrintWriterLogger(new PrintWriter(System.out), XADirFile.class.getName(), false)); freMngr.start(); // start the FileResourceManager service, must be started }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * After a system crash and upon recovery phase the <code>FileResourceManager</code> * object needs to be re-initialised./* w w w . j a v a 2s .c om*/ */ private void initFREM() { String workDir = storeDir + "/" + Globals.WORK_DIR_NAME; freMngr = new FileResourceManager(storeDir, workDir, false, new CommonsLoggingLogger(LogFactory.getLog(XADir.class.getName()))); try { freMngr.start(); // will automatically recover incomplete txs } catch (ResourceManagerSystemException e) { e.printStackTrace(); } }