|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jmythapi.protocol.impl.BackendConnection
public class BackendConnection
Field Summary |
---|
Fields inherited from interface org.jmythapi.protocol.IBackendConnection |
---|
DEFAULT_COMMAND_PORT |
Constructor Summary | |
---|---|
BackendConnection(String hostname)
|
|
BackendConnection(String hostname,
int port)
|
Method Summary | |
---|---|
void |
addEventListener(IMythEventPacketListener listener)
Registers a new event listener. |
boolean |
canReadData()
Checks if data is available to read without blocking. |
boolean |
canReadPacket()
Checks if at least PacketUtils.SIZE_STRING_LENGTH bytes
can be read from the underlying input stream without blocking. |
void |
close()
Closes the connection to the MythTV-backend. |
void |
enableEventListening()
Enables event listening. |
int |
getConnectTimeout()
|
String |
getHostname()
Gets the host name of the backend. |
int |
getPort()
Gets the port of the backend. |
int |
getReadTimeout()
|
ProtocolVersion |
getVersionNr()
Gets the protocol-version of an object. |
boolean |
isAnnotated()
|
boolean |
isClosed()
Gets the curernt connection state. |
boolean |
isOpen()
|
protected boolean |
negotiate()
|
void |
open()
Opens the connection. |
void |
open(int streamBufferSize,
boolean tcpNoDelay)
Opens the connection. |
int |
readData(byte[] b,
int offset,
int len)
Reads bytes from the socket. |
IMythPacket |
readPacket()
Receives the next packet from the backend. |
protected IMythPacket |
readPacketFromQueue()
|
protected IMythPacket |
readPacketFromSocket()
|
void |
removeEventListener(IMythEventPacketListener listener)
Unregisters an event listener. |
void |
setConnectTimeout(int connectTimeout)
|
void |
setInitialVersionNr(ProtocolVersion initialProtoVersion)
Sets the initla protocol-version to use. |
void |
setMsgDebugOut(PrintStream out)
Sets a print stream used to log packets. |
void |
setReadTimeout(int readTimeout)
|
String |
toString()
|
void |
writeMessage(IMythRequest msg)
Sends a request-message to the backend. |
void |
writePacket(IMythPacket packet)
Sends a packet to the backend. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BackendConnection(String hostname)
public BackendConnection(String hostname, int port)
Method Detail |
---|
public void setInitialVersionNr(ProtocolVersion initialProtoVersion) throws IllegalStateException
IBackendConnection
This function sets the initial protocol-version that will be used by the connection
during version negotiation in the course of IBackendConnection.open()
.
This is mainly usefull to speedup connection establishing.
setInitialVersionNr
in interface IBackendConnection
initialProtoVersion
- the initial protocol version.
IllegalStateException
- if the connection is already opened.public int getConnectTimeout()
getConnectTimeout
in interface IBackendConnection
public void setConnectTimeout(int connectTimeout)
setConnectTimeout
in interface IBackendConnection
public int getReadTimeout()
getReadTimeout
in interface IBackendConnection
public void setReadTimeout(int readTimeout)
setReadTimeout
in interface IBackendConnection
public void setMsgDebugOut(PrintStream out)
IBackendConnection
This method sets a print-stream that is used to log
incoming and outgoing packets.
This is mainly used for debugging.
backendConnection.setMsgDebugOut(System.out);
setMsgDebugOut
in interface IBackendConnection
out
- a print-stream to log messages.public String getHostname()
IBackendConnection
getHostname
in interface IBackendConnection
public int getPort()
IBackendConnection
getPort
in interface IBackendConnection
public ProtocolVersion getVersionNr()
IVersionable
getVersionNr
in interface IVersionable
public void open() throws IOException
IBackendConnection
This function opens the connection to the MythTV-backend and negotiates the protocol version to use.
open
in interface IBackendConnection
IOException
- on communication errors.public void open(int streamBufferSize, boolean tcpNoDelay) throws IOException
IBackendConnection
This function opens the connection to the MythTV-backend and negotiates the protocol version to use.
open
in interface IBackendConnection
streamBufferSize
- the stream buffer size to use
IOException
- on communication errorspublic void close()
IBackendConnection
close
in interface Closeable
close
in interface IBackendConnection
public boolean isClosed()
IBackendConnection
isClosed
in interface IBackendConnection
true
if the connection was not established so far or is already closed.public boolean isOpen()
public boolean isAnnotated()
protected boolean negotiate() throws IOException
IOException
public IMythPacket readPacket() throws IOException
IBackendConnection
readPacket
in interface IBackendConnection
IOException
- on communication errors.protected IMythPacket readPacketFromQueue() throws IOException
IOException
protected IMythPacket readPacketFromSocket() throws IOException
IOException
public boolean canReadPacket() throws IOException
IBackendConnection
PacketUtils.SIZE_STRING_LENGTH
bytes
can be read from the underlying input stream without blocking.
This function can be used to check if we should start reading the next packet.
canReadPacket
in interface IBackendConnection
true
if the next packet can be read
IOException
- on communication errorspublic void writePacket(IMythPacket packet) throws IOException
IBackendConnection
writePacket
in interface IBackendConnection
packet
- to packet to transfer
IOException
- on communication errors.public void writeMessage(IMythRequest msg) throws IOException
IBackendConnection
writeMessage
in interface IBackendConnection
msg
- the request message to be send
IOException
- on communication errors
UnknownCommandException
- if the given command is unknown
UnsupportedCommandException
- if the given command is not supported by the given protocol versionpublic int readData(byte[] b, int offset, int len) throws IOException
IBackendConnection
readData
in interface IBackendConnection
b
- the byte array to fill with dataoffset
- to offset used to start writing into the arraylen
- the amount of bytes to read
IOException
- on communication errorspublic boolean canReadData() throws IOException
IBackendConnection
canReadData
in interface IBackendConnection
true
if at least one byte is available to read without blocking.
IOException
- on communication errorspublic void enableEventListening()
IBackendConnection
This function starts a new thread, which reads incoming IMythPacket
and passes them
to event listeners, if the received packets are event packets.
enableEventListening
in interface IBackendConnection
public void addEventListener(IMythEventPacketListener listener)
IBackendConnection
addEventListener
in interface IBackendConnection
listener
- the listener to registerpublic void removeEventListener(IMythEventPacketListener listener)
IBackendConnection
removeEventListener
in interface IBackendConnection
listener
- the listener to unregister.public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |