1
1
/*
2
- * Copyright 2001-2018 the original author or authors.
2
+ * Copyright 2001-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
35
35
* determine success.
36
36
*
37
37
* @author Gary Russell
38
- * @author Artem Bilan
39
- *
40
38
* @since 2.0
41
39
*/
42
40
public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler {
@@ -103,45 +101,49 @@ public MulticastSendingMessageHandler(String address, int port,
103
101
104
102
@ Override
105
103
protected DatagramSocket getSocket () throws IOException {
106
- if (this .multicastSocket == null ) {
104
+ if (this .getTheSocket () == null ) {
107
105
synchronized (this ) {
108
- if (this .multicastSocket == null ) {
109
- createSocket ();
110
- }
106
+ createSocket ();
111
107
}
112
108
}
113
- return getTheSocket ();
109
+ return this . getTheSocket ();
114
110
}
115
111
116
112
private void createSocket () throws IOException {
117
- MulticastSocket socket ;
118
- if (isAcknowledge ()) {
119
- int ackPort = getAckPort ();
120
- if (this .localAddress == null ) {
121
- socket = ackPort == 0 ? new MulticastSocket () : new MulticastSocket (ackPort );
113
+ if (this .getTheSocket () == null ) {
114
+ MulticastSocket socket ;
115
+ if (this .isAcknowledge ()) {
116
+ int ackPort = this .getAckPort ();
117
+ if (this .localAddress == null ) {
118
+ socket = ackPort == 0 ? new MulticastSocket () : new MulticastSocket (ackPort );
119
+ }
120
+ else {
121
+ InetAddress whichNic = InetAddress .getByName (this .localAddress );
122
+ socket = new MulticastSocket (new InetSocketAddress (whichNic , ackPort ));
123
+ }
124
+ if (getSoReceiveBufferSize () > 0 ) {
125
+ socket .setReceiveBufferSize (this .getSoReceiveBufferSize ());
126
+ }
127
+ if (logger .isDebugEnabled ()) {
128
+ logger .debug ("Listening for acks on port: " + socket .getLocalPort ());
129
+ }
130
+ setSocket (socket );
131
+ updateAckAddress ();
122
132
}
123
133
else {
124
- InetAddress whichNic = InetAddress . getByName ( this . localAddress );
125
- socket = new MulticastSocket ( new InetSocketAddress ( whichNic , ackPort ) );
134
+ socket = new MulticastSocket ( );
135
+ setSocket ( socket );
126
136
}
127
- if (getSoReceiveBufferSize () > 0 ) {
128
- socket .setReceiveBufferSize ( getSoReceiveBufferSize () );
137
+ if (this . timeToLive >= 0 ) {
138
+ socket .setTimeToLive ( this . timeToLive );
129
139
}
130
- if (logger .isDebugEnabled ()) {
131
- logger .debug ("Listening for acks on port: " + socket .getLocalPort ());
140
+ setSocketAttributes (socket );
141
+ if (this .localAddress != null ) {
142
+ InetAddress whichNic = InetAddress .getByName (this .localAddress );
143
+ socket .setInterface (whichNic );
132
144
}
133
- setSocket (socket );
134
- updateAckAddress ();
135
- }
136
- else {
137
- socket = new MulticastSocket ();
138
- setSocket (socket );
139
- }
140
- if (this .timeToLive >= 0 ) {
141
- socket .setTimeToLive (this .timeToLive );
145
+ this .multicastSocket = socket ;
142
146
}
143
- setSocketAttributes (socket );
144
- this .multicastSocket = socket ;
145
147
}
146
148
147
149
@@ -151,7 +153,7 @@ private void createSocket() throws IOException {
151
153
* @param minAcksForSuccess The minimum number of acks that will represent success.
152
154
*/
153
155
public void setMinAcksForSuccess (int minAcksForSuccess ) {
154
- setAckCounter (minAcksForSuccess );
156
+ this . setAckCounter (minAcksForSuccess );
155
157
}
156
158
157
159
/**
0 commit comments