/// <summary> /// Create broker /// </summary> /// <param name="startInfo">indicating the session start information</param> /// <param name="sessionId">indicating the session id</param> /// <param name="targetTimeout">indicating the target timeout</param> /// <param name="eprs">indicating the broker epr list</param> /// <param name="attached">indicating whether it is attaching</param> /// <param name="binding">indicating the binding</param> /// <returns>returns the broker initialization result</returns> private Task <SessionBase> CreateBrokerInternal(SessionStartInfo startInfo, string sessionId, bool attached, Binding binding) { InprocBrokerAdapter adapter = new InprocBrokerAdapter(startInfo, attached, startInfo.DebugModeEnabled, binding); BrokerInitializationResult result; if (this.durable) { result = adapter.CreateDurable(startInfo.Data, sessionId); } else { result = adapter.Create(startInfo.Data, sessionId); } SessionInfo info = SessionBase.BuildSessionInfo(result, this.durable, sessionId, String.Empty, startInfo.Data.ServiceVersion, startInfo); info.InprocessBrokerAdapter = adapter; SessionBase session; if (this.durable) { session = new DurableSession(info, startInfo.Headnode, null); } else { session = new V3Session(info, startInfo.Headnode, startInfo.ShareSession, null); } InprocessSessions.GetInstance().AddSession(session, startInfo); #if net40 return(TaskEx.FromResult(session)); #else return(Task.FromResult(session)); #endif }
/// <summary> /// Create broker /// </summary> /// <param name="startInfo">indicating the session start information</param> /// <param name="sessionId">indicating the session id</param> /// <param name="targetTimeout">indicating the target timeout</param> /// <param name="eprs">indicating the broker epr list</param> /// <param name="epr">output selected epr</param> /// <param name="binding">indicting the binding</param> /// <returns>returns the session information</returns> public async Task <SessionBase> CreateBroker(SessionStartInfo startInfo, string sessionId, DateTime targetTimeout, string[] eprs, Binding binding) { Exception innerException = null; IEnumerable <string> endpoints = eprs; if (startInfo.UseAzureQueue.GetValueOrDefault() && !endpoints.Contains(SessionInternalConstants.BrokerConnectionStringToken)) { endpoints = endpoints.Concat(new[] { SessionInternalConstants.BrokerConnectionStringToken }); } foreach (string epr in endpoints) { TimeSpan timeout = SessionBase.GetTimeout(targetTimeout); IBrokerLauncher brokerLauncher = null; try { SessionBase.TraceSource.TraceInformation("[Session:{0}] Try to create broker... BrokerLauncherEpr = {1}", sessionId, epr); void RenewBrokerLauncherClient() { if (epr == SessionInternalConstants.BrokerConnectionStringToken) { brokerLauncher = new BrokerLauncherCloudQueueClient(startInfo.BrokerLauncherStorageConnectionString); } else { var client = new BrokerLauncherClient(new Uri(epr), startInfo, binding); client.InnerChannel.OperationTimeout = timeout; brokerLauncher = client; } } RenewBrokerLauncherClient(); BrokerInitializationResult result = null; int retry = 20; while (retry > 0) { try { if (this.durable) { result = brokerLauncher.CreateDurable(startInfo.Data, sessionId); } else { result = brokerLauncher.Create(startInfo.Data, sessionId); } break; } catch (Exception ex) { if (retry <= 0) { throw; } retry--; Debug.WriteLine($"Waiting for Broker Launcher running. Detail: {ex.Message}"); await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false); RenewBrokerLauncherClient(); } } Debug.Assert(result != null); SessionBase.TraceSource.TraceInformation("[Session:{0}] Succesfully created broker.", sessionId); SessionInfo info = SessionBase.BuildSessionInfo(result, this.durable, sessionId, epr, startInfo.Data.ServiceVersion, startInfo); if (this.durable) { #if net40 return(new DurableSession(info, startInfo.Headnode, binding)); #else return(new DurableSession(info, startInfo.Headnode, binding)); #endif } else { var session = new V3Session(info, startInfo.Headnode, startInfo.ShareSession, binding); if (startInfo.UseAzureStorage) { session.BrokerLauncherClient = brokerLauncher; } return(session); } } catch (FaultException <SessionFault> e) { SessionBase.TraceSource.TraceEvent(TraceEventType.Warning, 0, "[Session:{0}] Fault exception occured while creating broker: {1}. FaultCode = {2}", sessionId, e, e.Detail.Code); switch (e.Detail.Code) { // Continue if current broker node is being taken offline case SOAFaultCode.Broker_BrokerIsOffline: continue; } throw Utility.TranslateFaultException(e); } catch (TimeoutException te) { SessionBase.TraceSource.TraceEvent(TraceEventType.Error, 0, "[Session:{0}] TimeoutException occured while creating broker: {1}", sessionId, te); // don't continue when we timeout throw new TimeoutException(string.Format(SR.ConectBrokerLauncherTimeout, epr, Constant.DefaultCreateSessionTimeout), te); } catch (CommunicationException ex) { SessionBase.TraceSource.TraceEvent(TraceEventType.Warning, 0, "[Session:{0}] Failed to create broker: {1}", sessionId, ex); innerException = ex; SessionBase.TraceSource.TraceInformation(ex.ToString()); continue; } finally { var client = brokerLauncher as BrokerLauncherClient; if (client != null) { Utility.SafeCloseCommunicateObject(client); } } } SessionBase.TraceSource.TraceEvent(TraceEventType.Error, 0, "[Session:{0}] Failed to create broker after trying all available eprs.", sessionId); throw new SessionException(SR.NoBrokerNodeFound, innerException); }
/// <summary> /// create the session shim based on a v3 session /// </summary> /// <param name="v2session"></param> internal HpcSession(V3Session v3session) : base(v3session) { }