[Openbus-cvs-commits] Openbus/OpenbusJBI/src/java/org/openbus/jbi/framework/impl FileSystemRepositor
Status: Alpha
Brought to you by:
esancho
|
From: Esteban S. <es...@us...> - 2005-06-28 03:02:41
|
Update of /cvsroot/openbus/Openbus/OpenbusJBI/src/java/org/openbus/jbi/framework/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12959/src/java/org/openbus/jbi/framework/impl Modified Files: FileSystemRepositoryImpl.java HashmapJBIRegistryImpl.java Removed Files: RepositoryConfig.java Log Message: Removing transactional logic from repository and registry. Refactoring to regular filesystems and HashMaps. --- RepositoryConfig.java DELETED --- Index: HashmapJBIRegistryImpl.java =================================================================== RCS file: /cvsroot/openbus/Openbus/OpenbusJBI/src/java/org/openbus/jbi/framework/impl/HashmapJBIRegistryImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HashmapJBIRegistryImpl.java 9 Jun 2005 00:42:57 -0000 1.1 --- HashmapJBIRegistryImpl.java 28 Jun 2005 03:02:32 -0000 1.2 *************** *** 24,36 **** import java.util.Iterator; - import javax.transaction.xa.XAResource; - import org.apache.commons.collections.collection.UnmodifiableCollection; import org.apache.commons.lang.SerializationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.commons.transaction.memory.OptimisticMapWrapper; - import org.apache.commons.transaction.memory.TransactionalMapWrapper; - import org.apache.commons.transaction.memory.jca.MapXAResource; import org.openbus.jbi.framework.Component; import org.openbus.jbi.framework.FrameworkException; --- 24,31 ---- *************** *** 49,63 **** .getLog(HashmapJBIRegistryImpl.class); - // Map wrappers providing transactionality - private transient TransactionalMapWrapper sharedLibraries = null; - private transient TransactionalMapWrapper components = null; - // Backend maps to be serialized ! private HashMap sharedLibrariesBackend; ! private HashMap componentsBackend; ! ! // XAResources ! private transient XAResource librariesResource; ! private transient XAResource componentsResource; // To allow version changes on this class --- 44,50 ---- .getLog(HashmapJBIRegistryImpl.class); // Backend maps to be serialized ! private HashMap sharedLibraries; ! private HashMap components; // To allow version changes on this class *************** *** 65,79 **** public HashmapJBIRegistryImpl() { ! sharedLibrariesBackend = new HashMap(); ! componentsBackend = new HashMap(); ! initializeMaps(); ! } ! ! private void initializeMaps() { ! // @todo change logger ! sharedLibraries = new OptimisticMapWrapper(sharedLibrariesBackend); ! components = new OptimisticMapWrapper(componentsBackend); ! librariesResource = new MapXAResource(sharedLibraries); ! componentsResource = new MapXAResource(components); } --- 52,57 ---- public HashmapJBIRegistryImpl() { ! sharedLibraries = new HashMap(); ! components = new HashMap(); } *************** *** 85,89 **** ClassNotFoundException { in.defaultReadObject(); - initializeMaps(); } --- 63,66 ---- *************** *** 283,292 **** } - public XAResource[] getXAResources() { - XAResource[] resources = new XAResource[2]; - resources[0] = librariesResource; - resources[1] = componentsResource; - return resources; - } - } \ No newline at end of file --- 260,262 ---- Index: FileSystemRepositoryImpl.java =================================================================== RCS file: /cvsroot/openbus/Openbus/OpenbusJBI/src/java/org/openbus/jbi/framework/impl/FileSystemRepositoryImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileSystemRepositoryImpl.java 16 Jun 2005 03:35:38 -0000 1.2 --- FileSystemRepositoryImpl.java 28 Jun 2005 03:02:32 -0000 1.3 *************** *** 17,31 **** import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; ! import javax.transaction.xa.XAResource; ! import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; ! import org.openbus.commons.transaction.TransactionalException; ! import org.openbus.commons.transaction.impl.TransactionalFileSystemImpl; ! import org.openbus.commons.transaction.impl.ZipUtils; import org.openbus.jbi.framework.Component; import org.openbus.jbi.framework.FrameworkException; --- 17,30 ---- import java.io.File; + import java.io.FileInputStream; + import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; ! import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; ! import org.openbus.commons.util.ZipUtils; import org.openbus.jbi.framework.Component; import org.openbus.jbi.framework.FrameworkException; *************** *** 44,55 **** private static final String SHARED_LIBRARIES_PATH = "shared"; private static final String TEMP_DIR_PATH = "temp"; ! private static final String REGISTRY_FILE_NAME = "jbi-registry.bin"; // internal data private static Log log = LogFactory.getLog(FileSystemRepositoryImpl.class); private File installRoot; - private TransactionalFileSystemImpl repoFS; - private TransactionalFileSystemImpl libFS; - private TransactionalFileSystemImpl compFS; public FileSystemRepositoryImpl(String installRoot_) --- 43,51 ---- private static final String SHARED_LIBRARIES_PATH = "shared"; private static final String TEMP_DIR_PATH = "temp"; ! private static final String REGISTRY_FILE_NAME = "jbi-registry.dat"; // internal data private static Log log = LogFactory.getLog(FileSystemRepositoryImpl.class); private File installRoot; public FileSystemRepositoryImpl(String installRoot_) *************** *** 64,127 **** throw new FrameworkException("Install root doesn't exist"); } - try { - // initialize repo filesystem - String repoStoreDir = getRepositoryPath(); - String repoWorkingDir = installRoot_ + File.separator - + TEMP_DIR_PATH + File.separator + REPOSITORY_PATH; - //create dirs if they don't exist - new File(repoStoreDir).mkdirs(); - new File(repoWorkingDir).mkdirs(); - // create transactional file system - repoFS = new TransactionalFileSystemImpl(repoStoreDir, - repoWorkingDir); - - // initialize libraries filesystem - String libStoreDir = getLibrariesPath(); - String libWorkingDir = installRoot_ + File.separator - + TEMP_DIR_PATH + File.separator + SHARED_LIBRARIES_PATH; - //create dirs if they don't exist - new File(libStoreDir).mkdirs(); - new File(libWorkingDir).mkdirs(); - // create transactional file system - libFS = new TransactionalFileSystemImpl(libStoreDir, libWorkingDir); - - // initialize components filesystem - String compStoreDir = getComponentsPath(); - String compWorkingDir = installRoot_ + File.separator - + TEMP_DIR_PATH + File.separator + COMPONENTS_PATH; - //create dirs if they don't exist - new File(compStoreDir).mkdirs(); - new File(compWorkingDir).mkdirs(); - // create transactional file system - compFS = new TransactionalFileSystemImpl(compStoreDir, - compWorkingDir); - } catch (TransactionalException e) { - // @todo i18n - throw new FrameworkException("Error in constructor", e); - } - } - - public void init() throws FrameworkException { - try { - // @todo more elegant solution - repoFS.start(); - libFS.start(); - compFS.start(); - } catch (TransactionalException e) { - // @todo i18n - throw new FrameworkException("Error initializing repository", e); - } - } - - public void shutdown() throws FrameworkException { - try { - // @todo more elegant solution - repoFS.stop(); - libFS.stop(); - compFS.stop(); - } catch (TransactionalException e) { - // @todo i18n - throw new FrameworkException("Error shutting repository down", e); - } } --- 60,63 ---- *************** *** 130,133 **** --- 66,73 ---- } + public String getRegistryPath() { + return getRepositoryPath() + File.separator + REGISTRY_FILE_NAME; + } + public String getLibrariesPath() { return installRoot.getAbsolutePath() + File.separator *************** *** 142,147 **** throws FrameworkException { try { ! ObjectOutputStream os = new ObjectOutputStream(repoFS ! .writeFile(REGISTRY_FILE_NAME)); os.writeObject(registry_); os.close(); --- 82,91 ---- throws FrameworkException { try { ! File regFile = new File(getRegistryPath()); ! if (!regFile.getParentFile().exists()) { ! FileUtils.forceMkdir(regFile.getParentFile()); ! } ! ObjectOutputStream os = new ObjectOutputStream( ! new FileOutputStream(regFile)); os.writeObject(registry_); os.close(); *************** *** 149,157 **** // @todo i18n throw new FrameworkException("Couldn't store the registry", ioe); - } catch (TransactionalException te) { - // @todo i18n - throw new FrameworkException("Couldn't store the registry", te); } ! return getRepositoryPath() + File.separator + REGISTRY_FILE_NAME; } --- 93,98 ---- // @todo i18n throw new FrameworkException("Couldn't store the registry", ioe); } ! return getRegistryPath(); } *************** *** 162,167 **** registry = createNewRegistry(); } else { ! ObjectInputStream is = new ObjectInputStream(repoFS ! .readFile(REGISTRY_FILE_NAME)); registry = (JBIRegistry) is.readObject(); is.close(); --- 103,108 ---- registry = createNewRegistry(); } else { ! ObjectInputStream is = new ObjectInputStream( ! new FileInputStream(getRegistryPath())); registry = (JBIRegistry) is.readObject(); is.close(); *************** *** 173,179 **** // @todo i18n throw new FrameworkException("Couldn't load the registry", cnfe); - } catch (TransactionalException te) { - // @todo i18n - throw new FrameworkException("Couldn't store the registry", te); } return registry; --- 114,117 ---- *************** *** 182,203 **** public void removeRegistry() throws FrameworkException { try { ! repoFS.deleteFile(REGISTRY_FILE_NAME); ! } catch (TransactionalException te) { // @todo i18n throw new FrameworkException("Couldn't remove registry file " ! + REGISTRY_FILE_NAME, te); } } public boolean isRegistryCreated() throws FrameworkException { ! boolean exists = false; ! try { ! exists = repoFS.fileExists(REGISTRY_FILE_NAME); ! } catch (TransactionalException e) { ! // @todo i18n ! throw new FrameworkException("Unable to check registry existence", ! e); ! } ! return exists; } --- 120,133 ---- public void removeRegistry() throws FrameworkException { try { ! FileUtils.forceDelete(new File(getRegistryPath())); ! } catch (IOException ioe) { // @todo i18n throw new FrameworkException("Couldn't remove registry file " ! + getRegistryPath(), ioe); } } public boolean isRegistryCreated() throws FrameworkException { ! return new File(getRegistryPath()).exists(); } *************** *** 219,238 **** throw new FrameworkException("Component is already installed"); } try { ! ZipUtils.inflate(component_.getUniqueName(), zipFile_, compFS); ! } catch (TransactionalException e) { // @todo i18n ! throw new FrameworkException("Unable to store component", e); } ! return getComponentsPath() + File.separator ! + component_.getUniqueName(); } public void removeComponent(Component component_) throws FrameworkException { try { ! compFS.deleteDirectory(component_.getUniqueName()); ! } catch (TransactionalException e) { // @todo i18n ! throw new FrameworkException("Unable to remove component", e); } } --- 149,171 ---- throw new FrameworkException("Component is already installed"); } + File componentDir = new File(getComponentsPath(), component_ + .getUniqueName()); try { ! ZipUtils.inflate(zipFile_, componentDir); ! } catch (IOException ioe) { // @todo i18n ! throw new FrameworkException("Unable to store component", ioe); } ! return componentDir.getAbsolutePath(); } public void removeComponent(Component component_) throws FrameworkException { try { ! File componentDir = new File(getComponentsPath(), component_ ! .getUniqueName()); ! FileUtils.deleteDirectory(componentDir); ! } catch (IOException ioe) { // @todo i18n ! throw new FrameworkException("Unable to remove component", ioe); } } *************** *** 240,253 **** public boolean isComponentStored(Component component_) throws FrameworkException { ! boolean exists = false; ! try { ! exists = compFS.fileExists(component_.getUniqueName()); ! } catch (TransactionalException e) { ! // @todo i18n ! throw new FrameworkException( ! "Unable to check component existence: " ! + component_.getUniqueName(), e); ! } ! return exists; } --- 173,179 ---- public boolean isComponentStored(Component component_) throws FrameworkException { ! File componentDir = new File(getComponentsPath(), component_ ! .getUniqueName()); ! return componentDir.exists(); } *************** *** 260,271 **** } String libraryPath = getLibraryPath(library_); try { ! ZipUtils.inflate(libraryPath, zipFile_, libFS); ! } catch (TransactionalException e) { // @todo i18n throw new FrameworkException("Unable to store library " ! + library_.getUniqueName(), e); } ! return getLibrariesPath() + File.separator + libraryPath; } --- 186,199 ---- } String libraryPath = getLibraryPath(library_); + File libraryDir = new File(getLibrariesPath(), getLibraryPath(library_)); try { ! FileUtils.forceMkdir(libraryDir); ! ZipUtils.inflate(zipFile_, libraryDir); ! } catch (IOException ioe) { // @todo i18n throw new FrameworkException("Unable to store library " ! + library_.getUniqueName(), ioe); } ! return libraryDir.getAbsolutePath(); } *************** *** 273,280 **** throws FrameworkException { try { ! compFS.deleteDirectory(getLibraryPath(library_)); ! } catch (TransactionalException e) { // @todo i18n ! throw new FrameworkException("Unable to remove component", e); } } --- 201,213 ---- throws FrameworkException { try { ! File libraryDir = new File(getLibrariesPath(), getLibraryPath(library_)); ! File parentDir = libraryDir.getParentFile(); ! FileUtils.deleteDirectory(libraryDir); ! if (parentDir.list().length <= 0) { ! FileUtils.deleteDirectory(parentDir); ! } ! } catch (IOException ioe) { // @todo i18n ! throw new FrameworkException("Unable to remove shared library", ioe); } } *************** *** 282,297 **** public boolean isSharedLibraryStored(SharedLibrary library_) throws FrameworkException { ! boolean exists = false; ! try { ! exists = compFS.fileExists(getLibraryPath(library_)); ! } catch (TransactionalException e) { ! // @todo i18n ! throw new FrameworkException("Unable to check library existence: " ! + library_.getUniqueName(), e); ! } ! return exists; } ! protected String getLibraryPath(SharedLibrary library_) { String version = library_.getVersion(); if (version == null) { --- 215,224 ---- public boolean isSharedLibraryStored(SharedLibrary library_) throws FrameworkException { ! File libraryDir = new File(getLibrariesPath(), getLibraryPath(library_)); ! ! return libraryDir.exists(); } ! public String getLibraryPath(SharedLibrary library_) { String version = library_.getVersion(); if (version == null) { *************** *** 301,311 **** } - public XAResource[] getXAResources() throws TransactionalException { - XAResource[] resources = new XAResource[3]; - resources[0] = repoFS.getXAResource(); - resources[1] = libFS.getXAResource(); - resources[2] = compFS.getXAResource(); - return resources; - } - } \ No newline at end of file --- 228,230 ---- |