[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rhq-commits
Subject:    [rhq] Branch 'release/jon3.0.x' - modules/core
From:       jshaughn () fedoraproject ! org (Jay Shaughnessy)
Date:       2012-01-31 20:20:32
Message-ID: 20120131202032.4CD8B6437 () lists ! fedorahosted ! org
[Download RAW message or body]

 modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java \
|   60 +++++-----  1 file changed, 35 insertions(+), 25 deletions(-)

New commits:
commit d44638c22a94b4997fd3a5af9f27b642bed97ef0
Author: Jay Shaughnessy <jshaughn at redhat.com>
Date:   Tue Jan 31 15:20:14 2012 -0500

    [Bug 773435 - Enabled event sources cause initial resource component start to \
time out]  lazily access sigar on the first polling, which happens after container
    initialization.
    
    Conflicts:
    
    	modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java


diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java \
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
 index bcc42de..30cd3e5 100644
--- a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
                
+++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
 @@ -46,28 +46,21 @@ import org.rhq.core.pluginapi.event.EventPoller;
  *
  * @author Ian Springer
  */
-public class LogFileEventPoller implements EventPoller {    
+public class LogFileEventPoller implements EventPoller {
     private final Log log = LogFactory.getLog(this.getClass());
 
     private String eventType;
     private File logFile;
     private FileInfo logFileInfo;
     private LogEntryProcessor entryProcessor;
+    private EventContext eventContext;
 
-    public LogFileEventPoller(EventContext eventContext, String eventType, File \
                logFile, LogEntryProcessor entryProcessor) {
-        SigarProxy sigar = eventContext.getSigar();
+    public LogFileEventPoller(EventContext eventContext, String eventType, File \
logFile, +        LogEntryProcessor entryProcessor) {
         this.eventType = eventType;
         this.logFile = logFile;
-        if (sigar != null) {
-            try {
-                this.logFileInfo = new \
                LogFileInfo(sigar.getFileInfo(logFile.getPath()));
-            } catch (SigarException e) {
-                throw new RuntimeException("Failed to obtain file info for log file \
                [" + this.logFile + "].", e);
-            }
-        } else {
-            log.warn("SIGAR is unavailable - cannot poll log file [" + this.logFile \
                + "] for events.");
-        }
         this.entryProcessor = entryProcessor;
+        this.eventContext = eventContext;
     }
 
     @NotNull
@@ -80,11 +73,26 @@ public class LogFileEventPoller implements EventPoller {
         return this.logFile.getPath();
     }
 
+    // we can't get the FileInfo in the constructor because pollers are constructed \
during pc initialization, and +    // at that time the eventManager is not available \
(and so we can't get sigar).  +    private FileInfo getFileInfo() {
+        if (null == this.logFileInfo) {
+            try {
+                SigarProxy sigar = eventContext.getSigar();
+                this.logFileInfo = new \
LogFileInfo(sigar.getFileInfo(logFile.getPath())); +                // once we have \
the file info we can let go of the event context, just in case that's useful +        \
this.eventContext = null; +
+            } catch (SigarException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return this.logFileInfo;
+    }
+
     @Nullable
     public Set<Event> poll() {
-        if (this.logFileInfo == null) {
-            return null;
-        }
         if (!this.logFile.exists()) {
             log.warn("Log file [" + this.logFile + "] being polled does not \
exist.");  return null;
@@ -93,23 +101,25 @@ public class LogFileEventPoller implements EventPoller {
             log.error("Log file [" + this.logFile + "] being polled is a directory, \
not a regular file.");  return null;
         }
+        FileInfo fileInfo;
         try {
-            if (!this.logFileInfo.changed()) {
+            fileInfo = getFileInfo();
+            if (!fileInfo.changed()) {
                 return null;
             }
         } catch (SigarException e) {
             throw new RuntimeException(e);
         }
-        return processNewLines();
+        return processNewLines(fileInfo);
     }
 
-    private Set<Event> processNewLines() {
+    private Set<Event> processNewLines(FileInfo fileInfo) {
         Set<Event> events = null;
         Reader reader = null;
         try {
             reader = new FileReader(this.logFile);
 
-            long offset = getOffset();
+            long offset = getOffset(fileInfo);
 
             if (offset > 0) {
                 reader.skip(offset);
@@ -130,24 +140,24 @@ public class LogFileEventPoller implements EventPoller {
         return events;
     }
 
-    private long getOffset() {
-        FileInfo previousFileInfo = this.logFileInfo.getPreviousInfo();
+    private long getOffset(FileInfo fileInfo) {
+        FileInfo previousFileInfo = fileInfo.getPreviousInfo();
 
         if (previousFileInfo == null) {
             if (log.isDebugEnabled()) {
                 log.debug(this.logFile + ": first stat");
             }
-            return this.logFileInfo.getSize();
+            return fileInfo.getSize();
         }
 
-        if (this.logFileInfo.getInode() != previousFileInfo.getInode()) {
+        if (fileInfo.getInode() != previousFileInfo.getInode()) {
             if (log.isDebugEnabled()) {
                 log.debug(this.logFile + ": file inode changed");
             }
             return -1;
         }
 
-        if (this.logFileInfo.getSize() < previousFileInfo.getSize()) {
+        if (fileInfo.getSize() < previousFileInfo.getSize()) {
             if (log.isDebugEnabled()) {
                 log.debug(this.logFile + ": file truncated");
             }
@@ -155,7 +165,7 @@ public class LogFileEventPoller implements EventPoller {
         }
 
         if (log.isDebugEnabled()) {
-            long diff = this.logFileInfo.getSize() - previousFileInfo.getSize();
+            long diff = fileInfo.getSize() - previousFileInfo.getSize();
             log.debug(this.logFile + ": " + diff + " new bytes");
         }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic