Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/10 22:16:04 (14 years ago)
Author:
kgrading
Message:

#828 added various improvements to the plugin cache manager, the execution engine, the transaction handling on the serverside and the server console

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/sources/HeuristicLab.Hive.Server/3.2/ServiceCallInterception.cs

    r3931 r4042  
    99using HeuristicLab.Hive.Contracts;
    1010using HeuristicLab.Tracing;
     11using System.Reflection;
     12using HeuristicLab.Hive.Server.Core;
    1113
    1214namespace HeuristicLab.Hive.Server {
    1315  internal class ServiceCallInterception : IMethodInterceptor {
    14 
    1516    private const bool UseTransactions = true;
    1617
    1718    public object Invoke(IMethodInvocation invocation) {
     19      bool userTransaction = false;
     20
    1821      DateTime start = DateTime.Now;
    1922      Logger.Info("Entering Method: " + invocation.Method.Name);
    2023
    21       if(!ContextFactory.IsContextNull()) {
     24      if (!ContextFactory.IsContextNull()) {
    2225        Logger.Info("Not null context found - why wasn't this disposed?");
    2326        try {
    2427          Logger.Info("Trying to dispose");
    2528          ContextFactory.Context.Dispose();
    26         } catch (Exception e) {
     29        }
     30        catch (Exception e) {
    2731          Logger.Error(e);
    2832        }
     
    3034      }
    3135      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());
    3338      Object obj = null;
    3439
    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})) {
    7250          try {
    73             obj = invocation.Proceed();           
     51            Logger.Debug("Current Transaction Isolation level is: " + Transaction.Current.IsolationLevel);
     52            obj = invocation.Proceed();
     53            scope.Complete();
    7454          }
    7555          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);
    7758          }
    7859          finally {
     
    8162            ContextFactory.Context = null;
    8263            Logger.Debug("Set Context Null");
    83           } 
     64          }
    8465        }
     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      }
    8581      //}       
    8682      TimeSpan ts = DateTime.Now - start;
    8783      if (ts.Seconds > 2) {
    8884        Logger.Warn("Invocation took: " + ts);
    89       } else if (ts.Seconds > 10) {
     85      }
     86      else if (ts.Seconds > 10) {
    9087        Logger.Error("Invocation took: " + ts);
    91       } else {
    92         Logger.Info("Invocation took: " + ts); ;
     88      }
     89      else {
     90        Logger.Info("Invocation took: " + ts);
     91        ;
    9392      }
    9493      Logger.Info("Leaving Method: " + invocation.Method.Name);
    95      
     94
    9695      return obj;
    9796    }
    9897  }
    9998}
    100      
    101  
Note: See TracChangeset for help on using the changeset viewer.