airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shame...@apache.org
Subject [1/2] airavata git commit: Fixec email monitoring issue
Date Fri, 18 Sep 2015 14:18:38 GMT
Repository: airavata
Updated Branches:
  refs/heads/master ea0fb5229 -> 8139a8d8d


Fixec email monitoring issue


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/af8a84c4
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/af8a84c4
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/af8a84c4

Branch: refs/heads/master
Commit: af8a84c49b768ee93a8ad20aade8625c1ef6e999
Parents: e2132b6
Author: Shameera Rathanyaka <shameerainfo@gmail.com>
Authored: Fri Sep 18 10:15:40 2015 -0400
Committer: Shameera Rathanyaka <shameerainfo@gmail.com>
Committed: Fri Sep 18 10:15:40 2015 -0400

----------------------------------------------------------------------
 .../gfac/monitor/email/EmailBasedMonitor.java   | 96 +++++++++++---------
 1 file changed, 52 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/af8a84c4/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/EmailBasedMonitor.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/EmailBasedMonitor.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/EmailBasedMonitor.java
index dd15cfa..3f5718e 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/EmailBasedMonitor.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/EmailBasedMonitor.java
@@ -153,50 +153,58 @@ public class EmailBasedMonitor implements JobMonitor, Runnable{
 
     @Override
     public void run() {
-        try {
-            session = Session.getDefaultInstance(properties);
-            store = session.getStore(storeProtocol);
-            store.connect(host, emailAddress, password);
-            emailFolder = store.getFolder(folderName);
-            // first time we search for all unread messages.
-            SearchTerm unseenBefore = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
-            while (!(stopMonitoring || ServerSettings.isStopAllThreads())) {
-                Thread.sleep(ServerSettings.getEmailMonitorPeriod());// sleep a bit - get
a rest till job finishes
-                if (jobMonitorMap.isEmpty()) {
-                    log.info("[EJM]: Job Monitor Map is empty, no need to retrieve emails");
-                    continue;
-                } else {
-                    log.info("[EJM]: " + jobMonitorMap.size() + " job/s in job monitor map");
-                }
-                if (!store.isConnected()) {
-                    store.connect();
-                    emailFolder = store.getFolder(folderName);
-                }
-                log.info("[EJM]: Retrieving unseen emails");
-                emailFolder.open(Folder.READ_WRITE);
-                Message[] searchMessages = emailFolder.search(unseenBefore);
-                if (searchMessages == null || searchMessages.length == 0) {
-                    log.info("[EJM]: No new email messages");
-                } else {
-                    log.info("[EJM]: "+searchMessages.length + " new email/s received");
-                }
-                processMessages(searchMessages);
-                emailFolder.close(false);
-            }
-        } catch (MessagingException e) {
-            log.error("[EJM]: Couldn't connect to the store ", e);
-        } catch (InterruptedException e) {
-            log.error("[EJM]: Interrupt exception while sleep ", e);
-        } catch (AiravataException e) {
-            log.error("[EJM]: UnHandled arguments ", e);
-        } finally {
-            try {
-                emailFolder.close(false);
-                store.close();
-            } catch (MessagingException e) {
-                log.error("[EJM]: Store close operation failed, couldn't close store", e);
-            }
-        }
+
+	    while (!stopMonitoring && !ServerSettings.isStopAllThreads()) {
+		    try {
+			    session = Session.getDefaultInstance(properties);
+			    store = session.getStore(storeProtocol);
+			    store.connect(host, emailAddress, password);
+			    emailFolder = store.getFolder(folderName);
+			    // first time we search for all unread messages.
+			    SearchTerm unseenBefore = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
+			    while (!(stopMonitoring || ServerSettings.isStopAllThreads())) {
+				    Thread.sleep(ServerSettings.getEmailMonitorPeriod());// sleep a bit - get a rest
till job finishes
+				    if (jobMonitorMap.isEmpty()) {
+					    log.info("[EJM]: Job Monitor Map is empty, no need to retrieve emails");
+					    continue;
+				    } else {
+					    log.info("[EJM]: " + jobMonitorMap.size() + " job/s in job monitor map");
+				    }
+				    if (!store.isConnected()) {
+					    store.connect();
+					    emailFolder = store.getFolder(folderName);
+				    }
+				    log.info("[EJM]: Retrieving unseen emails");
+				    emailFolder.open(Folder.READ_WRITE);
+				    Message[] searchMessages = emailFolder.search(unseenBefore);
+				    if (searchMessages == null || searchMessages.length == 0) {
+					    log.info("[EJM]: No new email messages");
+				    } else {
+					    log.info("[EJM]: " + searchMessages.length + " new email/s received");
+				    }
+				    processMessages(searchMessages);
+				    emailFolder.close(false);
+			    }
+		    } catch (MessagingException e) {
+			    log.error("[EJM]: Couldn't connect to the store ", e);
+		    } catch (InterruptedException e) {
+			    log.error("[EJM]: Interrupt exception while sleep ", e);
+		    } catch (AiravataException e) {
+			    log.error("[EJM]: UnHandled arguments ", e);
+		    } catch (Throwable e)  {
+			    log.error("[EJM]: Caught a throwable ", e);
+		    } finally {
+			    try {
+				    emailFolder.close(false);
+				    store.close();
+			    } catch (MessagingException e) {
+				    log.error("[EJM]: Store close operation failed, couldn't close store", e);
+			    } catch (Throwable e) {
+				    log.error("[EJM]: Caught a throwable while closing email store ", e);
+			    }
+		    }
+	    }
+	    log.info("[EJM]: Email monitoring daemon stopped");
     }
 
     private void processMessages(Message[] searchMessages) throws MessagingException {


Mime
View raw message