-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
IConnection.cs
168 lines (151 loc) · 6.14 KB
/
IConnection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Copyright 2013-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver.Core.Configuration;
using MongoDB.Driver.Core.WireProtocol.Messages;
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
namespace MongoDB.Driver.Core.Connections
{
/// <summary>
/// Represents a connection.
/// </summary>
public interface IConnection : IDisposable
{
// properties
/// <summary>
/// Gets the connection identifier.
/// </summary>
/// <value>
/// The connection identifier.
/// </value>
ConnectionId ConnectionId { get; }
/// <summary>
/// Gets the connection description.
/// </summary>
/// <value>
/// The connection description.
/// </value>
ConnectionDescription Description { get; }
/// <summary>
/// Gets the end point.
/// </summary>
/// <value>
/// The end point.
/// </value>
EndPoint EndPoint { get; }
/// <summary>
/// Gets the generation of the pool when this connection was created.
/// </summary>
/// <value>
/// The generation of the pool when this connection was created.
/// </value>
int Generation { get; }
/// <summary>
/// Gets a value indicating whether this instance is expired.
/// </summary>
/// <value>
/// <c>true</c> if this instance is expired; otherwise, <c>false</c>.
/// </value>
bool IsExpired { get; }
/// <summary>
/// Gets the connection settings.
/// </summary>
/// <value>
/// The connection settings.
/// </value>
ConnectionSettings Settings { get; }
/// <summary>
/// Set read timeout value.
/// </summary>
/// <param name="timeout">The timeout.</param>
void SetReadTimeout(TimeSpan timeout);
// methods
/// <summary>
/// Opens the connection.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void Open(CancellationToken cancellationToken);
/// <summary>
/// Opens the connection.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A Task.</returns>
Task OpenAsync(CancellationToken cancellationToken);
/// <summary>
/// Reauthenticate the connection.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
void Reauthenticate(CancellationToken cancellationToken);
/// <summary>
/// Reauthenticate the connection.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task.</returns>
Task ReauthenticateAsync(CancellationToken cancellationToken);
/// <summary>
/// Receives a message.
/// </summary>
/// <param name="responseTo">The id of the sent message for which a response is to be received.</param>
/// <param name="encoderSelector">The encoder selector.</param>
/// <param name="messageEncoderSettings">The message encoder settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The response message.
/// </returns>
ResponseMessage ReceiveMessage(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken);
/// <summary>
/// Receives a message.
/// </summary>
/// <param name="responseTo">The id of the sent message for which a response is to be received.</param>
/// <param name="encoderSelector">The encoder selector.</param>
/// <param name="messageEncoderSettings">The message encoder settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A Task whose result is the response message.
/// </returns>
Task<ResponseMessage> ReceiveMessageAsync(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken);
/// <summary>
/// Sends the messages.
/// </summary>
/// <param name="messages">The messages.</param>
/// <param name="messageEncoderSettings">The message encoder settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
void SendMessages(IEnumerable<RequestMessage> messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken);
/// <summary>
/// Sends the messages.
/// </summary>
/// <param name="messages">The messages.</param>
/// <param name="messageEncoderSettings">The message encoder settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A Task.</returns>
Task SendMessagesAsync(IEnumerable<RequestMessage> messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken);
}
/// <summary>
/// Represents a handle to a connection.
/// </summary>
public interface IConnectionHandle : IConnection
{
// methods
/// <summary>
/// A new handle to the underlying connection.
/// </summary>
/// <returns>A connection handle.</returns>
IConnectionHandle Fork();
}
}