1 10 11 package org.mule.providers; 12 13 import javax.resource.spi.work.Work ; 14 import javax.resource.spi.work.WorkException ; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.mule.MuleManager; 19 import org.mule.umo.provider.UMOConnectable; 20 import org.mule.umo.provider.UMOMessageReceiver; 21 22 25 public abstract class AbstractConnectionStrategy implements ConnectionStrategy 26 { 27 30 protected transient Log logger = LogFactory.getLog(getClass()); 31 32 private volatile boolean doThreading = false; 33 34 public final void connect(final UMOConnectable connectable) throws FatalConnectException 35 { 36 if (doThreading) 37 { 38 try 39 { 40 MuleManager.getInstance().getWorkManager().scheduleWork(new Work () 41 { 42 public void release() 43 { 44 } 46 47 public void run() 48 { 49 try 50 { 51 synchronized (this) 52 { 53 doConnect(connectable); 54 } 55 } 56 catch (FatalConnectException e) 57 { 58 synchronized (this) 59 { 60 resetState(); 61 } 62 if (connectable instanceof AbstractMessageReceiver) 64 { 65 ((AbstractMessageReceiver)connectable).handleException(e); 66 } 67 } 68 } 69 }); 70 } 71 catch (WorkException e) 72 { 73 synchronized (this) 74 { 75 resetState(); 76 } 77 throw new FatalConnectException(e, connectable); 78 } 79 } 80 else 81 { 82 try 83 { 84 synchronized (this) 85 { 86 doConnect(connectable); 87 } 88 } 89 finally 90 { 91 synchronized (this) 92 { 93 resetState(); 94 } 95 } 96 } 97 } 98 99 public boolean isDoThreading() 100 { 101 return doThreading; 102 } 103 104 public void setDoThreading(boolean doThreading) 105 { 106 this.doThreading = doThreading; 107 } 108 109 public abstract void doConnect(UMOConnectable connectable) throws FatalConnectException; 110 111 114 public abstract void resetState(); 115 116 protected String getDescription(UMOConnectable connectable) 117 { 118 if (connectable instanceof UMOMessageReceiver) 119 { 120 return ((UMOMessageReceiver)connectable).getEndpointURI().toString(); 121 } 122 else 123 { 124 return connectable.toString(); 125 } 126 } 127 128 } 129 | Popular Tags |