@@ -82,13 +82,11 @@ public void initiate() throws IOException
82
82
{
83
83
logger .debug ("[Stream #{}] Sending stream init for incoming stream" , session .planId ());
84
84
Socket incomingSocket = session .createConnection ();
85
- incoming .start (incomingSocket , StreamMessage .CURRENT_VERSION );
86
- incoming .sendInitMessage (incomingSocket , true );
85
+ incoming .start (incomingSocket , StreamMessage .CURRENT_VERSION , true );
87
86
88
87
logger .debug ("[Stream #{}] Sending stream init for outgoing stream" , session .planId ());
89
88
Socket outgoingSocket = session .createConnection ();
90
- outgoing .start (outgoingSocket , StreamMessage .CURRENT_VERSION );
91
- outgoing .sendInitMessage (outgoingSocket , false );
89
+ outgoing .start (outgoingSocket , StreamMessage .CURRENT_VERSION , true );
92
90
}
93
91
94
92
/**
@@ -159,13 +157,15 @@ abstract static class MessageHandler implements Runnable
159
157
160
158
protected int protocolVersion ;
161
159
protected Socket socket ;
160
+ private final boolean isOutgoingHandler ;
162
161
163
162
private final AtomicReference <SettableFuture <?>> closeFuture = new AtomicReference <>();
164
163
private IncomingStreamingConnection incomingConnection ;
165
164
166
- protected MessageHandler (StreamSession session )
165
+ protected MessageHandler (StreamSession session , boolean isOutgoingHandler )
167
166
{
168
167
this .session = session ;
168
+ this .isOutgoingHandler = isOutgoingHandler ;
169
169
}
170
170
171
171
protected abstract String name ();
@@ -187,14 +187,14 @@ protected static ReadableByteChannel getReadChannel(Socket socket) throws IOExce
187
187
}
188
188
189
189
@ SuppressWarnings ("resource" )
190
- public void sendInitMessage (Socket socket , boolean isForOutgoing ) throws IOException
190
+ public void sendInitMessage () throws IOException
191
191
{
192
192
StreamInitMessage message = new StreamInitMessage (
193
193
FBUtilities .getBroadcastAddress (),
194
194
session .sessionIndex (),
195
195
session .planId (),
196
196
session .description (),
197
- isForOutgoing ,
197
+ ! isOutgoingHandler ,
198
198
session .keepSSTableLevel (),
199
199
session .isIncremental ());
200
200
ByteBuffer messageBuf = message .createMessage (false , protocolVersion );
@@ -203,16 +203,18 @@ public void sendInitMessage(Socket socket, boolean isForOutgoing) throws IOExcep
203
203
out .flush ();
204
204
}
205
205
206
- public void start (IncomingStreamingConnection connection , int protocolVersion )
206
+ public void start (IncomingStreamingConnection connection , int protocolVersion ) throws IOException
207
207
{
208
208
this .incomingConnection = connection ;
209
- start (connection .socket , protocolVersion );
209
+ start (connection .socket , protocolVersion , false );
210
210
}
211
211
212
- public void start (Socket socket , int protocolVersion )
212
+ public void start (Socket socket , int protocolVersion , boolean initiator ) throws IOException
213
213
{
214
214
this .socket = socket ;
215
215
this .protocolVersion = protocolVersion ;
216
+ if (initiator )
217
+ sendInitMessage ();
216
218
217
219
new Thread (this , name () + "-" + session .peer ).start ();
218
220
}
@@ -270,7 +272,7 @@ static class IncomingMessageHandler extends MessageHandler
270
272
{
271
273
IncomingMessageHandler (StreamSession session )
272
274
{
273
- super (session );
275
+ super (session , false );
274
276
}
275
277
276
278
protected String name ()
@@ -330,7 +332,7 @@ public int compare(StreamMessage o1, StreamMessage o2)
330
332
331
333
OutgoingMessageHandler (StreamSession session )
332
334
{
333
- super (session );
335
+ super (session , true );
334
336
}
335
337
336
338
protected String name ()
0 commit comments