11/*
2- * Copyright 2001-2018 the original author or authors.
2+ * Copyright 2001-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3535 * determine success.
3636 *
3737 * @author Gary Russell
38- * @author Artem Bilan
39- *
4038 * @since 2.0
4139 */
4240public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler {
@@ -103,45 +101,49 @@ public MulticastSendingMessageHandler(String address, int port,
103101
104102 @ Override
105103 protected DatagramSocket getSocket () throws IOException {
106- if (this .multicastSocket == null ) {
104+ if (this .getTheSocket () == null ) {
107105 synchronized (this ) {
108- if (this .multicastSocket == null ) {
109- createSocket ();
110- }
106+ createSocket ();
111107 }
112108 }
113- return getTheSocket ();
109+ return this . getTheSocket ();
114110 }
115111
116112 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 ();
122132 }
123133 else {
124- InetAddress whichNic = InetAddress . getByName ( this . localAddress );
125- socket = new MulticastSocket ( new InetSocketAddress ( whichNic , ackPort ) );
134+ socket = new MulticastSocket ( );
135+ setSocket ( socket );
126136 }
127- if (getSoReceiveBufferSize () > 0 ) {
128- socket .setReceiveBufferSize ( getSoReceiveBufferSize () );
137+ if (this . timeToLive >= 0 ) {
138+ socket .setTimeToLive ( this . timeToLive );
129139 }
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 );
132144 }
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 ;
142146 }
143- setSocketAttributes (socket );
144- this .multicastSocket = socket ;
145147 }
146148
147149
@@ -151,7 +153,7 @@ private void createSocket() throws IOException {
151153 * @param minAcksForSuccess The minimum number of acks that will represent success.
152154 */
153155 public void setMinAcksForSuccess (int minAcksForSuccess ) {
154- setAckCounter (minAcksForSuccess );
156+ this . setAckCounter (minAcksForSuccess );
155157 }
156158
157159 /**
0 commit comments