Coverage Report - org.mule.management.mbeans.EndpointService
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointService
0%
0/37
0%
0/24
1.833
 
 1  
 /*
 2  
  * $Id: EndpointService.java 9179 2007-10-17 09:15:12Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.management.mbeans;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.umo.endpoint.UMOEndpoint;
 15  
 import org.mule.umo.provider.UMOMessageReceiver;
 16  
 import org.mule.util.ObjectNameHelper;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 /**
 22  
  * The EndpointServiceMBean allows you to check the confiugration of an endpoint and
 23  
  * conect/disconnect endpoints manually.
 24  
  */
 25  
 public class EndpointService implements EndpointServiceMBean
 26  
 {
 27  
     /**
 28  
      * logger used by this class
 29  
      */
 30  0
     protected transient Log logger = LogFactory.getLog(getClass());
 31  
 
 32  
     private UMOEndpoint endpoint;
 33  
     private UMOMessageReceiver receiver;
 34  
     private String name;
 35  
     private String componentName;
 36  
 
 37  
     public EndpointService(UMOEndpoint endpoint)
 38  0
     {
 39  0
         this.endpoint = endpoint;
 40  0
         init();
 41  0
     }
 42  
 
 43  
     public EndpointService(UMOMessageReceiver receiver)
 44  0
     {
 45  0
         if (receiver == null)
 46  
         {
 47  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("Receiver").getMessage());
 48  
         }
 49  0
         this.endpoint = receiver.getEndpoint();
 50  0
         this.receiver = receiver;
 51  0
         this.componentName = receiver.getComponent().getDescriptor().getName();
 52  0
         init();
 53  0
     }
 54  
 
 55  
     private void init()
 56  
     {
 57  0
         if (endpoint == null)
 58  
         {
 59  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("Endpoint").getMessage());
 60  
         }
 61  0
         if (receiver == null && UMOEndpoint.ENDPOINT_TYPE_RECEIVER.equals(endpoint.getType()))
 62  
         {
 63  0
             throw new IllegalArgumentException(
 64  
                 "Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint");
 65  
         }
 66  
 
 67  0
         name = ObjectNameHelper.getEndpointName(endpoint);
 68  0
     }
 69  
 
 70  
     public String getAddress()
 71  
     {
 72  0
         return endpoint.getEndpointURI().getAddress();
 73  
     }
 74  
 
 75  
     public String getName()
 76  
     {
 77  0
         return name;
 78  
     }
 79  
 
 80  
     public boolean isConnected()
 81  
     {
 82  0
         return receiver == null || receiver.isConnected();
 83  
     }
 84  
 
 85  
     public void connect() throws Exception
 86  
     {
 87  0
         if (receiver != null && !receiver.isConnected())
 88  
         {
 89  0
             receiver.connect();
 90  
         }
 91  0
         else if (logger.isDebugEnabled())
 92  
         {
 93  0
             logger.debug("Endpoint is already connected");
 94  
         }
 95  0
     }
 96  
 
 97  
     public void disconnect() throws Exception
 98  
     {
 99  0
         if (receiver != null && receiver.isConnected())
 100  
         {
 101  0
             receiver.disconnect();
 102  
         }
 103  0
         else if (logger.isDebugEnabled())
 104  
         {
 105  0
             logger.debug("Endpoint is already disconnected");
 106  
         }
 107  0
     }
 108  
 
 109  
     public boolean isSynchronous()
 110  
     {
 111  0
         return endpoint.isSynchronous();
 112  
     }
 113  
 
 114  
     public String getType()
 115  
     {
 116  0
         return endpoint.getType();
 117  
     }
 118  
 
 119  
     public String getComponentName()
 120  
     {
 121  0
         return componentName;
 122  
     }
 123  
 
 124  
     public void setComponentName(String componentName)
 125  
     {
 126  0
         this.componentName = componentName;
 127  0
     }
 128  
 
 129  
 }