Package biz.onixs.util.network
Class MulticastReceiver
- java.lang.Object
-
- biz.onixs.util.network.MulticastReceiver
-
- All Implemented Interfaces:
IMulticastReceiver,Closeable,AutoCloseable
- Direct Known Subclasses:
MulticastThreadReceiver
public class MulticastReceiver extends Object implements IMulticastReceiver
- Author:
- vmelnyk Notes about implementation: all requests such as join/drop multicast groups will be processed in step() method.
-
-
Field Summary
Fields Modifier and Type Field Description static intPACKET_MAXSIZE
-
Constructor Summary
Constructors Constructor Description MulticastReceiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddrop(MulticastGroup feed)Drops (and closes) attached feed.MulticastGroupjoin(String groupId, int port, NetworkInterface nif, MulticastListener listener)Short version of join with default buffer sizeMulticastGroupjoin(String groupId, int port, NetworkInterface nif, MulticastListener listener, int bufferSize)Creates a feed and send a join request.MulticastGroupjoin(InetSocketAddress group, NetworkInterface nif, MulticastListener listener)Short version of join with default buffer sizeMulticastGroupjoin(InetSocketAddress group, NetworkInterface nif, MulticastListener listener, int bufferSize)Creates a feed and send a join request.booleanstep()process one step of receiving.
-
-
-
Field Detail
-
PACKET_MAXSIZE
public static final int PACKET_MAXSIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MulticastReceiver
public MulticastReceiver() throws IOException- Throws:
IOException
-
-
Method Detail
-
join
public MulticastGroup join(String groupId, int port, NetworkInterface nif, MulticastListener listener)
Short version of join with default buffer size
This method is equivalent to:
join(groupId, port, nif, listener, MulticastReceiver.PACKET_MAXSIZE);- Specified by:
joinin interfaceIMulticastReceiver- Parameters:
groupId- a multicast address to joinport- port number where to receive UDP packetsnif- The network interface on which to join the grouplistener- of the MulticastGroup events.- Returns:
- created MulticastGroup
-
join
public MulticastGroup join(String groupId, int port, NetworkInterface nif, MulticastListener listener, int bufferSize)
Creates a feed and send a join request.- Specified by:
joinin interfaceIMulticastReceiver- Parameters:
groupId- a multicast address to joinport- port number where to receive UDP packetsnif- The network interface on which to join the grouplistener- listener of the MulticastGroup events.bufferSize- max packet size for this multicast group- Returns:
- created MulticastGroup
-
join
public MulticastGroup join(InetSocketAddress group, NetworkInterface nif, MulticastListener listener, int bufferSize)
Creates a feed and send a join request.This implementation creates a new handler to receive, and puts it into join queue. All such requests will be proceed in
step()method- Specified by:
joinin interfaceIMulticastReceiver- Parameters:
group- a multicast address to join with UDP port Numbernif- The network interface on which to join the grouplistener- of the MulticastGroup events.bufferSize- buffer size for UDP packets of the corresponded group- Returns:
- created MulticastGroup to receive multicast group messages
-
join
public MulticastGroup join(InetSocketAddress group, NetworkInterface nif, MulticastListener listener)
Short version of join with default buffer size
This method is equivalent to:
Creates a feed and send a join request.join(group, nif, listener, MulticastReceiver.PACKET_MAXSIZE);- Specified by:
joinin interfaceIMulticastReceiver- Parameters:
group- a multicast address to join with UDP port Numbernif- The network interface on which to join the grouplistener- of the MulticastGroup events.- Returns:
- created MulticastGroup to receive multicast group messages
-
drop
public void drop(MulticastGroup feed)
Drops (and closes) attached feed. If feed doesn't belong to this Receiver, it will not be dropped.- Specified by:
dropin interfaceIMulticastReceiver- Parameters:
feed- feed to drop from receiving multicast
-
step
public boolean step()
process one step of receiving. It's: 1. Adds all feeds added by join function 2. Drops/removes feeds from drop list 3. Proceeds all opened connections- Specified by:
stepin interfaceIMulticastReceiver- Returns:
- false if MulticastReceiver cannot work farther and must be closed, true if everything going well
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-