本文整理汇总了C#中IConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Close方法的具体用法?C# IConnection.Close怎么用?C# IConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseConnection
/// <summary> Close the given NMS Connection and ignore any thrown exception.
/// This is useful for typical <code>finally</code> blocks in manual NMS code.
/// </summary>
/// <param name="con">the NMS Connection to close (may be <code>null</code>)
/// </param>
/// <param name="stop">whether to call <code>stop()</code> before closing
/// </param>
public static void CloseConnection(IConnection con, bool stop)
{
if (con != null)
{
try
{
if (stop)
{
try
{
con.Stop();
}
finally
{
con.Close();
}
}
else
{
con.Close();
}
}
catch (NMSException ex)
{
logger.Debug("Could not close NMS Connection", ex);
}
catch (Exception ex)
{
// We don't trust the NMS provider: It might throw another exception.
logger.Debug("Unexpected exception on closing NMS Connection", ex);
}
}
}
示例2: TryCreateConnectionFactory
protected void TryCreateConnectionFactory(object stateInfo)
{
if (Connection != null) Connection.Dispose();
Connection = null;
if (stateInfo != null)
{
Log.Information("Retrying connection");
var autoEvent = (AutoResetEvent)stateInfo;
if(autoEvent != null) autoEvent.Set();
}
var tempHostNames = hostNames;
//hostNames.Shuffle();
foreach (var hostName in tempHostNames)
{
try
{
factory = new ConnectionFactory
{
HostName = hostName,
UserName = userName,
Password = password,
NetworkRecoveryInterval = TimeSpan.FromMilliseconds(timeout),
AutomaticRecoveryEnabled = automaticRecoveryEnabled,
RequestedHeartbeat = (ushort) heartbeat,
RequestedConnectionTimeout = 60000
};
Connection = factory.CreateConnection();
Log.Information(
"Connection heartbeat is configured to {0} seconds, and the connection has returned a value of {1} seconds",
heartbeat, Connection.Heartbeat);
Connection.ConnectionShutdown += connection_ConnectionShutdown;
WaitingToConnect = false;
break;
}
catch (SocketException se)
{
Log.Error(se, "RabbitMq: TryCreateConnectionFactory has an Error creating connection to host {0}",
hostName);
if (Connection != null) Connection.Close();
}
catch (BrokerUnreachableException be)
{
Log.Error(be, "RabbitMq: TryCreateConnectionFactory Cannot reach broker for host {0}", hostName);
if (Connection != null) Connection.Close();
}
catch (Exception ex)
{
Log.Error(ex, "RabbitMq: TryCreateConnectionFactory has an Error with {0} - {1}", hostName,
ex.Message);
if (Connection != null) Connection.Close();
}
}
if (Connection == null) StartTryToConnect();
}
示例3: Close
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
public virtual bool Close(IConnection connection)
{
if (connection.IsOpen)
connection.Close();
return true;
}
示例4: ReleaseConnection
/// <summary>
/// Releases the given connection, stopping it (if necessary) and eventually closing it.
/// </summary>
/// <remarks>Checks <see cref="ISmartConnectionFactory.ShouldStop"/>, if available.
/// This is essentially a more sophisticated version of
/// <see cref="NmsUtils.CloseConnection(IConnection, bool)"/>
/// </remarks>
/// <param name="connection">The connection to release. (if this is <code>null</code>, the call will be ignored)</param>
/// <param name="cf">The ConnectionFactory that the Connection was obtained from. (may be <code>null</code>)</param>
/// <param name="started">whether the Connection might have been started by the application.</param>
public static void ReleaseConnection(IConnection connection, IConnectionFactory cf, bool started)
{
if (connection == null)
{
return;
}
if (started && cf is ISmartConnectionFactory && ((ISmartConnectionFactory)cf).ShouldStop(connection))
{
try
{
connection.Stop();
}
catch (Exception ex)
{
LOG.Debug("Could not stop NMS Connection before closing it", ex);
}
}
try
{
connection.Close();
} catch (Exception ex)
{
LOG.Debug("Could not close NMS Connection", ex);
}
}
示例5: TryClose
private static void TryClose(IConnection connection)
{
if (connection == null) return;
try
{
connection.Close();
}
catch
{}
}
示例6: CloseConnection
/// <summary>
/// Closes the given Rabbit Connection and ignore any thrown exception.
/// </summary>
/// <remarks>This is useful for typical 'finally' blocks in manual Rabbit
/// code</remarks>
/// <param name="connection">The connection to close (may be nul).</param>
public static void CloseConnection(IConnection connection)
{
if (connection != null)
{
try
{
connection.Close();
} catch (Exception ex)
{
logger.Debug("Ignoring Connection exception - assuming already closed: ", ex);
}
}
}
示例7: ReleaseConnection
/// <summary>
/// Releases the connection.
/// </summary>
/// <param name="con">The con.</param>
/// <param name="cf">The cf.</param>
/// <remarks></remarks>
public static void ReleaseConnection(IConnection con, IConnectionFactory cf)
{
if (con == null)
{
return;
}
try
{
con.Close();
}
catch (Exception ex)
{
logger.Debug("Could not close Otp Connection", ex);
}
}
示例8: ReceiveData
public static void ReceiveData(NetworkData data, IConnection connection)
{
var node = connection.RemoteHost;
ServerPrint(connection.RemoteHost, string.Format("recieved {0} bytes", data.Length));
var str = Encoding.UTF8.GetString(data.Buffer).Trim();
if (str.Trim().Equals("close"))
{
connection.Close();
return;
}
ServerPrint(connection.RemoteHost, string.Format("recieved \"{0}\"", str));
ServerPrint(connection.RemoteHost,
string.Format("sending \"{0}\" back to {1}:{2}", str, node.Host, node.Port));
var sendBytes = Encoding.UTF8.GetBytes(str + Environment.NewLine);
connection.Send(new NetworkData() {Buffer = sendBytes, Length = sendBytes.Length, RemoteHost = node});
}
示例9: receive
public String receive(String queueName)
{
Console.WriteLine(queueName);
Console.WriteLine("In RabbitMQ.receive");
string messageReceived = "";
Console.WriteLine("connectionFactory : " + connectionFactory);
using (connection = connectionFactory.CreateConnection())
{
Console.WriteLine("connection : " + connection);
using (channel = connection.CreateModel())
{
Console.WriteLine("channel : " + channel);
channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
Console.WriteLine("Requesting message");
consumer.Received += (Model, ea) =>
{
var body = ea.Body;
messageReceived = Encoding.UTF8.GetString(body);
Console.WriteLine("Message received : " + messageReceived);
};
channel.BasicConsume(queue: queueName,
noAck: true,
consumer: consumer);
Console.WriteLine("Waiting for message ...");
while (messageReceived == "") { } //menunggu hingga menerima pesan
channel.Close();
connection.Close();
return messageReceived;
}
}
}
示例10: ProcessErrorAndClose
private void ProcessErrorAndClose(IConnection connection, Exception ex)
{
try
{
// send error details
connection.SendErrorResponse(ex);
}
catch
{
// hmmm, what can we do now?
}
try
{
// close connection
connection.Close();
}
catch
{
// it seems reasonable to ignore this error
}
}
示例11: Init
protected void Init(IConnection channel, INode remoteSocketAddress, Address remoteAddress, NetworkData msg,
out AssociationHandle op)
{
var localAddress = HeliosTransport.NodeToAddress(channel.Local, WrappedTransport.SchemeIdentifier,
WrappedTransport.System.Name, WrappedTransport.Settings.Hostname);
if (localAddress != null)
{
var handle = CreateHandle(channel, localAddress, remoteAddress);
handle.ReadHandlerSource.Task.ContinueWith(s =>
{
var listener = s.Result;
RegisterListener(channel, listener, msg, remoteSocketAddress);
}, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.NotOnCanceled & TaskContinuationOptions.NotOnFaulted);
op = handle;
}
else
{
op = null;
channel.Close();
}
}
示例12: ShutdownAmqp
private void ShutdownAmqp(IConnection connection, ShutdownEventArgs reason)
{
// I can't make this NOT hang when RMQ goes down
// and then a log message is sent...
try
{
if (_Model != null && _Model.IsOpen
&& reason.ReplyCode != Constants.ChannelError
&& reason.ReplyCode != Constants.ConnectionForced)
_Model.Abort(); //_Model.Close();
}
catch (Exception e)
{
InternalLogger.Error("could not close model", e);
}
try
{
if (connection != null && connection.IsOpen)
{
connection.ConnectionShutdown -= ShutdownAmqp;
connection.Close(reason.ReplyCode, reason.ReplyText, 1000);
connection.Abort(1000); // you get 2 seconds to shut down!
}
}
catch (Exception e)
{
InternalLogger.Error("could not close connection", e);
}
}
示例13: Shutdown
public static void Shutdown(IConnection connection)
{
//TODO: Correct?
connection.Close();
}
示例14: CloseConnection
/// <summary>
/// Closes the given connection.
/// </summary>
/// <param name="con">The connection.</param>
protected virtual void CloseConnection(IConnection con)
{
if (LOG.IsDebugEnabled)
{
LOG.Debug("Closing shared NMS Connection: " + this.target);
}
try
{
try
{
if (this.started)
{
this.started = false;
con.Stop();
}
} finally
{
con.Close();
}
} catch (Exception ex)
{
LOG.Warn("Could not close shared NMS connection.", ex);
}
}
示例15: CloseNoThrow
internal static void CloseNoThrow(IConnection connection, TimeSpan timeout)
{
bool success = false;
try
{
connection.Close(timeout, false);
success = true;
}
catch (TimeoutException)
{
}
catch (CommunicationException)
{
}
finally
{
if (!success)
{
connection.Abort();
}
}
}