com.realtime.xmpp.dom
Class DomPacketSender

java.lang.Object
  |
  +--com.realtime.xmpp.dom.DomPacketSender
All Implemented Interfaces:
DomPacketListener

public class DomPacketSender
extends java.lang.Object
implements DomPacketListener

Helper class to send a packet and then wait for a response from the server. This class includes a timer that contrains the amount of time it will wait for a response packet. If you want to customize the timer, use the send( packet, timeout ) method.

Version:
1.0 Copyright © 2002 Real Time Entertainment Group, LLC - All rights reserved.
Author:
Mike Prince

Field Summary
static long DEFAULT_PACKET_TIMEOUT
          The default packet timeout in milliseconds.
protected  java.lang.Object m_packetMonitor
          Packet ready monitor.
protected  org.dom4j.Element m_response
          The response to our sent packet.
protected  java.lang.String m_sPacketId
          The packet id we have sent.
protected  Xmpp2DomTransformer m_transformer
          The XMPP to DOM transformer we should receive packets from.
 
Constructor Summary
DomPacketSender(Xmpp2DomTransformer transformer)
          Construct a packet sender to work with the DOM transformer.
 
Method Summary
 void incomingPacket(org.dom4j.Element packet)
          Signal a new packet has arrived from the stream.
 org.dom4j.Element query(XmppQuery request)
          Send a packet and wait for the response for a finite amount of time.
 org.dom4j.Element query(XmppQuery request, long timeout)
          Send a packet and wait for the response for a finite amount of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_packetMonitor

protected java.lang.Object m_packetMonitor
Packet ready monitor.


m_transformer

protected Xmpp2DomTransformer m_transformer
The XMPP to DOM transformer we should receive packets from.


m_sPacketId

protected java.lang.String m_sPacketId
The packet id we have sent.


m_response

protected org.dom4j.Element m_response
The response to our sent packet.


DEFAULT_PACKET_TIMEOUT

public static final long DEFAULT_PACKET_TIMEOUT
The default packet timeout in milliseconds. This is set to 20 seconds.

See Also:
Constant Field Values
Constructor Detail

DomPacketSender

public DomPacketSender(Xmpp2DomTransformer transformer)

Construct a packet sender to work with the DOM transformer.

Parameters:
transformer - The XMPP to DOM transformer to register with.
Method Detail

incomingPacket

public void incomingPacket(org.dom4j.Element packet)

Signal a new packet has arrived from the stream. The packet id is matched against the outgoing packets id, and if matching, will unblock the send() method and return the incoming packet as the result.

If the request packet did not have an id, then the first packet received will automatically match and be considered the response.

Specified by:
incomingPacket in interface DomPacketListener
Parameters:
packet - The XMPP packet as a DOM element.

query

public org.dom4j.Element query(XmppQuery request)
                        throws java.io.IOException

Send a packet and wait for the response for a finite amount of time. Uses the DEFAULT_PACKET_TIMEOUT value of 20 seconds.

Parameters:
request - The packet to send.
Returns:
The response as a DOM element.
Throws:
java.io.IOException - Generated when there is a problem writing the outgoing packet to the Jabber server.

query

public org.dom4j.Element query(XmppQuery request,
                               long timeout)
                        throws java.io.IOException

Send a packet and wait for the response for a finite amount of time.

Parameters:
request - The packet to send.
timeout - The maximum length of time, in milliseconds, to wait for a response.
Returns:
The response as a DOM element.
Throws:
java.io.IOException - Generated when there is a problem writing the outgoing packet to the Jabber server.


Copyright © 2002,2003 Real Time Entertainment Group, LLC. All Rights Reserved.