[jbosscache-commits] JBoss Cache SVN: r6678 - in benchmarks/benchmark-fwk/trunk: src/org/cachebench/utils and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Sep 2 13:08:54 EDT 2008


Author: mircea.markus
Date: 2008-09-02 13:08:54 -0400 (Tue, 02 Sep 2008)
New Revision: 6678

Added:
   benchmarks/benchmark-fwk/trunk/conf/email.properties
   benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/SMTPAppender.java
Modified:
   benchmarks/benchmark-fwk/trunk/conf/log4j.xml
   benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/PerNodeRollingFileAppender.java
Log:
added emaild notification

Added: benchmarks/benchmark-fwk/trunk/conf/email.properties
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/email.properties	                        (rev 0)
+++ benchmarks/benchmark-fwk/trunk/conf/email.properties	2008-09-02 17:08:54 UTC (rev 6678)
@@ -0,0 +1,12 @@
+mail.transport.protocol=smtp
+mail.host=smtp.gmail.com
+mail.smtp.auth=true
+mail.smtp.port=465
+mail.smtp.socketFactory.port=465
+mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
+mail.smtp.socketFactory.fallback=false
+mail.smtp.quitwait=false
+
+
+mail.smtp.user=notify.by.email at gmail.com
+mail.smtp.password=******

Modified: benchmarks/benchmark-fwk/trunk/conf/log4j.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/log4j.xml	2008-09-02 13:44:35 UTC (rev 6677)
+++ benchmarks/benchmark-fwk/trunk/conf/log4j.xml	2008-09-02 17:08:54 UTC (rev 6678)
@@ -5,7 +5,7 @@
 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <!-- The list of appenders -->
    <!-- The rolling file appender -->
-   <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
+   <appender name="FILE" class="org.cachebench.utils.PerNodeRollingFileAppender">
       <!--<appender name="FILE" class="org.cachebench.utils.PerNodeRollingFileAppender">-->
       <param name="File" value="cachebench.log"/>
       <param name="Append" value="true"/>
@@ -27,6 +27,20 @@
       </layout>
    </appender>
 
+   <appender name="EMAIL" class="org.cachebench.utils.SMTPAppender">
+      <param name="Threshold" value="WARN"/>
+      <param name="BufferSize" value="1"/>
+      <param name="From" value="notify.by.email at gmail.com"/>
+      <param name="From" value="notify.by.email at gmail.com"/>
+      <param name="To" value="mircea.markus at jboss.com"/>
+      <param name="SMTPHost" value="smtp.gmail.com"/>
+      <param name="SMTPPort" value="465"/>
+      <param name="Subject" value="Cache Bench notification1"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
    <!-- The list of Categories-->
    <category name="ClusterConfigurationCheck">
       <priority value="INFO"/>
@@ -42,6 +56,7 @@
 
    <category name="org.cachebench">
       <priority value="INFO"/>
+      <appender-ref ref="EMAIL"/>
    </category>
 
    <category name="org.cachebench.reportgenerators">

Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/PerNodeRollingFileAppender.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/PerNodeRollingFileAppender.java	2008-09-02 13:44:35 UTC (rev 6677)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/PerNodeRollingFileAppender.java	2008-09-02 17:08:54 UTC (rev 6678)
@@ -39,6 +39,15 @@
    }
 
    private String appendNodeIndex(String s) {
-      return conf.getCurrentNodeIndex() + "_" + s;
+      try
+      {
+         return conf.getCurrentNodeIndex() + "_" + s;
+      } catch (Throwable e)//ignore here, we're just a logger
+      {
+         System.out.println("exception occued while trying to index the file name: " + e.getMessage());
+         return s;
+      }
    }
+
+
 }

Added: benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/SMTPAppender.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/SMTPAppender.java	                        (rev 0)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/utils/SMTPAppender.java	2008-09-02 17:08:54 UTC (rev 6678)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.cachebench.utils;
+
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.TriggeringEventEvaluator;
+import org.apache.log4j.spi.LoggingEvent;
+
+import javax.mail.Authenticator;
+import javax.mail.Message;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.util.Properties;
+
+
+public class SMTPAppender extends org.apache.log4j.net.SMTPAppender
+{
+
+   public SMTPAppender()
+   {
+      //support all message types
+      super(new TriggeringEventEvaluator()
+      {
+         public boolean isTriggeringEvent(LoggingEvent event)
+         {
+            return true;
+         }
+      });
+   }
+
+   /**
+    * Activate the specified options, such as the smtp host, the
+    * recipient, from, etc.
+    */
+   public void activateOptions()
+   {
+      final Properties props = new Properties();
+      try
+      {
+         props.load(getClass().getClassLoader().getResourceAsStream("email.properties"));
+      } catch (Exception e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException(e);
+      }
+
+      try
+      {
+         Session session = Session.getInstance(props, new Authenticator()
+         {
+            @Override
+            protected PasswordAuthentication getPasswordAuthentication()
+            {
+               return new PasswordAuthentication(props.getProperty("mail.smtp.user"),props.getProperty("mail.smtp.password"));
+            }
+         });
+         //session.setDebug(true);
+         msg = new MimeMessage(session);
+
+
+         if (getFrom() != null)
+            msg.setFrom(new InternetAddress(getFrom()));
+         else
+            msg.setFrom();
+
+         msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getTo(), true));
+         if (getSubject() != null)
+            msg.setSubject(getSubject());
+      } catch (Throwable e)
+      {
+         LogLog.error("Could not activate SMTPAppender options.", e);
+      }
+   }
+
+
+}




More information about the jbosscache-commits mailing list