Coverage Report - org.mule.example.notifications.HeartbeatAgent
 
Classes in this File Line Coverage Branch Coverage Complexity
HeartbeatAgent
0%
0/15
N/A
0
HeartbeatAgent$Heartbeat
0%
0/9
N/A
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.example.notifications;
 8  
 
 9  
 import org.mule.AbstractAgent;
 10  
 import org.mule.api.DefaultMuleException;
 11  
 import org.mule.api.MuleException;
 12  
 import org.mule.api.lifecycle.InitialisationException;
 13  
 
 14  
 import javax.resource.spi.work.Work;
 15  
 import javax.resource.spi.work.WorkException;
 16  
 
 17  
 /**
 18  
  * A simple agent that fire {@link org.mule.example.notifications.HeartbeatNotification} events at a given frequency to
 19  
  * notify that the server is alive and well.
 20  
  */
 21  0
 public class HeartbeatAgent extends AbstractAgent
 22  
 {
 23  
     public static final String NAME = "Heartbeat";
 24  
 
 25  0
     private long frequency = 10000;
 26  
 
 27  
     public HeartbeatAgent()
 28  
     {
 29  0
         super(NAME);
 30  0
     }
 31  
 
 32  
     public long getFrequency()
 33  
     {
 34  0
         return frequency;
 35  
     }
 36  
 
 37  
     public void setFrequency(long frequency)
 38  
     {
 39  0
         this.frequency = frequency;
 40  0
     }
 41  
 
 42  
     public void initialise() throws InitialisationException
 43  
     {
 44  
         //No Op
 45  0
     }
 46  
 
 47  
     public void start() throws MuleException
 48  
     {
 49  
         try
 50  
         {
 51  0
             muleContext.getWorkManager().scheduleWork(new Heartbeat());
 52  
         }
 53  0
         catch (WorkException e)
 54  
         {
 55  0
             throw new DefaultMuleException(e);
 56  0
         }
 57  0
     }
 58  
 
 59  
     public void stop() throws MuleException
 60  
     {
 61  
         //No Op
 62  0
     }
 63  
 
 64  
     public void dispose()
 65  
     {
 66  
         //No Op
 67  0
     }
 68  
 
 69  0
     public class Heartbeat implements Work
 70  
     {
 71  
         public void release()
 72  
         {
 73  
             //No Op
 74  0
         }
 75  
 
 76  
         @SuppressWarnings("synthetic-access")
 77  
         public void run()
 78  
         {
 79  
             while(true)
 80  
             {
 81  0
                 muleContext.fireNotification(new HeartbeatNotification(muleContext));
 82  
                 try
 83  
                 {
 84  0
                     Thread.sleep(frequency);
 85  
                 }
 86  0
                 catch (InterruptedException e)
 87  
                 {
 88  0
                     Thread.currentThread().interrupt();
 89  0
                     break;
 90  0
                 }
 91  
             }
 92  0
         }
 93  
     }
 94  
 }