Asterisk-Java

org.asteriskjava.util.internal
Class SocketConnectionFacadeImpl

java.lang.Object
  extended by org.asteriskjava.util.internal.SocketConnectionFacadeImpl
All Implemented Interfaces:
SocketConnectionFacade

public class SocketConnectionFacadeImpl
extends java.lang.Object
implements SocketConnectionFacade

Default implementation of the SocketConnectionFacade interface using java.io.

Version:
$Id: SocketConnectionFacadeImpl.java 1097 2008-08-09 01:52:47Z sprior $
Author:
srt

Constructor Summary
SocketConnectionFacadeImpl(java.lang.String host, int port, boolean ssl, int timeout, int readTimeout)
          Creates a new instance for use with the Manager API that uses CRNL ("\r\n") as line delimiter.
 
Method Summary
 void close()
          Closes the socket connection including its input and output stream and frees all associated ressources.
 void flush()
          Flushes the socket connection by sending any buffered but yet unsent data.
 java.net.InetAddress getLocalAddress()
          Returns the local address this socket connection.
 int getLocalPort()
          Returns the local port of this socket connection.
 java.net.InetAddress getRemoteAddress()
          Returns the remote address of this socket connection.
 int getRemotePort()
          Returns the remote port of this socket connection.
 boolean isConnected()
          Returns the connection state of the socket.
 java.lang.String readLine()
          Reads a line of text from the socket connection.
 void write(java.lang.String s)
          Sends a given String to the socket connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnectionFacadeImpl

public SocketConnectionFacadeImpl(java.lang.String host,
                                  int port,
                                  boolean ssl,
                                  int timeout,
                                  int readTimeout)
                           throws java.io.IOException
Creates a new instance for use with the Manager API that uses CRNL ("\r\n") as line delimiter.

Parameters:
host - the foreign host to connect to.
port - the foreign port to connect to.
ssl - true to use SSL, false otherwise.
timeout - 0 incidcates default
readTimeout - see Socket.setSoTimeout(int)
Throws:
java.io.IOException - if the connection cannot be established.
Method Detail

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Reads a line of text from the socket connection. The current thread is blocked until either the next line is received or an IOException encounters.

Depending on the implementation different newline delimiters are used ("\r\n" for the Manager API and "\n" for AGI).

Specified by:
readLine in interface SocketConnectionFacade
Returns:
the line of text received excluding the newline delimiter.
Throws:
java.io.IOException - if the connection has been closed.

write

public void write(java.lang.String s)
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Sends a given String to the socket connection.

Specified by:
write in interface SocketConnectionFacade
Parameters:
s - the String to send.
Throws:
java.io.IOException - if the String cannot be sent, maybe because the connection has already been closed.

flush

public void flush()
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Flushes the socket connection by sending any buffered but yet unsent data.

Specified by:
flush in interface SocketConnectionFacade
Throws:
java.io.IOException - if the connection cannot be flushed.

close

public void close()
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Closes the socket connection including its input and output stream and frees all associated ressources.

When calling close() any Thread currently blocked by a call to readLine() will be unblocked and receive an IOException.

Specified by:
close in interface SocketConnectionFacade
Throws:
java.io.IOException - if the socket connection cannot be closed.

isConnected

public boolean isConnected()
Description copied from interface: SocketConnectionFacade
Returns the connection state of the socket.

Specified by:
isConnected in interface SocketConnectionFacade
Returns:
true if the socket successfuly connected to a server

getLocalAddress

public java.net.InetAddress getLocalAddress()
Description copied from interface: SocketConnectionFacade
Returns the local address this socket connection.

Specified by:
getLocalAddress in interface SocketConnectionFacade
Returns:
the local address this socket connection.

getLocalPort

public int getLocalPort()
Description copied from interface: SocketConnectionFacade
Returns the local port of this socket connection.

Specified by:
getLocalPort in interface SocketConnectionFacade
Returns:
the local port of this socket connection.

getRemoteAddress

public java.net.InetAddress getRemoteAddress()
Description copied from interface: SocketConnectionFacade
Returns the remote address of this socket connection.

Specified by:
getRemoteAddress in interface SocketConnectionFacade
Returns:
the remote address of this socket connection.

getRemotePort

public int getRemotePort()
Description copied from interface: SocketConnectionFacade
Returns the remote port of this socket connection.

Specified by:
getRemotePort in interface SocketConnectionFacade
Returns:
the remote port of this socket connection.

Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.