From 59909b64abf5930db51b5e9395f33aad3d287baf Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 19 Jan 2018 17:20:51 -0500 Subject: [PATCH] Revert "INT-4366: Fix MulticastSendingMH This reverts commit 3cccf9b52616bd8551b66166b04f747dae068902. --- .../udp/MulticastSendingMessageHandler.java | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java index 8ad4df80d1..b07633d4c5 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2018 the original author or authors. + * Copyright 2001-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,6 @@ import org.springframework.messaging.MessageHandler; * determine success. * * @author Gary Russell - * @author Artem Bilan - * * @since 2.0 */ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler { @@ -103,45 +101,49 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler @Override protected DatagramSocket getSocket() throws IOException { - if (this.multicastSocket == null) { + if (this.getTheSocket() == null) { synchronized (this) { - if (this.multicastSocket == null) { - createSocket(); - } + createSocket(); } } - return getTheSocket(); + return this.getTheSocket(); } private void createSocket() throws IOException { - MulticastSocket socket; - if (isAcknowledge()) { - int ackPort = getAckPort(); - if (this.localAddress == null) { - socket = ackPort == 0 ? new MulticastSocket() : new MulticastSocket(ackPort); + if (this.getTheSocket() == null) { + MulticastSocket socket; + if (this.isAcknowledge()) { + int ackPort = this.getAckPort(); + if (this.localAddress == null) { + socket = ackPort == 0 ? new MulticastSocket() : new MulticastSocket(ackPort); + } + else { + InetAddress whichNic = InetAddress.getByName(this.localAddress); + socket = new MulticastSocket(new InetSocketAddress(whichNic, ackPort)); + } + if (getSoReceiveBufferSize() > 0) { + socket.setReceiveBufferSize(this.getSoReceiveBufferSize()); + } + if (logger.isDebugEnabled()) { + logger.debug("Listening for acks on port: " + socket.getLocalPort()); + } + setSocket(socket); + updateAckAddress(); } else { + socket = new MulticastSocket(); + setSocket(socket); + } + if (this.timeToLive >= 0) { + socket.setTimeToLive(this.timeToLive); + } + setSocketAttributes(socket); + if (this.localAddress != null) { InetAddress whichNic = InetAddress.getByName(this.localAddress); - socket = new MulticastSocket(new InetSocketAddress(whichNic, ackPort)); + socket.setInterface(whichNic); } - if (getSoReceiveBufferSize() > 0) { - socket.setReceiveBufferSize(getSoReceiveBufferSize()); - } - if (logger.isDebugEnabled()) { - logger.debug("Listening for acks on port: " + socket.getLocalPort()); - } - setSocket(socket); - updateAckAddress(); + this.multicastSocket = socket; } - else { - socket = new MulticastSocket(); - setSocket(socket); - } - if (this.timeToLive >= 0) { - socket.setTimeToLive(this.timeToLive); - } - setSocketAttributes(socket); - this.multicastSocket = socket; } @@ -151,7 +153,7 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler * @param minAcksForSuccess The minimum number of acks that will represent success. */ public void setMinAcksForSuccess(int minAcksForSuccess) { - setAckCounter(minAcksForSuccess); + this.setAckCounter(minAcksForSuccess); } /**