/**
   * Adds Synapse Service to Axis2 configuration which enables the main message mediation.
   *
   * @throws AxisFault if an error occurs during Axis2 service initialization
   */
  private void deploySynapseService() throws AxisFault {

    log.info("Deploying the Synapse service...");
    // Dynamically initialize the Synapse Service and deploy it into Axis2
    AxisConfiguration axisCfg = configurationContext.getAxisConfiguration();
    AxisService synapseService = new AxisService(SynapseConstants.SYNAPSE_SERVICE_NAME);
    AxisOperation mediateOperation =
        new InOutAxisOperation(SynapseConstants.SYNAPSE_OPERATION_NAME);
    mediateOperation.setMessageReceiver(new SynapseMessageReceiver());
    synapseService.addOperation(mediateOperation);
    List<String> transports = new ArrayList<String>();
    transports.add(Constants.TRANSPORT_HTTP);
    transports.add(Constants.TRANSPORT_HTTPS);
    synapseService.setExposedTransports(transports);
    AxisServiceGroup synapseServiceGroup = new AxisServiceGroup(axisCfg);
    synapseServiceGroup.setServiceGroupName(SynapseConstants.SYNAPSE_SERVICE_NAME);
    synapseServiceGroup.addParameter(SynapseConstants.HIDDEN_SERVICE_PARAM, "true");
    synapseServiceGroup.addService(synapseService);
    axisCfg.addServiceGroup(synapseServiceGroup);
  }
  private ServerContextInformation initESB(
      String configurationName, ConfigurationContext configurationContext) throws AxisFault {
    ServerConfigurationInformation configurationInformation =
        ServerConfigurationInformationFactory.createServerConfigurationInformation(
            configurationContext.getAxisConfiguration());
    // ability to specify the SynapseServerName as a system property
    if (System.getProperty("SynapseServerName") != null) {
      configurationInformation.setServerName(System.getProperty("SynapseServerName"));
    }

    // for now we override the default configuration location with the value in registry
    String repoPath = configurationContext.getAxisConfiguration().getRepository().getPath();
    configurationInformation.setSynapseXMLLocation(
        repoPath
            + File.separator
            + ServiceBusConstants.SYNAPSE_CONFIGS
            + File.separator
            + configurationName);

    configurationInformation.setCreateNewInstance(false);
    configurationInformation.setServerControllerProvider(CarbonSynapseController.class.getName());
    if (isRunningSamplesMode()) {
      configurationInformation.setSynapseXMLLocation(
          "repository"
              + File.separator
              + "samples"
              + File.separator
              + "synapse_sample_"
              + System.getProperty(ServiceBusConstants.ESB_SAMPLE_SYSTEM_PROPERTY)
              + ".xml");
    }

    ServerManager serverManager = new ServerManager();
    ServerContextInformation contextInfo =
        new ServerContextInformation(configurationContext, configurationInformation);

    /*if (dataSourceInformationRepositoryService != null) {
        DataSourceInformationRepository repository =
                dataSourceInformationRepositoryService.getDataSourceInformationRepository();
        contextInfo.addProperty(DataSourceConstants.DATA_SOURCE_INFORMATION_REPOSITORY,
                repository);
    }*/

    TaskScheduler scheduler;
    if (configurationContext.getProperty(ServiceBusConstants.CARBON_TASK_SCHEDULER) == null) {
      scheduler = new TaskScheduler(TaskConstants.TASK_SCHEDULER);
      configurationContext.setProperty(ServiceBusConstants.CARBON_TASK_SCHEDULER, scheduler);
    } else {
      scheduler =
          (TaskScheduler)
              configurationContext.getProperty(ServiceBusConstants.CARBON_TASK_SCHEDULER);
    }
    contextInfo.addProperty(TaskConstants.TASK_SCHEDULER, scheduler);

    TaskDescriptionRepository repository;
    if (configurationContext.getProperty(ServiceBusConstants.CARBON_TASK_REPOSITORY) == null) {
      repository = new TaskDescriptionRepository();
      configurationContext.setProperty(ServiceBusConstants.CARBON_TASK_REPOSITORY, repository);
    } else {
      repository =
          (TaskDescriptionRepository)
              configurationContext.getProperty(ServiceBusConstants.CARBON_TASK_REPOSITORY);
    }
    contextInfo.addProperty(TaskConstants.TASK_DESCRIPTION_REPOSITORY, repository);

    /* if (secretCallbackHandlerService != null) {
        contextInfo.addProperty(SecurityConstants.PROP_SECRET_CALLBACK_HANDLER,
                secretCallbackHandlerService.getSecretCallbackHandler());
    }*/

    AxisConfiguration axisConf = configurationContext.getAxisConfiguration();
    axisConf.addParameter(
        new Parameter(ServiceBusConstants.SYNAPSE_CURRENT_CONFIGURATION, configurationName));

    serverManager.init(configurationInformation, contextInfo);
    serverManager.start();

    AxisServiceGroup serviceGroup = axisConf.getServiceGroup(SynapseConstants.SYNAPSE_SERVICE_NAME);
    serviceGroup.addParameter("hiddenService", "true");

    addDeployers(configurationContext);

    return contextInfo;
  }
  public void execute(ConfigurationContext configContext) throws ClusteringFault {
    AxisConfiguration axisConfig = configContext.getAxisConfiguration();

    // Run this code only if this node is not already initialized
    if (configContext.getPropertyNonReplicable(ClusteringConstants.RECD_CONFIG_INIT_MSG) == null) {
      log.info("Received configuration initialization message");
      configContext.setNonReplicableProperty(ClusteringConstants.RECD_CONFIG_INIT_MSG, "true");
      if (serviceGroups != null) {

        // Load all the service groups that are sent by the neighbour
        for (int i = 0; i < serviceGroups.length; i++) {
          String serviceGroup = serviceGroups[i];
          if (axisConfig.getServiceGroup(serviceGroup) == null) {
            // Load the service group
            try {
              ClusteringUtils.loadServiceGroup(
                  serviceGroup,
                  configContext,
                  System.getProperty(
                      "axis2.work.dir")); // TODO: Introduce a constant. work dir is a temp dir.
            } catch (FileNotFoundException ignored) {
            } catch (Exception e) {
              throw new ClusteringFault(e);
            }
          }
        }

        // TODO: We support only AAR files for now

        // Unload all service groups which were not sent by the neighbour,
        // but have been currently loaded
        for (Iterator iter = axisConfig.getServiceGroups(); iter.hasNext(); ) {
          AxisServiceGroup serviceGroup = (AxisServiceGroup) iter.next();
          boolean foundServiceGroup = false;
          for (int i = 0; i < serviceGroups.length; i++) {
            String serviceGroupName = serviceGroups[i];
            if (serviceGroup.getServiceGroupName().equals(serviceGroupName)) {
              foundServiceGroup = true;
              break;
            }
          }
          if (!foundServiceGroup) {
            boolean mustUnloadServiceGroup = true;
            // Verify that this service was not loaded from within a module
            // If so, we must not unload such a service
            for (Iterator serviceIter = serviceGroup.getServices(); serviceIter.hasNext(); ) {
              AxisService service = (AxisService) serviceIter.next();
              if (service.isClientSide()
                  || service.getParameter(AxisModule.MODULE_SERVICE)
                      != null) { // Do not unload service groups containing client side services or
                                 // ones deployed from within modules
                mustUnloadServiceGroup = false;
                break;
              }
            }
            if (mustUnloadServiceGroup) {
              try {
                axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
              } catch (Exception e) {
                throw new ClusteringFault(e);
              }
            }
          }
        }
      }
    }
  }