void OnAcceptTransport(TransportAsyncCallbackArgs args) { Fx.Assert(args.Exception == null, "Should not be failed."); Fx.Assert(args.Transport != null, "Should have a transport"); AmqpConnectionSettings settings = this.connectionSettings.Clone(); settings.OnOpenCallback = this.OnReceiveConnectionOpen; AmqpConnection connection = null; try { connection = this.CreateConnection( args.Transport, (ProtocolHeader)args.UserToken, false, this.amqpSettings.Clone(), settings); connection.BeginOpen(connection.DefaultOpenTimeout, this.onConnectionOpenComplete, connection); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } if (connection != null) { connection.TryClose(ExceptionHelper.ToAmqpException(ex)); } } }
public void AddSession(AmqpSession session, ushort?channel) { int?nullable1; session.Closed += new EventHandler(this.OnSessionClosed); lock (base.ThisLock) { session.LocalChannel = (ushort)this.sessionsByLocalHandle.Add(session); ushort?nullable2 = channel; if (nullable2.HasValue) { nullable1 = new int?((int)nullable2.GetValueOrDefault()); } else { nullable1 = null; } if (nullable1.HasValue) { this.sessionsByRemoteHandle.Add(channel.Value, session); } } MessagingClientEtwProvider.TraceClient <AmqpConnection, AmqpSession, ushort?>((AmqpConnection source, AmqpSession sess, ushort?ch) => { MessagingClientEventSource provider = MessagingClientEtwProvider.Provider; AmqpConnection amqpConnection = source; AmqpSession amqpSession = sess; ushort localChannel = sess.LocalChannel; ushort?nullable = ch; provider.EventWriteAmqpAddSession(amqpConnection, amqpSession, localChannel, (nullable.HasValue ? nullable.GetValueOrDefault() : 0)); }, this, session, channel); }
static void OnHeartBeatTimer(object state) { AmqpConnection thisPtr = (AmqpConnection)state; bool wasActive = thisPtr.active; thisPtr.active = false; if (thisPtr.State != AmqpObjectState.Opened) { return; } try { if (!wasActive) { thisPtr.AsyncIO.Writer.WriteBuffer(Frame.Empty.Buffer, null, null, null); } thisPtr.heartBeatTimer.Set(thisPtr.heartBeatInterval); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } Utils.Trace(TraceLevel.Warning, "{0}: OnHeartBeatTimer failed with exception {1}", thisPtr, exception); } }
public AmqpSession CreateSession(AmqpConnection connection, AmqpSessionSettings settings) { settings.DispositionInterval = TimeSpan.Zero; AmqpSession amqpSession = new AmqpSession(connection, settings, this); MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(this, TraceOperation.Create, amqpSession)); amqpSession.BeginOpen(this.OpenTimeout, AmqpTransportManager.sessionOpenCallback, amqpSession); return(amqpSession); }
public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) { AmqpConnection amqpConnection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings) { SessionFactory = this }; MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(this, TraceOperation.Connect, amqpConnection)); return(amqpConnection); }
public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) { if (this.amqpSettings.RequireSecureTransport && !transport.IsSecure) { throw new AmqpException(AmqpError.NotAllowed, SR.AmqpTransportNotSecure); } AmqpConnection connection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings); Utils.Trace(TraceLevel.Info, "{0}: Created {1}", this, connection); return(connection); }
void EnsureConnectionOpen() { if (this.connection == null) { lock (this.syncRoot) { if (this.connection == null) { this.connection = OpenContainerAsyncResult.End(new OpenContainerAsyncResult(this, null, null)); } } } }
private void OnTransportCallback(TransportAsyncCallbackArgs args) { if (args.Exception != null) { base.Complete(args.CompletedSynchronously, args.Exception); return; } AmqpConnectionSettings amqpConnectionSetting = new AmqpConnectionSettings() { ContainerId = Guid.NewGuid().ToString("N") }; this.AmqpConnection = new AmqpConnection(args.Transport, this.amqpSettings, amqpConnectionSetting); base.Complete(args.CompletedSynchronously); }
public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) { Fx.Assert(connection != null, "connection must not be null"); Fx.Assert(settings != null, "settings must not be null"); this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; this.State = AmqpObjectState.Start; this.links = new Dictionary<string, AmqpLink>(); this.linksByLocalHandle = new HandleTable<AmqpLink>(uint.MaxValue); this.linksByRemoteHandle = new HandleTable<AmqpLink>(uint.MaxValue); this.outgoingChannel = new OutgoingSessionChannel(this); this.incomingChannel = new IncomingSessionChannel(this); this.diagnostics = new Diagnostics(); }
public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) { Fx.Assert(connection != null, "connection must not be null"); Fx.Assert(settings != null, "settings must not be null"); this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; this.State = AmqpObjectState.Start; this.links = new Dictionary <string, AmqpLink>(); this.linksByLocalHandle = new HandleTable <AmqpLink>(uint.MaxValue); this.linksByRemoteHandle = new HandleTable <AmqpLink>(uint.MaxValue); this.outgoingChannel = new OutgoingSessionChannel(this); this.incomingChannel = new IncomingSessionChannel(this); this.diagnostics = new Diagnostics(); }
protected override void OnClosing() { SendingAmqpLink link = this.Link; if (link != null) { link.Closed -= this.onAmqpObjectClosed; } AmqpConnection connection = this.Connection; if (connection != null) { connection.Closed -= this.onAmqpObjectClosed; } base.OnClosing(); }
void OnAcceptTransport(TransportAsyncCallbackArgs args) { if (args.Exception != null) { return; } AmqpConnection connection = new AmqpConnection(args.Transport, this.settings, new AmqpConnectionSettings() { ContainerId = this.container.id }); connection.Closed += new EventHandler(connection_Closed); lock (this.syncRoot) { this.connections.Add(connection); } connection.Open(); }
void OnConnectionOpenComplete(IAsyncResult result) { AmqpConnection connection = (AmqpConnection)result.AsyncState; try { connection.EndOpen(result); this.HandleConnection(connection); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } connection.TryClose(ExceptionHelper.ToAmqpException(exception)); } }
private static void OnHeartBeatTimer(object state) { AmqpConnection amqpConnection = (AmqpConnection)state; if (amqpConnection.State != AmqpObjectState.Opened) { return; } bool flag = false; DateTime dateTime = amqpConnection.lastSendTime; DateTime utcNow = DateTime.UtcNow; DateTime dateTime1 = utcNow; if (utcNow.Subtract(dateTime) < TimeSpan.FromMilliseconds((double)amqpConnection.heartBeatInterval)) { flag = true; dateTime1 = dateTime; } try { if (!flag) { amqpConnection.SendBuffer(Frame.EncodeCommand(FrameType.Amqp, 0, null, 0)); } IOThreadTimer oThreadTimer = amqpConnection.heartBeatTimer; DateTime dateTime2 = dateTime1.AddMilliseconds((double)amqpConnection.heartBeatInterval); oThreadTimer.Set(dateTime2.Subtract(utcNow)); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } MessagingClientEtwProvider.TraceClient <AmqpConnection, Exception>((AmqpConnection source, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, "OnHeartBeatTimer", ex.Message), amqpConnection, exception); } }
protected override void HandleConnection(AmqpConnection connection) { try { Fx.Assert(connection.Settings.RemoteHostName != null, "RemoteHostName cannot be null. It has been validated in OnConnectionOpen."); IConnectionHandler handler = null; if (!this.connectionHandlers.TryGetValue(connection.Settings.RemoteHostName, out handler)) { throw new AmqpException(AmqpError.NotFound, SR.AmqpConnectionHandlerNotFound(connection.Settings.RemoteHostName)); } handler.HandleConnection(connection); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } throw ExceptionHelper.ToAmqpException(exception); } }
public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base("session") { uint valueOrDefault; uint num; this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; base.State = AmqpObjectState.Start; this.links = new Dictionary <string, AmqpLink>(); uint?handleMax = settings.HandleMax; if (handleMax.HasValue) { valueOrDefault = handleMax.GetValueOrDefault(); } else { valueOrDefault = -1; } this.linksByLocalHandle = new HandleTable <AmqpLink>(valueOrDefault); uint?nullable = settings.HandleMax; if (nullable.HasValue) { num = nullable.GetValueOrDefault(); } else { num = -1; } this.linksByRemoteHandle = new HandleTable <AmqpLink>(num); this.outgoingChannel = new AmqpSession.OutgoingSessionChannel(this); this.incomingChannel = new AmqpSession.IncomingSessionChannel(this); this.upgraded = true; }
private void OnAcceptTransport(TransportAsyncCallbackArgs args) { AmqpConnectionSettings amqpConnectionSetting = this.amqpConnectionSettings; AmqpConnection amqpConnection = null; try { amqpConnection = this.CreateConnection(args.Transport, (ProtocolHeader)args.UserToken, false, this.amqpSettings, amqpConnectionSetting); (new AmqpTransportManager.ConnectionHandler(amqpConnection, this.OpenTimeout)).Start(); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } Fx.Exception.TraceHandled(exception, "AmqpTransportManager.OnAcceptTransport", null); if (amqpConnection != null) { amqpConnection.SafeClose(exception); } } }
protected abstract void HandleConnection(AmqpConnection connection);
protected override void HandleConnection(AmqpConnection connection) { this.connectionHandler.HandleConnection(connection); }
AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings settings) { throw new NotImplementedException(); }
public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) { if (this.amqpSettings.RequireSecureTransport && !transport.IsSecure) { throw new AmqpException(AmqpError.NotAllowed, SR.AmqpTransportNotSecure); } AmqpConnection connection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings); Utils.Trace(TraceLevel.Info, "{0}: Created {1}", this, connection); return connection; }
AmqpSession Microsoft.ServiceBus.Messaging.Amqp.ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings) { return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider)); }
AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings) { return new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider); }
protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base(type) { this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; }
protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings) : this(type, connection, settings, null) { }
AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings) { return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider)); }
public ConnectionHandler(AmqpConnection connection, TimeSpan openTimeout) { this.connection = connection; this.openTimeout = openTimeout; }
protected AmqpSession(AmqpConnection connection, AmqpSessionSettings settings) { this.connection = connection; this.settings = settings; }