Class DynamicAddressChannel
- java.lang.Object
-
- org.jivesoftware.openfire.mediaproxy.DynamicAddressChannel
-
- All Implemented Interfaces:
Runnable
,DatagramListener
public class DynamicAddressChannel extends Object implements Runnable, DatagramListener
Listen packets from defined dataSocket and send packets to the defined host. But also provides a mechanism to dynamic bind host and port implementing DatagramListener methods to change the host and port values according to the received packets.- Author:
- Thiago Camargo
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buf
protected DatagramSocket
dataSocket
protected boolean
enabled
protected InetAddress
host
protected DatagramPacket
packet
protected int
port
-
Constructor Summary
Constructors Constructor Description DynamicAddressChannel(DatagramSocket dataSocket, InetAddress host, int port)
Default Channel Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(DatagramListener datagramListener)
Adds a DatagramListener to the Channelvoid
cancel()
boolean
datagramReceived(DatagramPacket datagramPacket)
Implement DatagramListener method.InetAddress
getHost()
Get the host that the packet will be sent to.int
getPort()
Get the port that the packet will be sent to.void
relayPacket(DatagramPacket packet)
void
removeListener(DatagramListener datagramListener)
Remove a DatagramListener from the Channelvoid
removeListeners()
Remove every Listenersvoid
run()
Thread override methodprotected void
setHost(InetAddress host)
Set the host that the packet will be sent to.protected void
setPort(int port)
Set the port that the packet will be sent to.
-
-
-
Field Detail
-
buf
protected byte[] buf
-
dataSocket
protected DatagramSocket dataSocket
-
packet
protected DatagramPacket packet
-
enabled
protected boolean enabled
-
host
protected InetAddress host
-
port
protected int port
-
-
Constructor Detail
-
DynamicAddressChannel
public DynamicAddressChannel(DatagramSocket dataSocket, InetAddress host, int port)
Default Channel Constructor- Parameters:
dataSocket
- datasocket to used to send and receive packetshost
- default destination host for received packetsport
- default destination port for received packets
-
-
Method Detail
-
datagramReceived
public boolean datagramReceived(DatagramPacket datagramPacket)
Implement DatagramListener method. Set the host and port value to the host and port value from the received packet.- Specified by:
datagramReceived
in interfaceDatagramListener
- Parameters:
datagramPacket
- the received packet- Returns:
- ?
-
getHost
public InetAddress getHost()
Get the host that the packet will be sent to.- Returns:
- remote host address
-
setHost
protected void setHost(InetAddress host)
Set the host that the packet will be sent to.- Parameters:
host
- the host to send the packet to
-
getPort
public int getPort()
Get the port that the packet will be sent to.- Returns:
- The remote port number
-
setPort
protected void setPort(int port)
Set the port that the packet will be sent to.- Parameters:
port
- the port to send the packet to
-
addListener
public void addListener(DatagramListener datagramListener)
Adds a DatagramListener to the Channel- Parameters:
datagramListener
- the listener to add
-
removeListener
public void removeListener(DatagramListener datagramListener)
Remove a DatagramListener from the Channel- Parameters:
datagramListener
- the listener to remove
-
removeListeners
public void removeListeners()
Remove every Listeners
-
cancel
public void cancel()
-
relayPacket
public void relayPacket(DatagramPacket packet)
-
-