Coverage Report - org.mule.module.client.remoting.RemoteDispatcherAgent
 
Classes in this File Line Coverage Branch Coverage Complexity
RemoteDispatcherAgent
0%
0/31
0%
0/8
1.636
 
 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.client.remoting;
 8  
 
 9  
 import org.mule.AbstractAgent;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.endpoint.InboundEndpoint;
 12  
 import org.mule.api.lifecycle.InitialisationException;
 13  
 import org.mule.api.service.Service;
 14  
 import org.mule.api.transformer.wire.WireFormat;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.module.client.remoting.notification.RemoteDispatcherNotification;
 17  
 import org.mule.module.client.remoting.notification.RemoteDispatcherNotificationListener;
 18  
 import org.mule.transformer.wire.SerializedMuleMessageWireFormat;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 
 23  
 /**
 24  
  * <code>RemoteDispatcherAgent</code> manages the server endpoint that receives Admin and
 25  
  * remote client requests
 26  
  */
 27  
 public class RemoteDispatcherAgent extends AbstractAgent
 28  
 {
 29  
     public static final String AGENT_NAME = "RemoteDispatcherServer";
 30  
 
 31  
     /**
 32  
      * logger used by this class
 33  
      */
 34  0
     protected static final Log logger = LogFactory.getLog(RemoteDispatcherAgent.class);
 35  
 
 36  
     private WireFormat wireFormat;
 37  
 
 38  
     private InboundEndpoint endpoint;
 39  
 
 40  
 
 41  
     public RemoteDispatcherAgent()
 42  
     {
 43  0
         super(AGENT_NAME);
 44  0
     }
 45  
 
 46  
     /**
 47  
      * Should be a 1 line description of the agent
 48  
      */
 49  
     public String getDescription()
 50  
     {
 51  0
         return getName() + ": accepting connections on " + endpoint.getEndpointURI().getAddress();
 52  
     }
 53  
 
 54  
     public void start() throws MuleException
 55  
     {
 56  
         // nothing to do
 57  0
     }
 58  
 
 59  
     public void stop() throws MuleException
 60  
     {
 61  
         // nothing to do
 62  0
     }
 63  
 
 64  
     public void dispose()
 65  
     {
 66  
         // nothing to do
 67  0
     }
 68  
 
 69  
 
 70  
     public void initialise() throws InitialisationException
 71  
     {
 72  0
         if (endpoint == null)
 73  
         {
 74  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("remote-endpoint").getMessage());
 75  
         }
 76  
 
 77  0
         if (wireFormat == null)
 78  
         {
 79  0
             wireFormat = new SerializedMuleMessageWireFormat();
 80  
         }
 81  0
         wireFormat.setMuleContext(muleContext);
 82  
 
 83  
         
 84  
         //Register the Remote Dispatcher Notification support
 85  0
         muleContext.getNotificationManager().addInterfaceToType(
 86  
                 RemoteDispatcherNotificationListener.class,
 87  
                 RemoteDispatcherNotification.class);
 88  
 
 89  
         try
 90  
         {
 91  
             // Check for override
 92  0
             if (muleContext.getRegistry().lookupService(RemoteDispatcherComponent.MANAGER_COMPONENT_NAME) != null)
 93  
             {
 94  0
                 logger.info("Mule manager component has already been initialised, ignoring server url");
 95  
             }
 96  
             else
 97  
             {
 98  
 
 99  0
                 Service component = RemoteDispatcherComponent.getSerivce(endpoint, wireFormat,
 100  
                     muleContext.getConfiguration().getDefaultEncoding(), muleContext.getConfiguration()
 101  
                         .getDefaultResponseTimeout(), muleContext);
 102  0
                 muleContext.getRegistry().registerService(component);
 103  
             }
 104  
         }
 105  0
         catch (MuleException e)
 106  
         {
 107  0
             throw new InitialisationException(e, this);
 108  0
         }
 109  0
     }
 110  
 
 111  
     public String toString()
 112  
     {
 113  0
         String address = "not set";
 114  0
         if(endpoint!=null)
 115  
         {
 116  0
              address = endpoint.getEndpointURI().getAddress();
 117  
         }
 118  0
         return "RemoteDispatcherAgent{" + "remote-endpoint='" + address + "'" + "}";
 119  
     }
 120  
 
 121  
     public WireFormat getWireFormat()
 122  
     {
 123  0
         return wireFormat;
 124  
     }
 125  
 
 126  
     public void setWireFormat(WireFormat wireFormat)
 127  
     {
 128  0
         this.wireFormat = wireFormat;
 129  0
     }
 130  
 
 131  
     public InboundEndpoint getEndpoint()
 132  
     {
 133  0
         return endpoint;
 134  
     }
 135  
 
 136  
     public void setEndpoint(InboundEndpoint endpoint)
 137  
     {
 138  0
         this.endpoint = endpoint;
 139  0
     }
 140  
 }