Coverage Report - org.mule.module.launcher.application.ApplicationWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationWrapper
0%
0/45
0%
0/8
0
 
 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.launcher.application;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.module.launcher.DeploymentStartException;
 11  
 import org.mule.module.launcher.InstallException;
 12  
 import org.mule.module.launcher.descriptor.ApplicationDescriptor;
 13  
 
 14  
 import java.io.IOException;
 15  
 
 16  
 /**
 17  
  * Decorates the target deployer to properly switch out context classloader for deployment
 18  
  * one where applicable. E.g. init() phase may load custom classes for an application, which
 19  
  * must be executed with deployment (app) classloader in the context, and not Mule system
 20  
  * classloader.
 21  
  */
 22  
 public class ApplicationWrapper implements Application
 23  
 {
 24  
 
 25  
     private Application delegate;
 26  
 
 27  
     protected ApplicationWrapper(Application delegate) throws IOException
 28  0
     {
 29  0
         this.delegate = delegate;
 30  0
     }
 31  
 
 32  
     public void dispose()
 33  
     {
 34  
         // moved wrapper logic into the actual implementation, as redeploy() invokes it directly, bypassing
 35  
         // classloader cleanup
 36  0
         delegate.dispose();
 37  0
     }
 38  
 
 39  
     public ClassLoader getDeploymentClassLoader()
 40  
     {
 41  0
         return delegate.getDeploymentClassLoader();
 42  
     }
 43  
 
 44  
     public MuleContext getMuleContext()
 45  
     {
 46  0
         return delegate.getMuleContext();
 47  
     }
 48  
 
 49  
     public void init()
 50  
     {
 51  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 52  
         try
 53  
         {
 54  0
             ClassLoader appCl = getDeploymentClassLoader();
 55  
             // if not initialized yet, it can be null
 56  0
             if (appCl != null)
 57  
             {
 58  0
                 Thread.currentThread().setContextClassLoader(appCl);
 59  
             }
 60  0
             delegate.init();
 61  
         }
 62  
         finally
 63  
         {
 64  0
             Thread.currentThread().setContextClassLoader(originalCl);
 65  0
         }
 66  0
     }
 67  
 
 68  
     public void install() throws InstallException
 69  
     {
 70  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 71  
         try
 72  
         {
 73  0
             ClassLoader appCl = getDeploymentClassLoader();
 74  
             // if not initialized yet, it can be null
 75  0
             if (appCl != null)
 76  
             {
 77  0
                 Thread.currentThread().setContextClassLoader(appCl);
 78  
             }
 79  0
             delegate.install();
 80  
         }
 81  
         finally
 82  
         {
 83  0
             Thread.currentThread().setContextClassLoader(originalCl);
 84  0
         }
 85  0
     }
 86  
 
 87  
     public void redeploy()
 88  
     {
 89  0
         delegate.redeploy();
 90  0
     }
 91  
 
 92  
     public void start() throws DeploymentStartException
 93  
     {
 94  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 95  
         try
 96  
         {
 97  0
             ClassLoader appCl = getDeploymentClassLoader();
 98  
             // if not initialized yet, it can be null
 99  0
             if (appCl != null)
 100  
             {
 101  0
                 Thread.currentThread().setContextClassLoader(appCl);
 102  
             }
 103  0
             delegate.start();
 104  
         }
 105  
         finally
 106  
         {
 107  0
             Thread.currentThread().setContextClassLoader(originalCl);
 108  0
         }
 109  0
     }
 110  
 
 111  
     public void stop()
 112  
     {
 113  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 114  
         try
 115  
         {
 116  0
             ClassLoader appCl = getDeploymentClassLoader();
 117  
             // if not initialized yet, it can be null
 118  0
             if (appCl != null)
 119  
             {
 120  0
                 Thread.currentThread().setContextClassLoader(appCl);
 121  
             }
 122  0
             delegate.stop();
 123  
         }
 124  
         finally
 125  
         {
 126  0
             Thread.currentThread().setContextClassLoader(originalCl);
 127  0
         }
 128  0
     }
 129  
 
 130  
     public String getAppName()
 131  
     {
 132  0
         return delegate.getAppName();
 133  
     }
 134  
 
 135  
     public ApplicationDescriptor getDescriptor()
 136  
     {
 137  0
         return delegate.getDescriptor();
 138  
     }
 139  
 
 140  
     @Override
 141  
     public String toString()
 142  
     {
 143  0
         return String.format("%s(%s)", getClass().getName(), delegate);
 144  
     }
 145  
 
 146  
     public Application getDelegate()
 147  
     {
 148  0
         return delegate;
 149  
     }
 150  
 }