Coverage Report - org.mule.module.management.mbean.EndpointService
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointService
0%
0/38
0%
0/24
1.769
 
 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.module.management.mbean;
 8  
 
 9  
 import org.mule.MessageExchangePattern;
 10  
 import org.mule.api.endpoint.ImmutableEndpoint;
 11  
 import org.mule.api.endpoint.InboundEndpoint;
 12  
 import org.mule.api.endpoint.OutboundEndpoint;
 13  
 import org.mule.api.transport.MessageReceiver;
 14  
 import org.mule.config.i18n.CoreMessages;
 15  
 import org.mule.util.ObjectNameHelper;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 
 20  
 /**
 21  
  * The EndpointServiceMBean allows you to check the confiugration of an endpoint and
 22  
  * conect/disconnect endpoints manually.
 23  
  */
 24  
 public class EndpointService implements EndpointServiceMBean
 25  
 {
 26  
     /**
 27  
      * logger used by this class
 28  
      */
 29  0
     protected transient Log logger = LogFactory.getLog(getClass());
 30  
 
 31  
     private ImmutableEndpoint endpoint;
 32  
     private MessageReceiver receiver;
 33  
     private String name;
 34  
     private String componentName;
 35  
 
 36  
     public EndpointService(ImmutableEndpoint endpoint)
 37  0
     {
 38  0
         this.endpoint = endpoint;
 39  0
         init();
 40  0
     }
 41  
 
 42  
     public EndpointService(MessageReceiver receiver)
 43  0
     {
 44  0
         if (receiver == null)
 45  
         {
 46  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("Receiver").getMessage());
 47  
         }
 48  0
         this.endpoint = receiver.getEndpoint();
 49  0
         this.receiver = receiver;
 50  0
         this.componentName = receiver.getFlowConstruct().getName();
 51  0
         init();
 52  0
     }
 53  
 
 54  
     private void init()
 55  
     {
 56  0
         if (endpoint == null)
 57  
         {
 58  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("Endpoint").getMessage());
 59  
         }
 60  0
         if (receiver == null && endpoint instanceof InboundEndpoint)
 61  
         {
 62  0
             throw new IllegalArgumentException(
 63  
                 "Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint");
 64  
         }
 65  
 
 66  0
         name = new ObjectNameHelper(endpoint.getConnector().getMuleContext()).getEndpointName(endpoint.getEndpointURI());
 67  0
     }
 68  
 
 69  
     public String getAddress()
 70  
     {
 71  0
         return endpoint.getEndpointURI().getAddress();
 72  
     }
 73  
 
 74  
     public String getName()
 75  
     {
 76  0
         return name;
 77  
     }
 78  
 
 79  
     public boolean isConnected()
 80  
     {
 81  0
         return receiver == null || receiver.isConnected();
 82  
     }
 83  
 
 84  
     public void connect() throws Exception
 85  
     {
 86  0
         if (receiver != null && !receiver.isConnected())
 87  
         {
 88  0
             receiver.connect();
 89  
         }
 90  0
         else if (logger.isDebugEnabled())
 91  
         {
 92  0
             logger.debug("Endpoint is already connected");
 93  
         }
 94  0
     }
 95  
 
 96  
     public void disconnect() throws Exception
 97  
     {
 98  0
         if (receiver != null && receiver.isConnected())
 99  
         {
 100  0
             receiver.disconnect();
 101  
         }
 102  0
         else if (logger.isDebugEnabled())
 103  
         {
 104  0
             logger.debug("Endpoint is already disconnected");
 105  
         }
 106  0
     }
 107  
 
 108  
     public boolean isInbound()
 109  
     {
 110  0
         return endpoint instanceof InboundEndpoint;
 111  
     }
 112  
 
 113  
     public boolean isOutbound()
 114  
     {
 115  0
         return endpoint instanceof OutboundEndpoint;
 116  
     }
 117  
 
 118  
     public MessageExchangePattern getMessageExchangePattern()
 119  
     {
 120  0
         return endpoint.getExchangePattern();
 121  
     }
 122  
     
 123  
     public String getComponentName()
 124  
     {
 125  0
         return componentName;
 126  
     }
 127  
 
 128  
     public void setComponentName(String componentName)
 129  
     {
 130  0
         this.componentName = componentName;
 131  0
     }
 132  
 }