String serviceName)
{
// Declare countdown latch and listener
final CountDownLatch latch = new CountDownLatch(1);
SystemExceptionHandler listener = null;
MessagingExceptionHandler messagingListener = null;
MuleClient muleClient = p.getMuleClient();
boolean localMuleClient = muleClient == null;
SystemExceptionHandler currentExceptionListener = null;
MessagingExceptionHandler currentMessagingListener = null;
final ValueHolder<Exception> exceptionHolder = new ValueHolder<Exception>();
try
{
// First create a local muleClient instance if not supplied
if (localMuleClient) muleClient = new MuleClient(muleContext);
// Next create a listener that listens for exception on the
// sftp-connector
listener = new SystemExceptionHandler()
{
public void handleException(Exception e, RollbackMethod rollbackMethod)
{
exceptionHolder.value = e;
if (logger.isDebugEnabled())
logger.debug("Expected exception occurred: " + e.getMessage()
+ ", time to countdown the latch");
latch.countDown();
}
public void handleException(Exception exception)
{
handleException(exception, null);
}
};
messagingListener = new MessagingExceptionHandler()
{
public MuleEvent handleException(Exception e, MuleEvent event, RollbackMethod rollbackMethod)
{
exceptionHolder.value = e;
if (logger.isDebugEnabled())