diff --git a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java index 44d13d522a..029b106927 100644 --- a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java +++ b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java @@ -24,6 +24,9 @@ import java.net.MulticastSocket; import org.springframework.integration.core.MessagingException; /** + * Channel adapter that joins a multicast group and receives incoming packets and + * sends them to an output channel. + * * @author Gary Russell * @since 2.0 */ @@ -33,7 +36,10 @@ public class MulticastReceivingChannelAdapter extends UnicastReceivingChannelAda /** - * @param port + * Constructs a MulticastReceivingChannelAdapter that listens for packets on the + * specified multichannel address (group) and port. + * @param group The multichannel address. + * @param port The port. */ public MulticastReceivingChannelAdapter(String group, int port) { super(port); @@ -41,8 +47,12 @@ public class MulticastReceivingChannelAdapter extends UnicastReceivingChannelAda } /** - * @param port - * @param lengthCheck + * Constructs a MulticastReceivingChannelAdapter that listens for packets on the + * specified multichannel address (group) and port. Enables setting the lengthCheck + * option, which expects a length to precede the incoming packets. + * @param group The multichannel address. + * @param port The port. + * @param lengthCheck If true, enables the lengthCheck Option. */ public MulticastReceivingChannelAdapter(String group, int port, boolean lengthCheck) { super(port, lengthCheck); diff --git a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java index bac3537b70..beb98dbef8 100644 --- a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java +++ b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java @@ -39,14 +39,54 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler protected int timeToLive = -1; + /** + * Constructs a MulticastSendingMessageHandler to send data to the multicast address/port. + * @param address The multicast address. + * @param port The port. + */ public MulticastSendingMessageHandler(String address, int port) { super(address, port); } + /** + * Constructs a MulticastSendingMessageHandler to send data to the multicast address/port + * and enables setting the lengthCheck option (if set, a length is prepended to the packet and checked + * at the destination). + * @param address The multicast address. + * @param port The port. + * @param lengthCheck Enable the lengthCheck option. + */ public MulticastSendingMessageHandler(String address, int port, boolean lengthCheck) { super(address, port, lengthCheck); } + + /** + * Constructs a MulticastSendingMessageHandler to send data to the multicast address/port + * and enables setting the acknowledge option, where the destination sends a receipt acknowledgment. + * @param address The multicast address. + * @param port The port. + * @param acknowledge Whether or not acknowledgments are required. + * @param ackHost The host to which acknowledgments should be sent; required if acknowledge is true. + * @param ackPort The port to which acknowledgments should be sent; required if acknowledge is true. + * @param ackTimeout How long to wait (milliseconds) for an acknowledgment. + */ + public MulticastSendingMessageHandler(String address, int port, + boolean acknowledge, String ackHost, int ackPort, int ackTimeout) { + super(address, port, acknowledge, ackHost, ackPort, ackTimeout); + } + + /** + * Constructs a MulticastSendingMessageHandler to send data to the multicast address/port + * and enables setting the acknowledge option, where the destination sends a receipt acknowledgment. + * @param address The multicast address. + * @param port The port. + * @param lengthCheck Enable the lengthCheck option. + * @param acknowledge Whether or not acknowledgments are required. + * @param ackHost The host to which acknowledgments should be sent; required if acknowledge is true. + * @param ackPort The port to which acknowledgments should be sent; required if acknowledge is true. + * @param ackTimeout How long to wait (milliseconds) for an acknowledgment. + */ public MulticastSendingMessageHandler(String address, int port, boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) { @@ -62,6 +102,10 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler this.ackCounter = minAcksForSuccess; } + /** + * Set the underlying {@link MulticastSocket} time to live property. + * @param timeToLive {@see MulticastSocket#setTimeToLive(int)} + */ public void setTimeToLive(int timeToLive) { this.timeToLive = timeToLive; } diff --git a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/UnicastReceivingChannelAdapter.java b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/UnicastReceivingChannelAdapter.java index a4251bd466..bbfbd18437 100644 --- a/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/UnicastReceivingChannelAdapter.java +++ b/org.springframework.integration.ip/src/main/java/org/springframework/integration/ip/udp/UnicastReceivingChannelAdapter.java @@ -34,6 +34,10 @@ import org.springframework.integration.ip.IpHeaders; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; /** + * A channel adapter to receive incoming UDP packets. Packets can optionally be preceded by a + * 4 byte length field, used to validate that all data was received. Packets may also contain + * information indicating an acknowledgment needs to be sent. + * * @author Gary Russell * @since 2.0 */ @@ -50,11 +54,22 @@ public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolRece private static Pattern addressPattern = Pattern.compile("([^:]*):([0-9]*)"); + /** + * Constructs a UnicastReceivingChannelAdapter that listens on the specified port. + * @param port + */ public UnicastReceivingChannelAdapter(int port) { super(port); mapper.setLengthCheck(false); } + /** + * Constructs a UnicastReceivingChannelAdapter that listens for packets on + * the specified port. Enables setting the lengthCheck option, which expects + * a length to precede the incoming packets. + * @param port The port. + * @param lengthCheck If true, enables the lengthCheck Option. + */ public UnicastReceivingChannelAdapter(int port, boolean lengthCheck) { super(port); mapper.setLengthCheck(lengthCheck); @@ -106,7 +121,7 @@ public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolRece } } - private void sendAck(Message message) { + protected void sendAck(Message message) { MessageHeaders headers = message.getHeaders(); Object id = headers.getId(); byte[] ack = id.toString().getBytes(); @@ -155,7 +170,7 @@ public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolRece return true; } - public DatagramPacket receive() throws Exception { + protected DatagramPacket receive() throws Exception { DatagramSocket socket = this.getSocket(); final byte[] buffer = new byte[this.receiveBufferSize]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length);