1 19 package za.org.coefficient.util.stats.webapp; 20 21 import net.sf.hibernate.util.HibernateUtil; 22 23 import za.org.coefficient.core.Constants; 24 import za.org.coefficient.interfaces.StatisticsMessageSender; 25 import za.org.coefficient.util.common.InvokerFactory; 26 27 32 public class WebAppStatisticsMessageSender implements StatisticsMessageSender { 33 35 37 public void reportStatistic(Long projectId, String moduleName, String action) { 38 if ((projectId == null) || (action == null)) { 39 throw new IllegalArgumentException ("project and action must not be null to send a message"); 40 } else { 41 try { 42 new StatsThread(projectId, moduleName, action).start(); 43 } catch (Exception e) { 44 System.out.println("WebAppStatisticMessageSender: error invoking stats service - " + e); 45 e.printStackTrace(); 46 } 47 } 48 } 49 50 private class StatsThread extends Thread { 51 52 private Long projectId; 53 private String moduleName; 54 private String action; 55 56 public StatsThread(Long projectId, String moduleName, String action) { 57 this.projectId = projectId; 58 this.action = action; 59 if(moduleName == null) { 60 this.moduleName = ""; 61 } else { 62 this.moduleName = moduleName; 63 } 64 } 65 66 public void run() { 67 try { 68 InvokerFactory.getInvoker() 69 .invokeMethodOnService("StatisticsService", "doStatistics", 70 new Object []{moduleName, projectId, action}); 71 HibernateUtil.finalizeSession(); 74 } catch(Exception e) { 75 e.printStackTrace(); 76 System.err.println("<< WebAppStatisticsMessageSender - problem with thread"); 77 } 78 } 79 } 80 } 81 | Popular Tags |