<commit_before>package org.jgroups.protocols;


import org.jgroups.Address;
import org.jgroups.Global;
import org.jgroups.Message;
import org.jgroups.annotations.DeprecatedProperty;
import org.jgroups.annotations.Property;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.BoundedList;
import org.jgroups.util.Util;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;




/**
 * IP multicast transport based on UDP. Messages to the group (msg.dest == null) will
 * be multicast (to all group members), whereas point-to-point messages
 * (msg.dest != null) will be unicast to a single member. Uses a multicast and
 * a unicast socket.<p>
 * The following properties are read by the UDP protocol:
 * <ul>
 * <li> param mcast_addr - the multicast address to use; default is 172.16.31.10.
 * <li> param mcast_port - (int) the port that the multicast is sent on; default is 7600
 * <li> param ip_mcast - (boolean) flag whether to use IP multicast; default is true.
 * <li> param ip_ttl - the default time-to-live for multicast packets sent out on this
 * socket; default is 32.
 * <li> param use_packet_handler - boolean, defaults to false.
 * If set, the mcast and ucast receiver threads just put
 * the datagram's payload (a byte buffer) into a queue, from where a separate thread
 * will dequeue and handle them (unmarshal and pass up). This frees the receiver
 * threads from having to do message unmarshalling; this time can now be spent
 * receiving packets. If you have lots of retransmissions because of network
 * input buffer overflow, consider setting this property to true.
 * </ul>
 * @author <NAME>
 * @version $Id: UDP.java,v 1.177 2008/06/03 14:37:00 belaban Exp $
 */
@DeprecatedProperty(names={"num_last_ports","null_src_addresses"})
public class UDP extends TP implements Runnable {

    /** Socket used for
     * <ol>
     * <li>sending unicast packets and
     * <li>receiving unicast packets
     * </ol>
     * The address of this socket will be our local address (<tt>local_addr</tt>) */
    DatagramSocket  sock=null;

    /**
     * BoundedList<Integer> of the last 100 ports used. This is to avoid reusing a port for DatagramSocket
     */
    private static final BoundedList<Integer> last_ports_used=new BoundedList<Integer>(100);

    /** IP multicast socket for <em>sending</em> and <em>receiving</em> multicast packets */
    MulticastSocket mcast_sock=null;


    /** If we have multiple mcast send sockets, e.g. send_interfaces or send_on_all_interfaces enabled */
    MulticastSocket[] mcast_send_sockets=null;

    /**
     * Traffic class for sending unicast and multicast datagrams.
     * Valid values are (check {@link DatagramSocket#setTrafficClass(int)} );  for details):
     * <UL>
     * <LI><CODE>IPTOS_LOWCOST (0x02)</CODE>, <b>decimal 2</b></LI>
     * <LI><CODE>IPTOS_RELIABILITY (0x04)</CODE><, <b>decimal 4</b>/LI>
     * <LI><CODE>IPTOS_THROUGHPUT (0x08)</CODE>, <b>decimal 8</b></LI>
     * <LI><CODE>IPTOS_LOWDELAY (0x10)</CODE>, <b>decimal</b> 16</LI>
     * </UL>
     */
    @Property
    int             tos=8; // valid values: 2, 4, 8 (default), 16


    /** The multicast address (mcast address and port) this member uses */
    IpAddress       mcast_addr=null;

    /** The multicast address used for sending and receiving packets */
    String          mcast_addr_name="228.8.8.8";

    /** The multicast port used for sending and receiving packets */
    int             mcast_port=7600;

    /** The multicast receiver thread */
    Thread          mcast_receiver=null;

    private final static String MCAST_RECEIVER_THREAD_NAME = "UDP mcast";

    /** The unicast receiver thread */
    UcastReceiver   ucast_receiver=null;

    /** Whether to enable IP multicasting. If false, multiple unicast datagram
     * packets are sent rather than one multicast packet */
    @Property
    boolean         ip_mcast=true;

    /** The time-to-live (TTL) for multicast datagram packets */
    @Property
    int             ip_ttl=8;

    /** Send buffer size of the multicast datagram socket */
    @Property
    int             mcast_send_buf_size=32000;

    /** Receive buffer size of the multicast datagram socket */
    @Property
    int             mcast_recv_buf_size=64000;

    /** Send buffer size of the unicast datagram socket */
    @Property
    int             ucast_send_buf_size=32000;

    /** Receive buffer size of the unicast datagram socket */
    @Property
    int             ucast_recv_buf_size=64000;


    /** Usually, src addresses are nulled, and the receiver simply sets them to the address of the sender. However,
     * for multiple addresses on a Windows loopback device, this doesn't work
     * (see http://jira.jboss.com/jira/browse/JGRP-79 and the JGroups wiki for details). This must be the same
     * value for all members of the same group. Default is true, for performance reasons */
    // private boolean null_src_addresses=true;



    /**
     * Creates the UDP protocol, and initializes the
     * state variables, does however not start any sockets or threads.
     */
    public UDP() {
    }


    @Property(name="mcast_addr")
    public void setMulticastAddress(String addr) {this.mcast_addr_name=addr;}
    public String getMulticastAddress() {return mcast_addr_name;}
    public int getMulticastPort() {return mcast_port;}
    @Property(name="mcast_port")
    public void setMulticastPort(int mcast_port) {this.mcast_port=mcast_port;}


    /* ----------------------- Receiving of MCAST UDP packets ------------------------ */

