diff --git a/modules/activiti-engine/src/main/java/org/activiti/engine/impl/mail/MailScanSchedulerThread.java b/modules/activiti-engine/src/main/java/org/activiti/engine/impl/mail/MailScanSchedulerThread.java index 92f87607045559682cac7434ea4d4552b562067c..5f5f5b3e36f0f1eadcb17e0d1e8f3f79672378f5 100644 --- a/modules/activiti-engine/src/main/java/org/activiti/engine/impl/mail/MailScanSchedulerThread.java +++ b/modules/activiti-engine/src/main/java/org/activiti/engine/impl/mail/MailScanSchedulerThread.java @@ -32,7 +32,7 @@ public class MailScanSchedulerThread extends Thread { private static Logger log = Logger.getLogger(MailScanSchedulerThread.class.getName()); protected boolean isActive = false; - protected int idleWaitInMillis = 2000; + protected int idleWaitInMillis = 10000; protected MailScanner mailScanner; protected CommandExecutor commandExecutor; protected Map allMailScansCmds = Collections.synchronizedMap(new HashMap()); @@ -58,15 +58,17 @@ public class MailScanSchedulerThread extends Thread { public void run() { isActive = true; log.fine(getClass().getName()+" is started"); - while (mailScanner.isActive()) { + while (isActive) { MailScanCmd mailScanCmd = getNextMailScanCmd(); - try { - commandExecutor.execute(mailScanCmd); - } catch (Exception e) { - // users need to logout and login if they want to re-enable mail scanning after a failure - String userId = mailScanCmd.getUserId(); - allMailScansCmds.remove(userId); - log.log(Level.SEVERE, "couldn't check todo mail for "+userId+": "+e.getMessage(), e); + if (mailScanCmd != null) { + try { + commandExecutor.execute(mailScanCmd); + } catch (Exception e) { + // users need to logout and login if they want to re-enable mail scanning after a failure + String userId = mailScanCmd.getUserId(); + allMailScansCmds.remove(userId); + log.log(Level.SEVERE, "couldn't check todo mail for "+userId+": "+e.getMessage(), e); + } } } log.fine(getClass().getName()+" is stopping"); @@ -81,6 +83,7 @@ public class MailScanSchedulerThread extends Thread { Thread.sleep(idleWaitInMillis); } catch (InterruptedException e) { log.fine("sleep got interrupted"); + return null; } } if (nextMailScanCmds.isEmpty()) { diff --git a/modules/activiti-webapp-explorer2/src/main/java/demo/DemoMailScanner.java b/modules/activiti-webapp-explorer2/src/main/java/demo/DemoMailScanner.java new file mode 100644 index 0000000000000000000000000000000000000000..c387eca7d45ae8db6c8866b610cf080e5a374520 --- /dev/null +++ b/modules/activiti-webapp-explorer2/src/main/java/demo/DemoMailScanner.java @@ -0,0 +1,50 @@ +/* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package demo; + +import org.activiti.engine.ProcessEngine; +import org.activiti.engine.impl.ProcessEngineImpl; +import org.activiti.engine.impl.mail.MailScanner; +import org.springframework.beans.factory.InitializingBean; + + +/** + * @author Joram Barrez + */ +public class DemoMailScanner implements InitializingBean { + + protected ProcessEngine processEngine; + protected MailScanner mailScanner; + + public void afterPropertiesSet() throws Exception { + mailScanner = ((ProcessEngineImpl) processEngine) + .getProcessEngineConfiguration() + .getMailScanner(); + mailScanner.start(); + mailScanner.addUser("tom", null); + } + + public void shutdown() { + mailScanner.shutdown(); + } + + public ProcessEngine getProcessEngine() { + return processEngine; + } + + public void setProcessEngine(ProcessEngine processEngine) { + this.processEngine = processEngine; + } + +} diff --git a/modules/activiti-webapp-explorer2/src/main/java/org/activiti/explorer/demo/DemoDataGenerator.java b/modules/activiti-webapp-explorer2/src/main/java/org/activiti/explorer/demo/DemoDataGenerator.java index c21e85cb8369e55baeaf9aba67dee1a2a0dbcad5..be2ae1186dab7085a5710f854bfb649ad043ac1b 100644 --- a/modules/activiti-webapp-explorer2/src/main/java/org/activiti/explorer/demo/DemoDataGenerator.java +++ b/modules/activiti-webapp-explorer2/src/main/java/org/activiti/explorer/demo/DemoDataGenerator.java @@ -13,6 +13,8 @@ package org.activiti.explorer.demo; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Logger; import org.activiti.engine.IdentityService; @@ -144,13 +146,26 @@ public class DemoDataGenerator { createUser(identityService, "julie", "Julie", "Hall", "julie", "julie.hall@alfresco.com", "org/activiti/explorer/images/julie.jpg"); createUser(identityService, "erik", "Erik", "Winlof", "erik", "erik.witloof@alfresco.com", "org/activiti/explorer/images/erik.jpg"); - // Additional info + // Joram identityService.setUserInfo("joram", "birthDate", "10-10-1985"); identityService.setUserInfo("joram", "jobTitle", "Activiti core developer"); identityService.setUserInfo("joram", "location", "Welle, Belgium"); identityService.setUserInfo("joram", "phone", "+32485869655"); identityService.setUserInfo("joram", "twitterName", "jbarrez"); identityService.setUserInfo("joram", "skype", "joram.barrez"); + + // Tim + String accountUsername = System.getProperty("user"); + String accountPassword = System.getProperty("pwd"); + if (accountUsername == null || accountPassword == null) { + throw new RuntimeException("'user' and 'pwd' system property must be set"); + } + Map accountDetails = new HashMap(); + accountDetails.put("toDoFolderName", "Cases"); + accountDetails.put("toDoInActivitiFolderName", "CasesInActiviti"); + accountDetails.put("imapHost", "imap.gmail.com"); + accountDetails.put("imapProtocol", "imaps"); + identityService.setUserAccount("tom", null, "mailscan", accountUsername, accountPassword, accountDetails); } protected void createUser(IdentityService identityService, String userId, String firstName, String lastName, diff --git a/modules/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml b/modules/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml index 04e4833f80589110c8a168ccbe70dbfff7acd376..fe8bb0b5048d59253a8444c440829ec125a24ae2 100644 --- a/modules/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml +++ b/modules/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml @@ -10,6 +10,10 @@ + + + +