3838import java .nio .channels .ClosedByInterruptException ;
3939import java .util .List ;
4040
41+ import static org .mongodb .assertions .Assertions .isTrue ;
4142import static org .mongodb .connection .ReplyHeader .REPLY_HEADER_LENGTH ;
4243
4344abstract class DefaultConnection implements Connection {
@@ -66,12 +67,14 @@ public ServerAddress getServerAddress() {
6667 return serverAddress ;
6768 }
6869
69- public DefaultConnectionSettings getSettings () {
70- return settings ;
70+ @ Override
71+ public void open () {
72+ isTrue ("open" , !isClosed ());
73+ ensureOpen ();
7174 }
7275
7376 public void sendMessage (final List <ByteBuf > byteBuffers ) {
74- check ( );
77+ isTrue ( "open" , ! isClosed () );
7578 try {
7679 write (byteBuffers );
7780 } catch (IOException e ) {
@@ -82,7 +85,7 @@ public void sendMessage(final List<ByteBuf> byteBuffers) {
8285
8386 @ Override
8487 public ResponseBuffers receiveMessage (final ResponseSettings responseSettings ) {
85- check ( );
88+ isTrue ( "open" , ! isClosed () );
8689 try {
8790 return receiveMessage (responseSettings , System .nanoTime ());
8891 } catch (IOException e ) {
@@ -149,10 +152,6 @@ private ResponseBuffers receiveMessage(final ResponseSettings responseSettings,
149152 return new ResponseBuffers (replyHeader , bodyByteBuffer , System .nanoTime () - start );
150153 }
151154
152- private void check () {
153- ensureOpen ();
154- }
155-
156155 protected void initializeSocket (final Socket socket ) throws IOException {
157156 socket .setTcpNoDelay (true );
158157 socket .setSoTimeout (settings .getReadTimeoutMS ());
0 commit comments