    public void run() {
        final byte      receive_buf[]=new byte[65535];
        int             offset, len, sender_port;
        InetAddress     sender_addr;
        Address         sender;

        final DatagramPacket packet=new DatagramPacket(receive_buf, receive_buf.length);

        while(mcast_receiver != null && mcast_sock != null) {
            try {
                mcast_sock.receive(packet);
                len=packet.getLength();<commit_msg>moved @Property to mast_addr_namer and mcast_port, from setters<commit_after>package org.jgroups.protocols;


import org.jgroups.Address;
import org.jgroups.Global;
import org.jgroups.Message;
import org.jgroups.annotations.DeprecatedProperty;
import org.jgroups.annotations.Property;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.BoundedList;
import org.jgroups.util.Util;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;




/**
 * IP multicast transport based on UDP. Messages to the group (msg.dest == null) will
 * be multicast (to all group members), whereas point-to-point messages
 * (msg.dest != null) will be unicast to a single member. Uses a multicast and
 * a unicast socket.<p>
 * The following properties are read by the UDP protocol:
 * <ul>
 * <li> param mcast_addr - the multicast address to use; default is 172.16.31.10.
 * <li> param mcast_port - (int) the port that the multicast is sent on; default is 7600
 * <li> param ip_mcast - (boolean) flag whether to use IP multicast; default is true.
 * <li> param ip_ttl - the default time-to-live for multicast packets sent out on this
 * socket; default is 32.
 * <li> param use_packet_handler - boolean, defaults to false.
 * If set, the mcast and ucast receiver threads just put
 * the datagram's payload (a byte buffer) into a queue, from where a separate thread
 * will dequeue and handle them (unmarshal and pass up). This frees the receiver
 * threads from having to do message unmarshalling; this time can now be spent
 * receiving packets. If you have lots of retransmissions because of network
 * input buffer overflow, consider setting this property to true.
 * </ul>
 * @author <NAME>
 * @version $Id: UDP.java,v 1.178 2008/06/05 09:40:53 belaban Exp $
 */
@DeprecatedProperty(names={"num_last_ports","null_src_addresses"})
public class UDP extends TP implements Runnable {

    /** Socket used for
     * <ol>
     * <li>sending unicast packets and
     * <li>receiving unicast packets
     * </ol>
     * The address of this socket will be our local address (<tt>local_addr</tt>) */
    DatagramSocket  sock=null;

    /**
     * BoundedList<Integer> of the last 100 ports used. This is to avoid reusing a port for DatagramSocket
     */
    private static final BoundedList<Integer> last_ports_used=new BoundedList<Integer>(100);

    /** IP multicast socket for <em>sending</em> and <em>receiving</em> multicast packets */
    MulticastSocket mcast_sock=null;


    /** If we have multiple mcast send sockets, e.g. send_interfaces or send_on_all_interfaces enabled */
    MulticastSocket[] mcast_send_sockets=null;

    /**
     * Traffic class for sending unicast and multicast datagrams.
     * Valid values are (check {@link DatagramSocket#setTrafficClass(int)} );  for details):
     * <UL>
     * <LI><CODE>IPTOS_LOWCOST (0x02)</CODE>, <b>decimal 2</b></LI>
     * <LI><CODE>IPTOS_RELIABILITY (0x04)</CODE><, <b>decimal 4</b>/LI>
     * <LI><CODE>IPTOS_THROUGHPUT (0x08)</CODE>, <b>decimal 8</b></LI>
     * <LI><CODE>IPTOS_LOWDELAY (0x10)</CODE>, <b>decimal</b> 16</LI>
     * </UL>
     */
    @Property
    int             tos=8; // valid values: 2, 4, 8 (default), 16


    /** The multicast address (mcast address and port) this member uses */
    IpAddress       mcast_addr=null;

    /** The multicast address used for sending and receiving packets */
    @Property(name="mcast_addr")
    String          mcast_addr_name="172.16.31.10";

    /** The multicast port used for sending and receiving packets */
    @Property
    int             mcast_port=7600;

    /** The multicast receiver thread */
    Thread          mcast_receiver=null;

    private final static String MCAST_RECEIVER_THREAD_NAME = "UDP mcast";

    /** The unicast receiver thread */
    UcastReceiver   ucast_receiver=null;

    /** Whether to enable IP multicasting. If false, multiple unicast datagram
     * packets are sent rather than one multicast packet */
    @Property
    boolean         ip_mcast=true;

    /** The time-to-live (TTL) for multicast datagram packets */
    @Property
    int             ip_ttl=8;

    /** Send buffer size of the multicast datagram socket */
    @Property
    int             mcast_send_buf_size=32000;

    /** Receive buffer size of the multicast datagram socket */
    @Property
    int             mcast_recv_buf_size=64000;

    /** Send buffer size of the unicast datagram socket */
    @Property
    int             ucast_send_buf_size=32000;

    /** Receive buffer size of the unicast datagram socket */
    @Property
    int             ucast_recv_buf_size=64000;


    /** Usually, src addresses are nulled, and the receiver simply sets them to the address of the sender. However,
     * for multiple addresses on a Windows loopback device, this doesn't work
     * (see http://jira.jboss.com/jira/browse/JGRP-79 and the JGroups wiki for details). This must be the same
     * value for all members of the same group. Default is true, for performance reasons */
    // private boolean null_src_addresses=true;



    /**
     * Creates the UDP protocol, and initializes the
     * state variables, does however not start any sockets or threads.
     */
    public UDP() {
    }


    public void setMulticastAddress(String addr) {this.mcast_addr_name=addr;}
    public String getMulticastAddress() {return mcast_addr_name;}
    public int getMulticastPort() {return mcast_port;}
    public void setMulticastPort(int mcast_port) {this.mcast_port=mcast_port;}


    /* ----------------------- Receiving of MCAST UDP packets ------------------------ */

    public void run() {
        final byte      receive_buf[]=new byte[65535];
        int             offset, len, sender_port;
        InetAddress     sender_addr;
        Address         sender;

        final DatagramPacket packet=new DatagramPacket(receive_buf, receive_buf.length);

        while(mcast_receiver != null && mcast_sock != null) {
            try {
                mcast_sock.receive(packet);
                len=packet.getLength();
{'fraction_non_alphanumeric': 0.10363666014350946, 'fraction_numerical': 0.016552511415525113, 'mean_word_length': 2.982142857142857, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4650291', 'n_tokens_mistral': 3903, 'n_tokens_neox': 3585, 'n_words': 1218}