- Timestamp:
- 07/18/10 22:16:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/sources/HeuristicLab.Hive.Server/3.2/ServiceCallInterception.cs
r3931 r4042 9 9 using HeuristicLab.Hive.Contracts; 10 10 using HeuristicLab.Tracing; 11 using System.Reflection; 12 using HeuristicLab.Hive.Server.Core; 11 13 12 14 namespace HeuristicLab.Hive.Server { 13 15 internal class ServiceCallInterception : IMethodInterceptor { 14 15 16 private const bool UseTransactions = true; 16 17 17 18 public object Invoke(IMethodInvocation invocation) { 19 bool userTransaction = false; 20 18 21 DateTime start = DateTime.Now; 19 22 Logger.Info("Entering Method: " + invocation.Method.Name); 20 23 21 if (!ContextFactory.IsContextNull()) {24 if (!ContextFactory.IsContextNull()) { 22 25 Logger.Info("Not null context found - why wasn't this disposed?"); 23 26 try { 24 27 Logger.Info("Trying to dispose"); 25 28 ContextFactory.Context.Dispose(); 26 } catch (Exception e) { 29 } 30 catch (Exception e) { 27 31 Logger.Error(e); 28 32 } … … 30 34 } 31 35 Logger.Info("Context info: Timeout: " + ContextFactory.Context.Connection.ConnectionTimeout + " | " + 32 ContextFactory.Context.Connection.State + " | Conn: " + ContextFactory.Context + " | HashCode is: " + ContextFactory.Context.Connection.GetHashCode()); 36 ContextFactory.Context.Connection.State + " | Conn: " + ContextFactory.Context + " | HashCode is: " + 37 ContextFactory.Context.Connection.GetHashCode()); 33 38 Object obj = null; 34 39 35 /*if (invocation.Method.Name.Equals("SendStreamedJob") || invocation.Method.Name.Equals("StoreFinishedJobResultStreamed")) { 36 ContextFactory.Context.Connection.Open(); 37 if(UseTransactions) { 38 Logger.Debug("Opening Transaction"); 39 ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction(ApplicationConstants.ISOLATION_LEVEL); 40 } else { 41 Logger.Debug("Not using a Transaction"); 42 } 43 try { 44 obj = invocation.Proceed(); 45 Logger.Info("leaving context open for streaming"); 46 } 47 catch (Exception e) { 48 Logger.Error("Exception occured during method invocation", e); 49 ContextFactory.Context.Dispose(); 50 ContextFactory.Context = null; 51 } 52 } else { */ 53 if(UseTransactions) { 54 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE })) { 55 try { 56 Logger.Debug("Current Transaction Isolation level is: " + Transaction.Current.IsolationLevel); 57 obj = invocation.Proceed(); 58 scope.Complete(); 59 } 60 catch (Exception e) { 61 Logger.Error("Exception occured during method invocation", e); 62 Logger.Error("Inner Exception: ", e.InnerException); 63 } 64 finally { 65 ContextFactory.Context.Dispose(); 66 Logger.Debug("Disposed Context"); 67 ContextFactory.Context = null; 68 Logger.Debug("Set Context Null"); 69 } 70 } 71 } else { 40 Object[] attributes = invocation.Method.GetCustomAttributes(typeof (SpringTransaction), true); 41 foreach (Object o in attributes) { 42 SpringTransaction st = (SpringTransaction) o; 43 userTransaction = st.UserTransaction; 44 } 45 if (UseTransactions && !userTransaction) { 46 using ( 47 TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, 48 new TransactionOptions 49 {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})) { 72 50 try { 73 obj = invocation.Proceed(); 51 Logger.Debug("Current Transaction Isolation level is: " + Transaction.Current.IsolationLevel); 52 obj = invocation.Proceed(); 53 scope.Complete(); 74 54 } 75 55 catch (Exception e) { 76 Logger.Error("Exception occured during method invocation", e); 56 Logger.Error("Exception occured during method invocation", e); 57 Logger.Error("Inner Exception: ", e.InnerException); 77 58 } 78 59 finally { … … 81 62 ContextFactory.Context = null; 82 63 Logger.Debug("Set Context Null"); 83 } 64 } 84 65 } 66 } 67 else { 68 try { 69 obj = invocation.Proceed(); 70 } 71 catch (Exception e) { 72 Logger.Error("Exception occured during method invocation", e); 73 } 74 finally { 75 ContextFactory.Context.Dispose(); 76 Logger.Debug("Disposed Context"); 77 ContextFactory.Context = null; 78 Logger.Debug("Set Context Null"); 79 } 80 } 85 81 //} 86 82 TimeSpan ts = DateTime.Now - start; 87 83 if (ts.Seconds > 2) { 88 84 Logger.Warn("Invocation took: " + ts); 89 } else if (ts.Seconds > 10) { 85 } 86 else if (ts.Seconds > 10) { 90 87 Logger.Error("Invocation took: " + ts); 91 } else { 92 Logger.Info("Invocation took: " + ts); ; 88 } 89 else { 90 Logger.Info("Invocation took: " + ts); 91 ; 93 92 } 94 93 Logger.Info("Leaving Method: " + invocation.Method.Name); 95 94 96 95 return obj; 97 96 } 98 97 } 99 98 } 100 101
Note: See TracChangeset
for help on using the changeset viewer.