You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/09/25 18:10:49 UTC
svn commit: r449715 - in
/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework:
BundleInfo.java cache/BundleArchive.java
Author: rickhall
Date: Mon Sep 25 09:10:48 2006
New Revision: 449715
URL: http://svn.apache.org/viewvc?view=rev&rev=449715
Log:
Applied patch (FELIX-31) to implement Bundle.getLastModified() in a persistent
way; the previous implementation was not persistent.
Modified:
incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleInfo.java
incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleInfo.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleInfo.java?view=diff&rev=449715&r1=449714&r2=449715
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleInfo.java (original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleInfo.java Mon Sep 25 09:10:48 2006
@@ -31,7 +31,6 @@
private BundleArchive m_archive = null;
private IModule[] m_modules = null;
private int m_state = 0;
- private long m_modified = 0;
private BundleActivator m_activator = null;
private BundleContext m_context = null;
// Indicates whether the bundle is stale, meaning that it has
@@ -215,12 +214,33 @@
public long getLastModified()
{
- return m_modified;
+ try
+ {
+ return m_archive.getLastModified();
+ }
+ catch (Exception ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ "Error reading last modification time from bundle archive.",
+ ex);
+ return 0;
+ }
}
public void setLastModified(long l)
{
- m_modified = l;
+ try
+ {
+ m_archive.setLastModified(l);
+ }
+ catch (Exception ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ "Error writing last modification time to bundle archive.",
+ ex);
+ }
}
public int getPersistentState()
Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?view=diff&rev=449715&r1=449714&r2=449715
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java (original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java Mon Sep 25 09:10:48 2006
@@ -78,6 +78,7 @@
private static final transient String BUNDLE_START_LEVEL_FILE = "bundle.startlevel";
private static final transient String REFRESH_COUNTER_FILE = "refresh.counter";
private static final transient String BUNDLE_ACTIVATOR_FILE = "bundle.activator";
+ private static final transient String BUNDLE_LASTMODIFIED_FILE = "bundle.lastmodified";
private static final transient String REVISION_DIRECTORY = "version";
private static final transient String DATA_DIRECTORY = "data";
private static final transient String ACTIVE_STATE = "active";
@@ -91,6 +92,7 @@
private String m_currentLocation = null;
private int m_persistentState = -1;
private int m_startLevel = -1;
+ private long m_lastModified = -1;
private BundleRevision[] m_revisions = null;
private Collection m_trustedCaCerts = null;
@@ -465,6 +467,85 @@
m_logger.log(
Logger.LOG_ERROR,
getClass().getName() + ": Unable to record start level - " + ex);
+ throw ex;
+ }
+ finally
+ {
+ if (bw != null) bw.close();
+ if (os != null) os.close();
+ }
+ }
+
+ /**
+ * <p>
+ * Returns the last modification time of this archive.
+ * </p>
+ * @return the last modification time of this archive.
+ * @throws Exception if any error occurs.
+ **/
+ public synchronized long getLastModified() throws Exception
+ {
+ if (m_lastModified >= 0)
+ {
+ return m_lastModified;
+ }
+
+ // Get bundle last modification time file.
+ File lastModFile = new File(m_archiveRootDir, BUNDLE_LASTMODIFIED_FILE);
+
+ // If the last modification file doesn't exist, then
+ // return an error.
+ if (!BundleCache.getSecureAction().fileExists(lastModFile))
+ {
+ return 0;
+ }
+
+ // Read the bundle start level.
+ InputStream is = null;
+ BufferedReader br= null;
+ try
+ {
+ is = BundleCache.getSecureAction().getFileInputStream(lastModFile);
+ br = new BufferedReader(new InputStreamReader(is));
+ m_lastModified = Long.parseLong(br.readLine());
+ return m_lastModified;
+ }
+ finally
+ {
+ if (br != null) br.close();
+ if (is != null) is.close();
+ }
+ }
+
+ /**
+ * <p>
+ * Sets the the last modification time of this archive.
+ * </p>
+ * @param lastModified The time of the last modification to set for
+ * this archive. According to the OSGi specification this time is
+ * set each time a bundle is installed, updated or uninstalled.
+ *
+ * @throws Exception if any error occurs.
+ **/
+ public synchronized void setLastModified(long lastModified) throws Exception
+ {
+ // Write the bundle last modification time.
+ OutputStream os = null;
+ BufferedWriter bw = null;
+ try
+ {
+ os = BundleCache.getSecureAction()
+ .getFileOutputStream(new File(m_archiveRootDir, BUNDLE_LASTMODIFIED_FILE));
+ bw = new BufferedWriter(new OutputStreamWriter(os));
+ String s = Long.toString(lastModified);
+ bw.write(s, 0, s.length());
+ m_lastModified = lastModified;
+ }
+ catch (IOException ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ getClass().getName() + ": Unable to record last modification time - " + ex);
throw ex;
}
finally