Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 87772 Details for
Bug 214816
[prov] Local caching of remote metadata repositories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Metadata Caching v01
patch-metadataCaching_v02.txt (text/plain), 11.53 KB, created by
Tim Mok
on 2008-01-24 10:02:09 EST
(
hide
)
Description:
Metadata Caching v01
Filename:
MIME Type:
Creator:
Tim Mok
Created:
2008-01-24 10:02:09 EST
Size:
11.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.metadata.repository >Index: src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java,v >retrieving revision 1.2 >diff -u -r1.2 ECFMetadataTransport.java >--- src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java 23 Jan 2008 02:17:58 -0000 1.2 >+++ src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java 24 Jan 2008 14:39:40 -0000 >@@ -12,7 +12,9 @@ > > import java.io.IOException; > import java.io.OutputStream; >+import java.util.Date; > import org.eclipse.core.runtime.*; >+import org.eclipse.ecf.core.*; > import org.eclipse.ecf.filetransfer.*; > import org.eclipse.ecf.filetransfer.events.*; > import org.eclipse.ecf.filetransfer.identity.FileCreateException; >@@ -50,6 +52,66 @@ > return transfer(factory.newInstance(), toDownload, target, monitor); > } > >+ /** >+ * Gets the last modified date for the specified file. >+ * @param location - The URL location of the file. >+ * @return The <code>Date</code> of the file's last modified date, <code>null</code> if operation was not successful. >+ */ >+ public Date getLastModified(String location) { >+ IContainer container; >+ try { >+ container = ContainerFactory.getDefault().createContainer(); >+ } catch (ContainerCreateException e) { >+ return null; >+ } >+ IRemoteFileSystemBrowserContainerAdapter adapter = (IRemoteFileSystemBrowserContainerAdapter) container.getAdapter(IRemoteFileSystemBrowserContainerAdapter.class); >+ if (adapter == null) { >+ return null; >+ } >+ IRemoteFile remoteFile = checkFile(adapter, location); >+ if (remoteFile == null) { >+ return null; >+ } >+ return new Date(remoteFile.getInfo().getLastModified()); >+ } >+ >+ private IRemoteFile checkFile(final IRemoteFileSystemBrowserContainerAdapter retrievalContainer, final String location) { >+ final Object[] result = new Object[1]; >+ IRemoteFileSystemListener listener = new IRemoteFileSystemListener() { >+ public void handleRemoteFileEvent(IRemoteFileSystemEvent event) { >+ if (event instanceof IRemoteFileSystemBrowseEvent) { >+ IRemoteFileSystemBrowseEvent fsbe = (IRemoteFileSystemBrowseEvent) event; >+ IRemoteFile[] remoteFiles = fsbe.getRemoteFiles(); >+ if (remoteFiles != null && remoteFiles.length > 0) { >+ synchronized (result) { >+ result[0] = remoteFiles[0]; >+ result.notify(); >+ } >+ } >+ } >+ } >+ }; >+ try { >+ retrievalContainer.sendBrowseRequest(FileIDFactory.getDefault().createFileID(retrievalContainer.getBrowseNamespace(), location), listener); >+ } catch (RemoteFileSystemException e) { >+ return null; >+ } catch (FileCreateException e) { >+ return null; >+ } >+ synchronized (result) { >+ while (result[0] == null) { >+ boolean logged = false; >+ try { >+ result.wait(); >+ } catch (InterruptedException e) { >+ if (!logged) >+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Unexpected interrupt while waiting on ECF browse", e)); //$NON-NLS-1$ >+ } >+ } >+ } >+ return (IRemoteFile) result[0]; >+ } >+ > private IStatus transfer(final IRetrieveFileTransferContainerAdapter retrievalContainer, final String toDownload, final OutputStream target, final IProgressMonitor monitor) { > final IStatus[] result = new IStatus[1]; > IFileTransferListener listener = new IFileTransferListener() { >Index: src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java,v >retrieving revision 1.18 >diff -u -r1.18 SimpleMetadataRepositoryFactory.java >--- src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java 23 Jan 2008 02:18:35 -0000 1.18 >+++ src/org/eclipse/equinox/internal/p2/metadata/repository/SimpleMetadataRepositoryFactory.java 24 Jan 2008 14:39:40 -0000 >@@ -12,12 +12,13 @@ > > import java.io.*; > import java.net.URL; >+import java.util.Date; > import java.util.jar.JarEntry; > import java.util.jar.JarInputStream; > import org.eclipse.core.runtime.*; >-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; >-import org.eclipse.equinox.internal.p2.core.helpers.Tracing; >+import org.eclipse.equinox.internal.p2.core.helpers.*; > import org.eclipse.equinox.p2.core.ProvisionException; >+import org.eclipse.equinox.p2.core.location.AgentLocation; > import org.eclipse.equinox.p2.metadata.repository.IMetadataRepository; > import org.eclipse.equinox.spi.p2.metadata.repository.IMetadataRepositoryFactory; > >@@ -34,75 +35,108 @@ > } > > public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { >+ final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ > long time = 0; > boolean compress = true; >+ boolean local = false; > final String debugMsg = "Restoring metadata repository "; //$NON-NLS-1$ >- File temp = null; >+ AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); >+ Date timestamp, cacheTimestamp; >+ URL actualFile, dataArea; >+ File cacheFile = null; > if (Tracing.DEBUG_METADATA_PARSING) { > Tracing.debug(debugMsg + location); > time = -System.currentTimeMillis(); > } > try { >- temp = File.createTempFile(CONTENT_FILENAME, JAR_EXTENSION); >+ IStatus status = Status.OK_STATUS; >+ OutputStream metadata = null; > SubMonitor sub = SubMonitor.convert(monitor, 300); >- OutputStream metadata = new BufferedOutputStream(new FileOutputStream(temp)); >- IStatus status = getTransport().download(URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).toExternalForm(), metadata, sub); >- URL actualFile = URLMetadataRepository.getActualLocation(location); >- if (!status.isOK()) { >- // retry uncompressed >- metadata.close(); >- if (!temp.delete()) { >- temp.deleteOnExit(); >- } >- temp = File.createTempFile(CONTENT_FILENAME, XML_EXTENSION); >- metadata = new BufferedOutputStream(new FileOutputStream(temp)); >- compress = false; >- status = getTransport().download(URLMetadataRepository.getActualLocation(location, XML_EXTENSION).toExternalForm(), metadata, sub); >- if (!status.isOK()) >- return null; >- } >- if (metadata != null) { >- metadata.close(); >+ String fileLocation = URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).toExternalForm(); >+ int hashCode = location.hashCode(); >+ timestamp = getTransport().getLastModified(fileLocation); >+ cacheTimestamp = null; >+ actualFile = URLMetadataRepository.getActualLocation(location); >+ // check if the file is from a local repo >+ if (PROTOCOL_FILE.equals(actualFile.getProtocol())) { >+ local = true; >+ cacheFile = new File(URLMetadataRepository.getActualLocation(location, JAR_EXTENSION).getPath()); >+ if (!cacheFile.exists()) { >+ cacheFile = new File(actualFile.getPath()); >+ compress = false; >+ } > } >- InputStream inStream = new BufferedInputStream(new FileInputStream(temp)); >- if (compress) { >- JarInputStream jInStream = new JarInputStream(inStream); >- JarEntry jarEntry = jInStream.getNextJarEntry(); >- String entryName = new Path(actualFile.getPath()).lastSegment(); >- while (jarEntry != null && (!entryName.equals(jarEntry.getName()))) { >- jarEntry = jInStream.getNextJarEntry(); >+ if (!local) { >+ dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ >+ String cachePath = dataArea.getPath(); >+ if (timestamp != null) { >+ cacheFile = new File(cachePath + CONTENT_FILENAME + hashCode + JAR_EXTENSION); >+ cacheTimestamp = new Date(cacheFile.lastModified()); >+ } else { >+ fileLocation = URLMetadataRepository.getActualLocation(location, XML_EXTENSION).toExternalForm(); >+ timestamp = getTransport().getLastModified(fileLocation); >+ if (timestamp != null) { >+ compress = false; >+ cacheFile = new File(cachePath, CONTENT_FILENAME + hashCode + XML_EXTENSION); >+ cacheTimestamp = new Date(cacheFile.lastModified()); >+ } else >+ return null; > } >- if (jarEntry == null) { >- throw new FileNotFoundException("Repository not found in compressed file."); //$NON-NLS-1$ >+ if (timestamp.after(cacheTimestamp)) { >+ // retrieve the newer index file >+ File parentFile = cacheFile.getParentFile(); >+ if (!parentFile.exists()) { >+ parentFile.mkdirs(); >+ } >+ cacheFile.createNewFile(); >+ metadata = new BufferedOutputStream(new FileOutputStream(cacheFile)); >+ status = getTransport().download(fileLocation, metadata, sub); > } >- inStream = jInStream; > } >- InputStream descriptorStream = new BufferedInputStream(inStream); >- try { >- IMetadataRepository result = new MetadataRepositoryIO().read(temp.toURL(), descriptorStream, sub.newChild(100)); >- if (result instanceof LocalMetadataRepository) >- ((LocalMetadataRepository) result).initializeAfterLoad(location); >- if (result instanceof URLMetadataRepository) >- ((URLMetadataRepository) result).initializeAfterLoad(location); >- if (Tracing.DEBUG_METADATA_PARSING) { >- time += System.currentTimeMillis(); >- Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ >- } >- return result; >- } finally { >- if (descriptorStream != null) >- descriptorStream.close(); >+ if (status.isOK()) { >+ if (metadata != null) { >+ metadata.close(); >+ } >+ InputStream inStream = new BufferedInputStream(new FileInputStream(cacheFile)); >+ if (compress) { >+ JarInputStream jInStream = new JarInputStream(inStream); >+ JarEntry jarEntry = jInStream.getNextJarEntry(); >+ String entryName = new Path(actualFile.getPath()).lastSegment(); >+ while (jarEntry != null && (!entryName.equals(jarEntry.getName()))) { >+ jarEntry = jInStream.getNextJarEntry(); >+ } >+ if (jarEntry == null) { >+ throw new FileNotFoundException("Repository not found in compressed file."); //$NON-NLS-1$ >+ } >+ inStream = jInStream; >+ } >+ InputStream descriptorStream = new BufferedInputStream(inStream); >+ try { >+ IMetadataRepository result = new MetadataRepositoryIO().read(cacheFile.toURL(), descriptorStream, sub.newChild(100)); >+ if (result instanceof LocalMetadataRepository) >+ ((LocalMetadataRepository) result).initializeAfterLoad(location); >+ if (result instanceof URLMetadataRepository) >+ ((URLMetadataRepository) result).initializeAfterLoad(location); >+ if (Tracing.DEBUG_METADATA_PARSING) { >+ time += System.currentTimeMillis(); >+ Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ >+ } >+ return result; >+ } finally { >+ if (descriptorStream != null) >+ descriptorStream.close(); >+ } > } > } catch (FileNotFoundException e) { > //if the repository doesn't exist, then it's fine to return null > } catch (IOException e) { > log(debugMsg, e); >- } finally { >- if (temp != null && !temp.delete()) { >- temp.deleteOnExit(); >- } >+ } >+ if (cacheFile != null) { >+ cacheFile.deleteOnExit(); > } > return null; >+ > } > > private ECFMetadataTransport getTransport() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 214816
:
87517
|
87772
|
88147
|
88162