Return-Path: Delivered-To: apmail-incubator-felix-commits-archive@www.apache.org Received: (qmail 59633 invoked from network); 25 Sep 2006 16:11:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Sep 2006 16:11:32 -0000 Received: (qmail 43177 invoked by uid 500); 25 Sep 2006 16:11:32 -0000 Delivered-To: apmail-incubator-felix-commits-archive@incubator.apache.org Received: (qmail 43121 invoked by uid 500); 25 Sep 2006 16:11:31 -0000 Mailing-List: contact felix-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: felix-dev@incubator.apache.org Delivered-To: mailing list felix-commits@incubator.apache.org Received: (qmail 43105 invoked by uid 99); 25 Sep 2006 16:11:31 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Sep 2006 09:11:31 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=rickhall@apache.org; spf=permerror X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received-SPF: error (idunn.apache.osuosl.org: domain apache.org from 140.211.166.113 cause and error) Received: from [140.211.166.113] ([140.211.166.113:58618] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 7A/7B-13750-2AFF7154 for ; Mon, 25 Sep 2006 09:11:20 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 652A21A981A; Mon, 25 Sep 2006 09:10:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r449715 - in /incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework: BundleInfo.java cache/BundleArchive.java Date: Mon, 25 Sep 2006 16:10:49 -0000 To: felix-commits@incubator.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060925161049.652A21A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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(); + } + } + + /** + *

+ * Returns the last modification time of this archive. + *

+ * @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(); + } + } + + /** + *

+ * Sets the the last modification time of this archive. + *

+ * @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