com.realtime.xmpp.util
Class RestartingEndpoint

java.lang.Object
  |
  +--com.realtime.xmpp.util.RestartingEndpoint
All Implemented Interfaces:
XmppEndpoint
Direct Known Subclasses:
DomComponent

public abstract class RestartingEndpoint
extends java.lang.Object
implements XmppEndpoint

An XMPP endpoint for a Jabber server. Maintains a connection to a Jabber server using the host, port, and namespace specified in the constructor.

Use start() to start the component and establish a connection to the Jabber server, and stop() to break the connection.

The component will re-establish failed connections by using the XmppSessionRestarter class.

Version:
1.0
Author:
Mike Prince

Field Summary
protected  XmppSession m_session
          The XMPP session to the Jabber server.
protected  XmppSessionRestarter m_sessionRestarter
          A session restarter, to keep-alive the session.
static long XMPP_REQUEST_TIMEOUT
          A reasonable default XMPP request timeout in milliseconds.
 
Constructor Summary
RestartingEndpoint(java.lang.String sHost, int nPort, java.lang.String sNamespace)
          Create a Jabber component connected to a specific host and port, and using one of the four namespaces.
RestartingEndpoint(XmlStreamFactory streamFactory, java.lang.String sNamespace)
          Create a Jabber component connected to a specific host and port, and using one of the four namespaces.
 
Method Summary
 void fastStart()
          Starts the component.
 JID getComponentName()
          Provide the name of this component.
 XmppSession getSession()
          Provide the underlying XMPP session.
 void start()
          Starts the component.
 void stop()
          Stop the component and close the stream to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.realtime.xmpp.XmppEndpoint
send
 

Field Detail

m_session

protected XmppSession m_session
The XMPP session to the Jabber server.


m_sessionRestarter

protected XmppSessionRestarter m_sessionRestarter
A session restarter, to keep-alive the session.


XMPP_REQUEST_TIMEOUT

public static final long XMPP_REQUEST_TIMEOUT
A reasonable default XMPP request timeout in milliseconds.

See Also:
Constant Field Values
Constructor Detail

RestartingEndpoint

public RestartingEndpoint(XmlStreamFactory streamFactory,
                          java.lang.String sNamespace)

Create a Jabber component connected to a specific host and port, and using one of the four namespaces. The session will not be created until start() is called. Start also authenticates with the server using the provided secret.

Parameters:
streamFactory - An XML stream factory.
sNamespace - The Jabber namespace to use.

RestartingEndpoint

public RestartingEndpoint(java.lang.String sHost,
                          int nPort,
                          java.lang.String sNamespace)

Create a Jabber component connected to a specific host and port, and using one of the four namespaces. The session will not be created until start() is called. Start also authenticates with the server using the provided secret.

Parameters:
sHost - The host name to connect to.
nPort - The server port to connect to.
sNamespace - The Jabber namespace to use.
Method Detail

getSession

public XmppSession getSession()

Provide the underlying XMPP session. The session might be open or closed.

Specified by:
getSession in interface XmppEndpoint
Returns:
The XMPP session.

fastStart

public void fastStart()
               throws java.io.IOException

Starts the component. Opens the socket and starts XMPP streaming. If you are interested in the XMPP session lifecycle events, then register using getSession().addListener().

NOTE: This is a non-blocking call and will likely return BEFORE the stream is ready to write to. If you want to know when the stream is ready for writing, call getSession().waitForOpen() or write an XmppSessionListener and look for the SESSION_STARTED event.

Specified by:
fastStart in interface XmppEndpoint
Throws:
java.io.IOException - Generated when the component could not start.

start

public void start()
           throws java.io.IOException

Starts the component. Opens the socket and starts XMPP streaming. If you are interested in the XMPP session lifecycle events, then register using getSession().addListener().

This is a blocking call and uses getSession().waitForOpen() to wait until the stream has been established. Uses the default XMPP request timeout of 20 seconds.

Specified by:
start in interface XmppEndpoint
Throws:
java.io.IOException - Generated when the component could not start.

stop

public void stop()

Stop the component and close the stream to the server. Also disable the sesson restarter.

Specified by:
stop in interface XmppEndpoint

getComponentName

public JID getComponentName()

Provide the name of this component. This method will only work AFTER a session has been started.

* @return The name of this component.

Specified by:
getComponentName in interface XmppEndpoint
Returns:
The name of this component.


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