com.epam.common.transport.client.udp
Class UDPTransport

java.lang.Object
  extended by com.epam.common.transport.client.udp.UDPTransport
All Implemented Interfaces:
ClientTransport, Transport

public class UDPTransport
extends Object
implements ClientTransport

UDP transport implementation.


Constructor Summary
UDPTransport()
          Creates UDP transport.
UDPTransport(String multicastAddress, int port)
          Creates UDP transport.
 
Method Summary
 void close()
          Closes the transport.
 String getAddress()
          Getter for address value.
 int getPort()
          Getter for port value.
 boolean isBlockingSocket()
           
 boolean isOpen()
          Returns true if, transport is open.
 void open()
          Method opens the transport.
 int read(byte[] buffer)
          Transport dependent read method.
 int read(byte[] buffer, int offset, int length)
          Transport dependent read method.
 int read(ByteBuffer buffer)
           
 int read(ByteBuffer buffer, int offset, int length)
           
 void setAddress(String multicastAddress)
          Setter for multicat address.
 void setBufferSize(int bufferSize)
           
 void setNetworkInterfaceName(String networkInterface)
          Setter for network interface.
 void setPort(int port)
          Setter for port.
 void setSocketFactory(SocketFactory socketFactory)
           
 void waitUntilReadyToWrite()
           
 void write(byte[] message)
          Transport dependent write method.
 int write(byte[] message, int offset, int length)
          Transport dependent write method.
 int write(ByteBuffer buffer)
           
 int write(ByteBuffer buffer, int offset, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPTransport

public UDPTransport()
Creates UDP transport.


UDPTransport

public UDPTransport(String multicastAddress,
                    int port)
Creates UDP transport.

Parameters:
multicastAddress - the multicast address
port - the transport port
Method Detail

setSocketFactory

public void setSocketFactory(SocketFactory socketFactory)
Specified by:
setSocketFactory in interface ClientTransport

isBlockingSocket

public boolean isBlockingSocket()
Specified by:
isBlockingSocket in interface Transport

setNetworkInterfaceName

public void setNetworkInterfaceName(String networkInterface)
Setter for network interface.

Parameters:
networkInterface -

setBufferSize

public void setBufferSize(int bufferSize)

setAddress

public void setAddress(String multicastAddress)
Setter for multicat address.

Specified by:
setAddress in interface ClientTransport
Parameters:
multicastAddress - the multicat address

setPort

public void setPort(int port)
Setter for port.

Specified by:
setPort in interface ClientTransport
Parameters:
port - the transport port

open

public void open()
          throws IOException
Method opens the transport. The implementation create a multicast socket and bind it to a specific port, and then joins created socket to multicast group.

Specified by:
open in interface Transport
Throws:
IOException - - if an I/O error occurs.

close

public void close()
           throws IOException
Closes the transport.

Leave a multicast group and close socket.

Specified by:
close in interface Transport
Throws:
IOException - - if an I/O error occurs.

isOpen

public boolean isOpen()
Description copied from interface: Transport
Returns true if, transport is open.

Specified by:
isOpen in interface Transport
See Also:
Transport.isOpen()

write

public void write(byte[] message)
           throws IOException
Description copied from interface: Transport
Transport dependent write method.

Specified by:
write in interface Transport
Parameters:
message - actual message
Throws:
IOException - if unable to write
See Also:
Transport.write(byte[])

write

public int write(byte[] message,
                 int offset,
                 int length)
          throws IOException
Description copied from interface: Transport
Transport dependent write method.

Specified by:
write in interface Transport
Parameters:
message - actual message
offset - the offset in buffer
length - the num of bytes to write
Throws:
IOException - if unable to write

read

public int read(byte[] buffer)
         throws IOException
Description copied from interface: Transport
Transport dependent read method.

Specified by:
read in interface Transport
Parameters:
buffer - holder for read bytes
Returns:
number of byte actually read
Throws:
IOException - if unable to read
See Also:
Transport.read(byte[])

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IOException
Description copied from interface: Transport
Transport dependent read method.

Specified by:
read in interface Transport
Parameters:
buffer - holder for read bytes
offset - in buffer
length - maximum bytes to be read
Returns:
number of byte actually read
Throws:
IOException - if unable to read
See Also:
Transport.read(byte[], int, int)

getAddress

public String getAddress()
Description copied from interface: Transport
Getter for address value.

Specified by:
getAddress in interface Transport
See Also:
Transport.getAddress()

getPort

public int getPort()
Description copied from interface: Transport
Getter for port value.

Specified by:
getPort in interface Transport
See Also:
Transport.getPort()

write

public int write(ByteBuffer buffer)
          throws IOException
Specified by:
write in interface ClientTransport
Specified by:
write in interface Transport
Throws:
IOException

write

public int write(ByteBuffer buffer,
                 int offset,
                 int length)
          throws IOException
Specified by:
write in interface ClientTransport
Specified by:
write in interface Transport
Throws:
IOException

read

public int read(ByteBuffer buffer,
                int offset,
                int length)
         throws IOException
Specified by:
read in interface ClientTransport
Specified by:
read in interface Transport
Throws:
IOException

read

public int read(ByteBuffer buffer)
         throws IOException
Specified by:
read in interface ClientTransport
Specified by:
read in interface Transport
Throws:
IOException

waitUntilReadyToWrite

public void waitUntilReadyToWrite()
                           throws IOException
Specified by:
waitUntilReadyToWrite in interface Transport
Throws:
IOException


Copyright © 2000-2014 EPAM Systems. All Rights Reserved.