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