/** Destroys the Synapse Environment by undeploying all Axis2 services. */
 public void destroySynapseEnvironment() {
   if (synapseEnvironment != null) {
     try {
       undeploySynapseService();
       undeployProxyServices();
       undeployEventSources();
     } catch (AxisFault e) {
       handleFatal("Error while shutting down the Synapse environment", e);
     }
     synapseEnvironment.setInitialized(false);
   }
 }
  /**
   * Setup synapse in axis2 environment and return the created instance.
   *
   * @return SynapseEnvironment instance
   */
  public SynapseEnvironment createSynapseEnvironment() {

    try {
      deployMediationLibraryArtifacts();
      deployMediatorExtensions();
      deploySynapseService();
      deployProxyServices();
      deployEventSources();
      // deployMediatorExtensions();
    } catch (AxisFault axisFault) {
      log.fatal("Synapse startup failed...", axisFault);
      throw new SynapseException("Synapse startup failed", axisFault);
    }

    synapseEnvironment =
        new Axis2SynapseEnvironment(
            configurationContext, synapseConfiguration, serverContextInformation);
    MessageContextCreatorForAxis2.setSynEnv(synapseEnvironment);

    Parameter synapseEnvironmentParameter =
        new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    try {
      configurationContext.getAxisConfiguration().addParameter(synapseEnvironmentParameter);
    } catch (AxisFault e) {
      handleFatal(
          "Could not set parameter '"
              + SynapseConstants.SYNAPSE_ENV
              + "' to the Axis2 configuration : "
              + e.getMessage(),
          e);
    }

    synapseEnvironment.getTaskManager().init(taskDescriptionRepository, taskScheduler);
    synapseConfiguration.init(synapseEnvironment);
    synapseEnvironment.setInitialized(true);

    return synapseEnvironment;
  }