mstover1    01/07/15 10:01:06

  Modified:    src/org/apache/jmeter/protocol/http/sampler HTTPSampler.java
               src/org/apache/jmeter/reporters ResultCollector.java
               src/org/apache/jmeter/visualizers MailerVisualizer.java
                        ViewResultsVisualizer.java
  Added:       src/org/apache/jmeter/reporters MailerResultCollector.java
               src/org/apache/jmeter/samplers Clearable.java
  Log:
  Mailer visualizer revamped to new JMeter architecture.  New Clearable interface.
  
  Revision  Changes    Path
  1.15      +4 -4      
jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
  
  Index: HTTPSampler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- HTTPSampler.java  2001/06/29 21:57:15     1.14
  +++ HTTPSampler.java  2001/07/15 17:01:05     1.15
  @@ -6,7 +6,7 @@
    * companies.
    *
    * All rights reserved
  - * $Header: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
 1.14 2001/06/29 21:57:15 mstover1 Exp $
  + * $Header: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
 1.15 2001/07/15 17:01:05 mstover1 Exp $
    */
   package org.apache.jmeter.protocol.http.sampler;
   
  @@ -28,8 +28,8 @@
    *  HTTP requests, including cookies and authentication.
    *
    *@author     Michael Stover
  - *@created    $Date: 2001/06/29 21:57:15 $
  - *@version    $Revision: 1.14 $
  + *@created    $Date: 2001/07/15 17:01:05 $
  + *@version    $Revision: 1.15 $
    */
   public class HTTPSampler implements Sampler
   {
  @@ -304,7 +304,7 @@
                }
                catch (IOException ex)
                {
  -                     ex.printStackTrace();
  +                     //ex.printStackTrace();
                        res.setTime((long) 0);
                        res.putValue(this.TEXT_RESPONSE, ex.toString());
                        res.putValue(SUCCESS, new Boolean(false));
  
  
  
  1.7       +272 -164  
jakarta-jmeter/src/org/apache/jmeter/reporters/ResultCollector.java
  
  Index: ResultCollector.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/reporters/ResultCollector.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ResultCollector.java      2001/06/29 21:57:21     1.6
  +++ ResultCollector.java      2001/07/15 17:01:05     1.7
  @@ -1,164 +1,272 @@
  -/*
  - * ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - * notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - * notice, this list of conditions and the following disclaimer in
  - * the documentation and/or other materials provided with the
  - * distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - * if any, must include the following acknowledgment:
  - * "This product includes software developed by the
  - * Apache Software Foundation (http://www.apache.org/)."
  - * Alternately, this acknowledgment may appear in the software itself,
  - * if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - * "Apache JMeter" must not be used to endorse or promote products
  - * derived from this software without prior written permission. For
  - * written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - * "Apache JMeter", nor may "Apache" appear in their name, without
  - * prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  - package org.apache.jmeter.reporters;
  -
  -import org.apache.jmeter.gui.*;
  -import java.util.*;
  -import org.apache.jmeter.samplers.*;
  -import org.apache.jmeter.visualizers.ViewResultsVisualizer;
  -import org.apache.jmeter.save.Saveable;
  -/**
  - * Title:
  - * Description:
  - * Copyright:    Copyright (c) 2001
  - * Company:
  - * @author Michael Stover
  - * @version 1.0
  - */
  -
  -public class ResultCollector implements 
JMeterComponentModel,SampleListener,Saveable
  -{
  -
  -     private ArrayList results = new ArrayList();
  -     private String name;
  -     private ViewResultsVisualizer listener;
  -     private int current;
  -
  -     public ResultCollector()
  -     {
  -             current = 0;
  -     }
  -
  -     public Class getTagHandlerClass()
  -     {
  -             return org.apache.jmeter.save.handlers.JMeterComponentHandler.class;
  -     }
  -
  -     public void setListener(ViewResultsVisualizer listener)
  -     {
  -             this.listener = listener;
  -     }
  -
  -     public Class getGuiClass()
  -     {
  -             return org.apache.jmeter.visualizers.ViewResultsVisualizer.class;
  -     }
  -     public String getName()
  -     {
  -             return name;
  -     }
  -     public void setName(String name)
  -     {
  -             this.name = name;
  -     }
  -     public Collection getAddList()
  -     {
  -             return null;
  -     }
  -     public String getClassLabel()
  -     {
  -             return "View Results";
  -     }
  -     public void uncompile()
  -     {
  -             this.clear();
  -     }
  -
  -     public void clear()
  -     {
  -             results.clear();
  -             current = 0;
  -             if(listener != null)
  -             {
  -                     listener.clear();
  -             }
  -     }
  -
  -     public String getSampleLabel()
  -     {
  -             if(current < results.size() && current >= 0)
  -             {
  -             SampleResult res = (SampleResult)results.get(current);
  -             return (String)res.getValue(Sampler.SAMPLE_LABEL);
  -             }
  -             else return "";
  -     }
  -
  -     public String getTextResponse()
  -     {
  -             if(current < results.size() && current >= 0)
  -             {
  -             return 
(String)((SampleResult)results.get(current++)).getValue(Sampler.TEXT_RESPONSE);
  -             }
  -             else return "";
  -     }
  -
  -     public void sampleStarted(SampleEvent e)
  -     {
  -     }
  -
  -     public void sampleStopped(SampleEvent e)
  -     {
  -     }
  -
  -     public void sampleOccurred(SampleEvent e)
  -     {
  -             results.add(e.getResult());
  -             if(listener != null)
  -             {
  -                     listener.updateGui();
  -             }
  -     }
  -}
  \ No newline at end of file
  +/*
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + * notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + * notice, this list of conditions and the following disclaimer in
  + * the documentation and/or other materials provided with the
  + * distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + * if any, must include the following acknowledgment:
  + * "This product includes software developed by the
  + * Apache Software Foundation (http://www.apache.org/)."
  + * Alternately, this acknowledgment may appear in the software itself,
  + * if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + * "Apache JMeter" must not be used to endorse or promote products
  + * derived from this software without prior written permission. For
  + * written permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + * "Apache JMeter", nor may "Apache" appear in their name, without
  + * prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +package org.apache.jmeter.reporters;
  +
  +import org.apache.jmeter.gui.*;
  +import java.util.*;
  +import org.apache.jmeter.samplers.*;
  +import org.apache.jmeter.visualizers.ViewResultsVisualizer;
  +import org.apache.jmeter.save.Saveable;
  +/**
  + *  Title: Description: Copyright: Copyright (c) 2001 Company:
  + *
  + *@author     Michael Stover
  + *@created    July 14, 2001
  + *@version    1.0
  + */
  +
  +public class ResultCollector implements JMeterComponentModel, SampleListener, 
Saveable,Clearable
  +{
  +     private static int SIZE_LIMIT = 100;
  +
  +     private ArrayList results = new ArrayList();
  +     private String name;
  +     private ModelSupported listener;
  +     private int current;
  +
  +     /**
  +      *  Constructor for the ResultCollector object
  +      */
  +     public ResultCollector()
  +     {
  +             current = 0;
  +     }
  +
  +     /**
  +      *  Sets the Listener attribute of the ResultCollector object
  +      *
  +      *@param  listener  The new Listener value
  +      */
  +     public void setListener(ModelSupported listener)
  +     {
  +             this.listener = listener;
  +     }
  +
  +     /**
  +      *  Sets the Name attribute of the ResultCollector object
  +      *
  +      *@param  name  The new Name value
  +      */
  +     public void setName(String name)
  +     {
  +             this.name = name;
  +     }
  +
  +     /**
  +      *  Gets the TagHandlerClass attribute of the ResultCollector object
  +      *
  +      *@return    The TagHandlerClass value
  +      */
  +     public Class getTagHandlerClass()
  +     {
  +             return org.apache.jmeter.save.handlers.JMeterComponentHandler.class;
  +     }
  +
  +     /**
  +      *  Gets the GuiClass attribute of the ResultCollector object
  +      *
  +      *@return    The GuiClass value
  +      */
  +     public Class getGuiClass()
  +     {
  +             return org.apache.jmeter.visualizers.ViewResultsVisualizer.class;
  +     }
  +
  +     /**
  +      *  Gets the Name attribute of the ResultCollector object
  +      *
  +      *@return    The Name value
  +      */
  +     public String getName()
  +     {
  +             return name;
  +     }
  +
  +     /**
  +      *  Gets the AddList attribute of the ResultCollector object
  +      *
  +      *@return    The AddList value
  +      */
  +     public Collection getAddList()
  +     {
  +             return null;
  +     }
  +
  +     /**
  +      *  Gets the ClassLabel attribute of the ResultCollector object
  +      *
  +      *@return    The ClassLabel value
  +      */
  +     public String getClassLabel()
  +     {
  +             return "View Results";
  +     }
  +
  +
  +     /**
  +      *  Gets the SampleLabel attribute of the ResultCollector object
  +      *
  +      *@return    The SampleLabel value
  +      */
  +     public String getSampleLabel()
  +     {
  +             if (current < results.size() && current >= 0)
  +             {
  +                     SampleResult res = (SampleResult) results.get(current);
  +                     return (String) res.getValue(Sampler.SAMPLE_LABEL);
  +             }
  +             else
  +             {
  +                     return "";
  +             }
  +     }
  +
  +     /**
  +      *  Gets the TextResponse attribute of the ResultCollector object
  +      *
  +      *@return    The TextResponse value
  +      */
  +     public String getTextResponse()
  +     {
  +             if (current < results.size() && current >= 0)
  +             {
  +                     return (String) ((SampleResult) 
results.get(current)).getValue(Sampler.TEXT_RESPONSE);
  +             }
  +             else
  +             {
  +                     return "";
  +             }
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      */
  +     public void uncompile()
  +     {
  +             this.clear();
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      */
  +     public void clear()
  +     {
  +             results.clear();
  +             current = 0;
  +             if (listener != null)
  +             {
  +                     ((Clearable)listener).clear();
  +             }
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      */
  +     public void next()
  +     {
  +             if (++current >= results.size())
  +             {
  +                     current--;
  +             }
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      */
  +     public void previous()
  +     {
  +             if (--current < 0)
  +             {
  +                     current = 0;
  +             }
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      *
  +      *@param  e  Description of Parameter
  +      */
  +     public void sampleStarted(SampleEvent e)
  +     {
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      *
  +      *@param  e  Description of Parameter
  +      */
  +     public void sampleStopped(SampleEvent e)
  +     {
  +     }
  +
  +     /**
  +      *  Description of the Method
  +      *
  +      *@param  e  Description of Parameter
  +      */
  +     public void sampleOccurred(SampleEvent e)
  +     {
  +             results.add(e.getResult());
  +             if(results.size() > SIZE_LIMIT)
  +             {
  +                     results.remove(0);
  +                     current--;
  +             }
  +             if (listener != null)
  +             {
  +                     listener.updateGui();
  +             }
  +     }
  +}
  
  
  
  1.1                  
jakarta-jmeter/src/org/apache/jmeter/reporters/MailerResultCollector.java
  
  Index: MailerResultCollector.java
  ===================================================================
  package org.apache.jmeter.reporters;
  
  import java.util.*;
  import java.net.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  
  import org.apache.jmeter.util.JMeterUtils;
  import org.apache.jmeter.samplers.*;
  
  /**
   * Title:        Apache JMeter
   * Description:
   * Copyright:    Copyright (c) 2000
   * Company:      Apache Foundation
   * @author Michael Stover
   * @version 1.0
   */
  
  public class MailerResultCollector extends ResultCollector
  {
  
        String address;
        String from;
        String smtpHost;
        String failSubject;
        String successSubject;
        long failureCount = 0;
        long successCount = 0;
        long failureLimit = 2;
        long successLimit = 2;
        boolean failureMsgSent = false;
        boolean siteDown = false;
        boolean successMsgSent = false;
  
        public MailerResultCollector()
        {
                super();
                from = JMeterUtils.getPropDefault("mailer.from","");
                address = JMeterUtils.getPropDefault("mailer.addressies","");
                smtpHost = JMeterUtils.getPropDefault("mailer.smtphost","");
                failSubject = JMeterUtils.getPropDefault("mailer.failsubject","");
                successSubject = 
JMeterUtils.getPropDefault("mailer.successsubject","");
                try
                {
                        failureLimit =
                                        
Long.parseLong(JMeterUtils.getPropDefault("mailer.failurelimit","2"));
                }catch (NumberFormatException ex){}
                try
                {
                        successLimit =
                                        
Long.parseLong(JMeterUtils.getPropDefault("mailer.successlimit","2"));
                }catch (NumberFormatException ex){}
        }
  
                /**
         *  Gets the GuiClass attribute of the ResultCollector object
         *
         *@return    The GuiClass value
         */
        public Class getGuiClass()
        {
                return org.apache.jmeter.visualizers.MailerVisualizer.class;
        }
  
                /**
         *  Gets the ClassLabel attribute of the ResultCollector object
         *
         *@return    The ClassLabel value
         */
        public String getClassLabel()
        {
                return "Email Results";
        }
  
        public long getFailureLimit()
        {
                return failureLimit;
        }
  
        public long getFailureCount()
        {
                return failureCount;
        }
  
        public long getSuccessLimit()
        {
                return successLimit;
        }
  
        public void setFailureLimit(long limit)
        {
                failureLimit = limit;
        }
  
        public void setSuccessLimit(long limit)
        {
                successLimit = limit;
        }
  
        public void setAddress(String address)
        {
                this.address = address;
        }
  
        public String getAddress()
        {
                return address;
        }
  
        public void setFrom(String from)
        {
                this.from = from;
        }
  
        public String getFrom()
        {
                return from;
        }
  
        public void setSmtpHost(String host)
        {
                smtpHost = host;
        }
  
        public String getSmtpHost()
        {
                return smtpHost;
        }
  
        public void setFailSubject(String subject)
        {
                failSubject = subject;
        }
  
        public String getFailSubject()
        {
                return failSubject;
        }
  
        public void setSuccessSubject(String subject)
        {
                successSubject = subject;
        }
  
        public String getSuccessSubject()
        {
                return successSubject;
        }
  
        /************************************************************
         *  !ToDoo (Method description)
         *
         *@return    !ToDo (Return description)
         ***********************************************************/
        public synchronized boolean isFailing()
        {
                return (failureCount > failureLimit);
        }
  
        public void sendTestMessage()
        {
                System.out.println("### Test To:  " + this.address + ", " +
                                                "Via:  " + this.smtpHost + ", " +
                                                "Fail Subject:  " + this.failSubject + 
", " +
                                                "Success Subject:  " + 
this.successSubject);
                                String testMessage = ("### Test To:  " + this.address 
+ ", " +
                                                "Via:  " + this.smtpHost + ", " +
                                                "Fail Subject:  " + this.failSubject + 
", " +
                                                "Success Subject:  " + 
this.successSubject);
  
                                Vector addressVector = newAddressVector(address);
                                sendMail(from, addressVector, "Testing addressies", 
testMessage, smtpHost);
        }
  
                /************************************************************
         *  !ToDo (Method description)
         *
         *@param  sample  !ToDo (Parameter description)
         ***********************************************************/
        public synchronized void sampleOccurred(SampleEvent event)
        {
                super.sampleOccurred(event);
                SampleResult sample = event.getResult();
  
                // -1 is the code for a failed sample.
                //
                if (sample.getValue(Sampler.SUCCESS) == null ||
                                
!((Boolean)sample.getValue(Sampler.SUCCESS)).booleanValue())
                {
                        failureCount++;
                }
                else
                {
                        successCount++;
                }
  
                if (this.isFailing() && !siteDown && !failureMsgSent)
                {
  
                        // Send the mail ...
                        Vector addressVector = newAddressVector(address);
                        sendMail(from, addressVector, failSubject, "URL Failed: " +
                                        sample.getValue(Sampler.SAMPLE_LABEL), 
smtpHost);
                        siteDown = true;
                        failureMsgSent = true;
                        successCount = 0;
                }
  
                if (siteDown && (sample.getTime() != -1) & !successMsgSent)
                {
                        // Send the mail ...
                        if (successCount > successLimit)
                        {
                                Vector addressVector = newAddressVector(address);
                                sendMail(from, addressVector, successSubject, "URL 
Restarted: " +
                                                sample.getValue(Sampler.SAMPLE_LABEL), 
smtpHost);
                                siteDown = false;
                                successMsgSent = true;
                        }
                }
  
                if (successMsgSent && failureMsgSent)
                {
                        clear();
                }
        }
  
        /************************************************************
         *  !ToDo (Method description)
         *
         *@param  from      !ToDo (Parameter description)
         *@param  vEmails   !ToDo (Parameter description)
         *@param  subject   !ToDo (Parameter description)
         *@param  attText   !ToDo (Parameter description)
         *@param  SMTPHost  !ToDo (Parameter description)
         ***********************************************************/
        public static synchronized void sendMail(String from,
                        Vector vEmails,
                        String subject,
                        String attText,
                        String SMTPHost)
        {
                try
                {
                        String host = SMTPHost;
                        boolean debug = Boolean.valueOf(host).booleanValue();
                        InetAddress remote = InetAddress.getByName(host);
  
                        InternetAddress[] address = new 
InternetAddress[vEmails.size()];
                        for (int k = 0; k < vEmails.size(); k++)
                        {
                                address[k] = new 
InternetAddress(vEmails.elementAt(k).toString());
                        }
  
                        // create some properties and get the default Session
                        Properties props = new Properties();
                        props.put("mail.smtp.host", host);
                        Session session = Session.getDefaultInstance(props, null);
                        session.setDebug(debug);
  
                        // create a message
                        Message msg = new MimeMessage(session);
                        msg.setFrom(new InternetAddress(from));
                        msg.setRecipients(Message.RecipientType.TO, address);
                        msg.setSubject(subject);
                        msg.setText(attText);
                        Transport.send(msg);
                        System.out.println("Mail sent successfully!!");
                }
                catch (UnknownHostException e1)
                {
                        System.out.println("NxError:Invalid Mail Server " + e1);
                        System.exit(1);
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                        System.exit(1);
                }
        }
  
                /************************************************************
         *  !ToDo (Method description)
         *
         *@param  theAddressie  !ToDo (Parameter description)
         *@return               !ToDo (Return description)
         ***********************************************************/
        public synchronized Vector newAddressVector(String theAddressie)
        {
                Vector addressVector = new Vector();
                String addressSep = ", ";
  
                StringTokenizer next = new StringTokenizer(theAddressie, addressSep);
  
                while (next.hasMoreTokens())
                {
                        String theToken = next.nextToken();
  
                        if (theToken.indexOf("@") > 0)
                        {
                                addressVector.addElement(theToken);
                        }
                }
  
                return addressVector;
        }
  }
  
  
  1.1                  jakarta-jmeter/src/org/apache/jmeter/samplers/Clearable.java
  
  Index: Clearable.java
  ===================================================================
  package org.apache.jmeter.samplers;
  
  /**
   * Title:        Apache JMeter
   * Description:
   * Copyright:    Copyright (c) 2000
   * Company:      Apache Foundation
   * @author Michael Stover
   * @version 1.0
   */
  
  public interface Clearable
  {
        /**
         * Clears the current data of the object.
         */
        public void clear();
  }
  
  
  1.13      +38 -237   
jakarta-jmeter/src/org/apache/jmeter/visualizers/MailerVisualizer.java
  
  Index: MailerVisualizer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/visualizers/MailerVisualizer.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MailerVisualizer.java     2001/03/17 22:25:59     1.12
  +++ MailerVisualizer.java     2001/07/15 17:01:05     1.13
  @@ -61,13 +61,14 @@
   import javax.swing.event.*;
   import java.util.*;
   import java.net.*;
  -import javax.mail.*;
  -import javax.mail.internet.*;
   //import javax.activation.* ;
   import java.util.Properties;
   import org.apache.jmeter.util.*;
   import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.samplers.Sampler;
  +import org.apache.jmeter.reporters.MailerResultCollector;
  +import org.apache.jmeter.gui.ModelSupported;
  +import org.apache.jmeter.gui.JMeterComponentModel;
   
   /*
    * TODO :
  @@ -84,27 +85,13 @@
    *  occurs.
    *
    *@author     <a href="mailto:[EMAIL PROTECTED]";>Stuart Schmukler</a>
  - *@created    $Date: 2001/03/17 22:25:59 $
  - *@version    $Revision: 1.12 $ $Date: 2001/03/17 22:25:59 $
  + *@created    $Date: 2001/07/15 17:01:05 $
  + *@version    $Revision: 1.13 $ $Date: 2001/07/15 17:01:05 $
    ***********************************************************/
  -public class MailerVisualizer extends JPanel implements Visualizer, ActionListener
  +public class MailerVisualizer extends JPanel implements ModelSupported, 
ActionListener
   {
  +     MailerResultCollector model;
   
  -     String addressie;
  -     String from;
  -     String smtpHost;
  -     String failsubject;
  -     String successsubject;
  -     long failureCount = 0;
  -     long successCount = 0;
  -     long failureLimit = 2;
  -     long successLimit = 2;
  -     boolean failureMsgSent = false;
  -     boolean siteDown = false;
  -     boolean successMsgSent = false;
  -
  -     Properties appProperties;
  -
        JButton testerButton;
        JTextField addressField;
        JTextField fromField;
  @@ -123,10 +110,21 @@
        public MailerVisualizer()
        {
                super();
  +     }
   
  -             // Properties connection.
  -             this.appProperties = JMeterUtils.getJMeterProperties();
  +     public void setModel(Object model)
  +     {
  +             this.model = (MailerResultCollector)model;
  +             init();
  +     }
   
  +     public void updateGui()
  +     {
  +             failureField.setText(Long.toString(model.getFailureCount()));
  +     }
  +
  +     private void init()
  +     {
                // File panel
                JPanel mailerPanel = new JPanel();
                GridBagLayout g = new GridBagLayout();
  @@ -138,8 +136,7 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("From:"));
   
  -             from = appProperties.getProperty("mailer.from");
  -             fromField = new JTextField(from, 25);
  +             fromField = new JTextField(model.getFrom(), 25);
                fromField.setEditable(true);
                fromField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -151,8 +148,7 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("Addressie(s):"));
   
  -             addressie = appProperties.getProperty("mailer.addressies");
  -             addressField = new JTextField(addressie, 25);
  +             addressField = new JTextField(model.getAddress(), 25);
                addressField.setEditable(true);
                addressField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -162,8 +158,7 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("SMTP Host:"));
   
  -             smtpHost = appProperties.getProperty("mailer.smtphost");
  -             smtpHostField = new JTextField(smtpHost, 25);
  +             smtpHostField = new JTextField(model.getSmtpHost(), 25);
                smtpHostField.setEditable(true);
                smtpHostField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -173,8 +168,7 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("Failure Subject:"));
   
  -             failsubject = appProperties.getProperty("mailer.failsubject");
  -             failsubjectField = new JTextField(failsubject, 25);
  +             failsubjectField = new JTextField(model.getFailSubject(), 25);
                failsubjectField.setEditable(true);
                failsubjectField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -184,8 +178,7 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("Success Subject:"));
   
  -             successsubject = appProperties.getProperty("mailer.successsubject");
  -             successsubjectField = new JTextField(successsubject, 25);
  +             successsubjectField = new JTextField(model.getSuccessSubject(), 25);
                successsubjectField.setEditable(true);
                successsubjectField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -195,16 +188,8 @@
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("Failure Limit:"));
   
  -             try
  -             {
  -                     failureLimit =
  -                                     
Long.parseLong(appProperties.getProperty("mailer.failurelimit"));
  -             }
  -             catch (NumberFormatException ex)
  -             {
  -                     // Ignore any garbage
  -             }
  -             failureLimitField = new JTextField(Long.toString(failureLimit), 6);
  +
  +             failureLimitField = new 
JTextField(Long.toString(model.getFailureLimit()), 6);
                failureLimitField.setEditable(true);
                failureLimitField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -213,17 +198,7 @@
   
                c.gridwidth = 1;
                mailerPanel.add(new JLabel("Success Limit:"));
  -
  -             try
  -             {
  -                     successLimit =
  -                                     
Long.parseLong(appProperties.getProperty("mailer.successlimit"));
  -             }
  -             catch (NumberFormatException ex)
  -             {
  -                     // Ignore any garbage
  -             }
  -             successLimitField = new JTextField(Long.toString(successLimit), 6);
  +             successLimitField = new 
JTextField(Long.toString(model.getSuccessLimit()), 6);
                successLimitField.setEditable(true);
                successLimitField.addActionListener(this);
                c.gridwidth = GridBagConstraints.REMAINDER;
  @@ -249,26 +224,9 @@
                this.add(mailerPanel);
        }
   
  -     /************************************************************
  -      *  !ToDoo (Method description)
  -      *
  -      *@return    !ToDo (Return description)
  -      ***********************************************************/
  -     public synchronized boolean isFailing()
  -     {
  -             return (failureCount > failureLimit);
  -     }
   
  -     /************************************************************
  -      *  !ToDoo (Method description)
  -      *
  -      *@return    !ToDo (Return description)
  -      ***********************************************************/
  -     public JPanel getControlPanel()
  -     {
  -             return this;
  -     }
   
  +
        /************************************************************
         *  !ToDo (Method description)
         *
  @@ -281,53 +239,36 @@
                        JComponent c = (JComponent)e.getSource();
                        if (c == addressField)
                        {
  -                             this.addressie = this.addressField.getText();
  -                             System.out.println("AddressField=" + 
addressField.getText());
  +                             this.model.setAddress(addressField.getText());
                        }
                        else if (c == fromField)
                        {
  -                             this.from = this.fromField.getText();
  -                             System.out.println("FromField=" + 
fromField.getText());
  +                             model.setFrom(fromField.getText());
                        }
                        else if (c == smtpHostField)
                        {
  -                             this.smtpHost = this.smtpHostField.getText();
  -                             System.out.println("smtpHostField=" + 
smtpHostField.getText());
  +                             model.setSmtpHost(smtpHostField.getText());
                        }
                        else if (c == failsubjectField)
                        {
  -                             this.failsubject = this.failsubjectField.getText();
  -                             System.out.println("failsubjectField=" + 
failsubjectField.getText());
  +                             model.setFailSubject(failsubjectField.getText());
                        }
                        else if (c == successsubjectField)
                        {
  -                             this.successsubject = 
this.successsubjectField.getText();
  -                             System.out.println("successsubjectField=" + 
successsubjectField.getText());
  +                             
model.setSuccessSubject(successsubjectField.getText());
                        }
                        else if (c == failureLimitField)
                        {
  -                             this.failureLimit = 
Long.parseLong(this.failureLimitField.getText());
  -                             System.out.println("failureLimitField=" + 
failureLimitField.getText());
  +                             
model.setFailureLimit(Long.parseLong(this.failureLimitField.getText()));
                        }
                        else if (c == successLimitField)
                        {
  -                             this.successLimit = 
Long.parseLong(this.successLimitField.getText());
  -                             System.out.println("successLimitField=" + 
successLimitField.getText());
  +                             
model.setSuccessLimit(Long.parseLong(this.successLimitField.getText()));
                        }
                        else if (c == testerButton)
                        {
  -                             System.out.println("### Test To:  " + this.addressie + 
", " +
  -                                             "Via:  " + this.smtpHost + ", " +
  -                                             "Fail Subject:  " + this.failsubject + 
", " +
  -                                             "Success Subject:  " + 
this.successsubject);
  -
  -                             String testMessage = ("### Test To:  " + 
this.addressie + ", " +
  -                                             "Via:  " + this.smtpHost + ", " +
  -                                             "Fail Subject:  " + this.failsubject + 
", " +
  -                                             "Success Subject:  " + 
this.successsubject);
  +                             model.sendTestMessage();
   
  -                             Vector addressVector = newAddressVector(addressie);
  -                             sendMail(from, addressVector, "Testing addressies", 
testMessage, smtpHost);
                        }
                        else
                        {
  @@ -341,103 +282,15 @@
        }
   
   
  -     /************************************************************
  -      *  !ToDo (Method description)
  -      *
  -      *@param  theAddressie  !ToDo (Parameter description)
  -      *@return               !ToDo (Return description)
  -      ***********************************************************/
  -     public synchronized Vector newAddressVector(String theAddressie)
  -     {
  -             Vector addressVector = new Vector();
  -             String addressSep = ", ";
  -
  -             StringTokenizer next = new StringTokenizer(theAddressie, addressSep);
  -
  -             while (next.hasMoreTokens())
  -             {
  -                     String theToken = next.nextToken();
  -
  -                     if (theToken.indexOf("@") > 0)
  -                     {
  -                             addressVector.addElement(theToken);
  -                     }
  -             }
  -
  -             return addressVector;
  -     }
  -
  -
  -     /************************************************************
  -      *  !ToDo (Method description)
  -      *
  -      *@param  sample  !ToDo (Parameter description)
  -      ***********************************************************/
  -     public synchronized void add(SampleResult sample)
  -     {
  -
  -             // -1 is the code for a failed sample.
  -             //
  -             if (sample.getValue(Sampler.SUCCESS) == null ||
  -                             
!((Boolean)sample.getValue(Sampler.SUCCESS)).booleanValue())
  -             {
  -                     failureCount++;
  -             }
  -             else
  -             {
  -                     successCount++;
  -             }
  -
  -             if (this.isFailing() && !siteDown && !failureMsgSent)
  -             {
  -                     // Display ...
  -                     failureField.setText(Long.toString(failureCount));
  -                     repaint();
  -
  -                     // Send the mail ...
  -                     Vector addressVector = newAddressVector(addressie);
  -                     sendMail(from, addressVector, failsubject, "URL Failed: " +
  -                                     sample.getValue(Sampler.SAMPLE_LABEL), 
smtpHost);
  -                     siteDown = true;
  -                     failureMsgSent = true;
  -                     successCount = 0;
  -             }
  -
  -             if (siteDown && (sample.getTime() != -1) & !successMsgSent)
  -             {
  -                     // Display ...
  -                     failureField.setText(Long.toString(failureCount));
  -                     repaint();
  -
  -                     // Send the mail ...
  -                     if (successCount > successLimit)
  -                     {
  -                             Vector addressVector = newAddressVector(addressie);
  -                             sendMail(from, addressVector, successsubject, "URL 
Restarted: " +
  -                                             sample.getValue(Sampler.SAMPLE_LABEL), 
smtpHost);
  -                             siteDown = false;
  -                             successMsgSent = true;
  -                     }
  -             }
   
  -             if (successMsgSent && failureMsgSent)
  -             {
  -                     clear();
  -             }
  -     }
   
        /************************************************************
         *  !ToDo (Method description)
         ***********************************************************/
        public synchronized void clear()
        {
  -             failureCount = 0;
  -             successCount = 0;
  -             siteDown = false;
  -             successMsgSent = false;
  -             failureMsgSent = false;
   
  -             failureField.setText(Long.toString(failureCount));
  +             failureField.setText(Long.toString(model.getFailureCount()));
                repaint();
        }
   
  @@ -454,57 +307,5 @@
        //-----------
        //function to send a mail to list mailaddresses
   
  -     /************************************************************
  -      *  !ToDo (Method description)
  -      *
  -      *@param  from      !ToDo (Parameter description)
  -      *@param  vEmails   !ToDo (Parameter description)
  -      *@param  subject   !ToDo (Parameter description)
  -      *@param  attText   !ToDo (Parameter description)
  -      *@param  SMTPHost  !ToDo (Parameter description)
  -      ***********************************************************/
  -     public static synchronized void sendMail(String from,
  -                     Vector vEmails,
  -                     String subject,
  -                     String attText,
  -                     String SMTPHost)
  -     {
  -             try
  -             {
  -                     String host = SMTPHost;
  -                     boolean debug = Boolean.valueOf(host).booleanValue();
  -                     InetAddress remote = InetAddress.getByName(host);
  -
  -                     InternetAddress[] address = new 
InternetAddress[vEmails.size()];
  -                     for (int k = 0; k < vEmails.size(); k++)
  -                     {
  -                             address[k] = new 
InternetAddress(vEmails.elementAt(k).toString());
  -                     }
   
  -                     // create some properties and get the default Session
  -                     Properties props = new Properties();
  -                     props.put("mail.smtp.host", host);
  -                     Session session = Session.getDefaultInstance(props, null);
  -                     session.setDebug(debug);
  -
  -                     // create a message
  -                     Message msg = new MimeMessage(session);
  -                     msg.setFrom(new InternetAddress(from));
  -                     msg.setRecipients(Message.RecipientType.TO, address);
  -                     msg.setSubject(subject);
  -                     msg.setText(attText);
  -                     Transport.send(msg);
  -                     System.out.println("Mail sent successfully!!");
  -             }
  -             catch (UnknownHostException e1)
  -             {
  -                     System.out.println("NxError:Invalid Mail Server " + e1);
  -                     System.exit(1);
  -             }
  -             catch (Exception e)
  -             {
  -                     e.printStackTrace();
  -                     System.exit(1);
  -             }
  -     }
   }
  
  
  
  1.12      +5 -3      
jakarta-jmeter/src/org/apache/jmeter/visualizers/ViewResultsVisualizer.java
  
  Index: ViewResultsVisualizer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/visualizers/ViewResultsVisualizer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ViewResultsVisualizer.java        2001/03/17 22:26:00     1.11
  +++ ViewResultsVisualizer.java        2001/07/15 17:01:05     1.12
  @@ -60,6 +60,7 @@
   import javax.swing.*;
   import org.apache.jmeter.reporters.ResultCollector;
   import org.apache.jmeter.gui.*;
  +import org.apache.jmeter.samplers.Clearable;
   
   /************************************************************
    *  Allows the tester to view the textual response from sampling an Entry. This
  @@ -67,10 +68,10 @@
    *  "Continue" button.
    *
    *@author     $Author: mstover1 $
  - *@created    $Date: 2001/03/17 22:26:00 $
  - *@version    $Revision: 1.11 $ $Date: 2001/03/17 22:26:00 $
  + *@created    $Date: 2001/07/15 17:01:05 $
  + *@version    $Revision: 1.12 $ $Date: 2001/07/15 17:01:05 $
    ***********************************************************/
  -public class ViewResultsVisualizer extends JPanel implements ModelSupported, 
ActionListener
  +public class ViewResultsVisualizer extends JPanel implements ModelSupported, 
ActionListener,Clearable
   {
   
   
  @@ -151,6 +152,7 @@
        public void actionPerformed(ActionEvent e)
        {
                label.setText("");
  +             model.next();
                updateGui();
        }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to