SMACK-279: The XMPPConnection extends the new abstract Connection class

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11613 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Günther Niess 2010-02-09 11:55:56 +00:00 committed by niess
parent 11a41e79ca
commit 127319a821
102 changed files with 1420 additions and 1194 deletions

View File

@ -19,8 +19,9 @@
</p>
<p>
The <tt>org.jivesoftware.smack.XMPPConnection</tt> class manages your connection to an XMPP
server. Two constructors are available. The first, <tt>XMPPConnection(String)</tt> takes
The <tt>org.jivesoftware.smack.Connection</tt> class manages your connection to an XMPP
server. The default implementation is the <tt>org.jivesoftware.smack.XMPPConnection</tt>
class. Two constructors are mainly used. The first, <tt>XMPPConnection(String)</tt> takes
the server name you'd like to connect to as an argument. All default connection settings will
be used:
<ul>
@ -62,7 +63,7 @@ ConnectionConfiguration config = new ConnectionConfiguration(<font color="green"
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
Connection connection = new XMPPConnection(config);
<font color="gray"><i>// Connect to the server</i></font>
connection.connect();
<font color="gray"><i>// Log into the server</i></font>
@ -79,7 +80,7 @@ manager will try to immediately reconnect to the server and increase the delay b
successive reconnections keep failing.</i>
<br>
In case you want to force a reconnection while the reconnetion manager is waiting for the next
reconnection, you can just use <i>XMPPConnection#connect()</i> and a new attempt will be made.
reconnection, you can just use <i>Connection#connect()</i> and a new attempt will be made.
If the manual attempt also failed then the reconnection manager will still continue the
reconnection job.
</p>

View File

@ -26,7 +26,7 @@ Debugging mode can be enabled in two different ways:
<ol>
<li>Add the following line of code <b>before</b> creating new connections:<p>
<tt>XMPPConnection.DEBUG_ENABLED = true;</tt><p>
<tt>Connection.DEBUG_ENABLED = true;</tt><p>
<li>Set the Java system property <tt>smack.debugEnabled</tt> to true. The
system property can be set on the command line such as:<p>
@ -39,7 +39,7 @@ add the following line to your application before opening new connections:
</p>
<p>
<tt>XMPPConnection.DEBUG_ENABLED = false;</tt>
<tt>Connection.DEBUG_ENABLED = false;</tt>
</p>
<p>

View File

@ -34,9 +34,9 @@ discovery request with the information that you previously configured.</p>
<b>Usage</b><p>
In order to configure the supported features by your client you should first obtain the
ServiceDiscoveryManager associated with your XMPPConnection. To get your ServiceDiscoveryManager
ServiceDiscoveryManager associated with your Connection. To get your ServiceDiscoveryManager
send <b>getInstanceFor(connection)</b> to the class <i><b>ServiceDiscoveryManager</b></i> where
connection is your XMPPConnection.<br></p>
connection is your Connection.<br></p>
<p>Once you have your ServiceDiscoveryManager you will be able to manage the supported features. To
register a new feature send <b>addFeature(feature)</b> to your <i><b>ServiceDiscoveryManager</b></i>
@ -48,7 +48,7 @@ String that represents the feature to remove.</p>
In this example we can see how to add and remove supported features: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my Connection</font>
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
<font color="#3f7f5f">// Register that a new feature is supported by this XMPP entity</font>
@ -74,7 +74,7 @@ to configure the information providers associated to the items/nodes within the
In order to configure the associated nodes within the Smack client you will need to create a
NodeInformationProvider and register it with the <i><b>ServiceDiscoveryManager</b></i>. To get
your ServiceDiscoveryManager send <b>getInstanceFor(connection)</b> to the class <i><b>ServiceDiscoveryManager</b></i>
where connection is your XMPPConnection.<br></p>
where connection is your Connection.<br></p>
<p>Once you have your ServiceDiscoveryManager you will be able to register information providers
for the XMPP entity's nodes. To register a new node information provider send <b>setNodeInformationProvider(String node, NodeInformationProvider listener)</b>
@ -126,7 +126,7 @@ the discovered items.</p>
In this example we can see how to discover the items associated with an online catalog service: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my Connection</font>
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
<font color="#3f7f5f">// Get the items of a given XMPP entity</font>
@ -171,7 +171,7 @@ the discovered information.</p>
In this example we can see how to discover the information of a conference room: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my Connection</font>
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
<font color="#3f7f5f">// Get the information of a given XMPP entity</font>
@ -216,7 +216,7 @@ to publish.</p>
In this example we can see how to publish new items: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my Connection</font>
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
<font color="#3f7f5f">// Create a DiscoverItems with the items to publish</font>

View File

@ -34,7 +34,7 @@ to enable the user to easily send a file.
<b>Usage</b><p>
In order to send a file you must first construct an instance of the <b><i>FileTransferManager</i></b>
class. This class has one constructor with one parameter which is your XMPPConnection.
class. This class has one constructor with one parameter which is your Connection.
In order to instantiate the manager you should call <i>new FileTransferManager(connection)</i>
<p>Once you have your <b><i>FileTransferManager</i></b> you will need to create an outgoing
@ -86,7 +86,7 @@ manager.</p>
<b>Usage</b><p>
In order to recieve a file you must first construct an instance of the <b><i>FileTransferManager</i></b>
class. This class has one constructor with one parameter which is your XMPPConnection.
class. This class has one constructor with one parameter which is your Connection.
In order to instantiate the manager you should call <i>new FileTransferManager(connection)</i>
<p>Once you have your <b><i>FileTransferManager</i></b> you will need to register a listener

View File

@ -75,14 +75,14 @@ You can receive notification requests for the following events: delivered, displ
The general idea is to create a new <i>DefaultMessageEventRequestListener</i> that will listen to the event notifications
requests and react with custom logic. Then you will have to add the listener to the
<i>MessageEventManager</i> that works on
the desired <i>XMPPConnection</i>.
the desired <i>Connection</i>.
<p>Note that <i>DefaultMessageEventRequestListener</i> is a default implementation of the
<i>MessageEventRequestListener</i> interface.
The class <i>DefaultMessageEventRequestListener</i> automatically sends a delivered notification to the sender of the message
if the sender has requested to be notified when the message is delivered. If you decide to create a new class that
implements the <i>MessageEventRequestListener</i> interface, please remember to send the delivered notification.</p>
<ul>
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(XMPPConnection)</b></i> constructor.
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(Connection)</b></i> constructor.
</li>
<li>To create an event notification requests listener create a subclass of <i><b>DefaultMessageEventRequestListener</b></i> or
create a class that implements the <i><b>MessageEventRequestListener</b></i> interface.
@ -178,9 +178,9 @@ will probably want to react to some or all of these events.</p>
The general idea is to create a new <i>MessageEventNotificationListener</i> that will listen to the event notifications
and react with custom logic. Then you will have to add the listener to the <i>MessageEventManager</i> that works on
the desired <i>XMPPConnection</i>.
the desired <i>Connection</i>.
<ul>
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(XMPPConnection)</b></i> constructor.
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(Connection)</b></i> constructor.
</li>
<li>To create an event notifications listener create a class that implements the <i><b>MessageEventNotificationListener</b></i>
interface.

View File

@ -51,7 +51,7 @@ the form and finally send it back to the server.</p>
In this example we can see how to create an instant room: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using a Connection for a room</font>
MultiUserChat muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
<font color="#3f7f5f">// Create the room</font>
@ -65,7 +65,7 @@ In this example we can see how to create an instant room: <br>
In this example we can see how to create a reserved room. The form is completed with default values: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using a Connection for a room</font>
MultiUserChat muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
<font color="#3f7f5f">// Create the room</font>
@ -121,7 +121,7 @@ for a response from the server.</p>
In this example we can see how to join a room with a given nickname: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using a Connection for a room</font>
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
<font color="#3f7f5f">// User2 joins the new room</font>
@ -132,7 +132,7 @@ In this example we can see how to join a room with a given nickname: <br>
In this example we can see how to join a room with a given nickname and password: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using a Connection for a room</font>
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
<font color="#3f7f5f">// User2 joins the new room using a password</font>
@ -144,7 +144,7 @@ In this example we can see how to join a room with a given nickname and password
In this example we can see how to join a room with a given nickname specifying the amount of history
to receive: <br>
<blockquote>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
<pre> <font color="#3f7f5f">// Create a MultiUserChat using a Connection for a room</font>
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
<font color="#3f7f5f">// User2 joins the new room using a password and specifying</font>
@ -205,7 +205,7 @@ In this example we can see how to listen for room invitations and decline invita
<blockquote>
<pre> <font color="#3f7f5f">// User3 listens for MUC invitations</font>
MultiUserChat.addInvitationListener(conn3, new InvitationListener() {
public void invitationReceived(XMPPConnection conn, String room, String inviter, String reason, String password) {
public void invitationReceived(Connection conn, String room, String inviter, String reason, String password) {
<font color="#3f7f5f">// Reject the invitation</font>
MultiUserChat.decline(conn, room, inviter, <font color="#0000FF">"I'm busy right now"</font>);
}
@ -224,7 +224,7 @@ A user may want to discover if one of the user's contacts supports the Multi-Use
<b>Usage</b><p>
In order to discover if one of the user's contacts supports MUC just send
<b>isServiceEnabled(XMPPConnection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
<b>isServiceEnabled(Connection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
class where user is a fully qualified XMPP ID, e.g. jdoe@example.com. You will receive
a boolean indicating whether the user supports MUC or not.</p>
@ -248,7 +248,7 @@ A user may also want to query a contact regarding which rooms the contact is in.
<b>Usage</b><p>
In order to get the rooms where a user is in just send
<b>getJoinedRooms(XMPPConnection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
<b>getJoinedRooms(Connection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
class where user is a fully qualified XMPP ID, e.g. jdoe@example.com. You will get an Iterator
of Strings as an answer where each String represents a room name.</p>
@ -272,7 +272,7 @@ will provide information only for public rooms.</p>
<b>Usage</b><p>
In order to discover information about a room just send <b>getRoomInfo(XMPPConnection connection, String room)</b>
In order to discover information about a room just send <b>getRoomInfo(Connection connection, String room)</b>
to the <i><b>MultiUserChat</b></i> class where room is the XMPP ID of the room, e.g.
roomName@conference.myserver. You will get a RoomInfo object that contains the discovered room
information.</p>

View File

@ -47,7 +47,7 @@ a fully configured node.</p><p>
Create an instant node: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Create the node</font>
@ -58,7 +58,7 @@ Create an instant node: <br>
Create a node with default configuration and then configure it: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Create the node</font>
@ -77,7 +77,7 @@ Create a node with default configuration and then configure it: <br>
Create and configure a node: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Create the node</font>
@ -117,7 +117,7 @@ will be dependent on its configuration.
In this example we publish an item to a node that does not take payload: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -133,7 +133,7 @@ In this example we publish an item to a node that does not take payload: <br>
In this example we publish an item to a node that does take payload: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -174,7 +174,7 @@ In this example we can see how to create a listener and register it and then sub
messages. <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -212,7 +212,7 @@ In this example we can see how to create a listener, register it and then subscr
item deletion messages. <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -250,7 +250,7 @@ In this example we can see how to create a listener, register it and then subscr
node configuration messages. <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -315,7 +315,7 @@ of a <i><b>LeafNode</b></i> and call one of the retrieve methods.
In this example we can see how to retrieve the existing items from a node: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -329,7 +329,7 @@ In this example we can see how to retrieve the existing items from a node: <br>
In this example we can see how to retrieve the last N existing items: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -343,7 +343,7 @@ In this example we can see how to retrieve the specified existing items: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the node</font>
@ -375,7 +375,7 @@ or <i><b>Node</b></i> classes depending on what type of information is required.
In this example we can see how to get pubsub capabilities: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the pubsub features that are supported</font>
@ -386,7 +386,7 @@ In this example we can see how to get pubsub capabilities: <br>
In this example we can see how to get pubsub subscriptions for all nodes: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get all the subscriptions in the pubsub service</font>
@ -397,7 +397,7 @@ In this example we can see how to get pubsub subscriptions for all nodes: <br>
In this example we can see how to get all affiliations for the users bare JID on the pubsub service: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
<font color="#3f7f5f">// Get the affiliations for the users bare JID</font>
@ -408,7 +408,7 @@ In this example we can see how to get all affiliations for the users bare JID on
In this example we can see how to get information about the node: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
Node node = mgr.getNode(<font color="#0000FF">"testNode"</font>);
@ -420,7 +420,7 @@ In this example we can see how to get information about the node: <br>
In this example we can see how to discover the node items: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
Node node = mgr.getNode(<font color="#0000FF">"testNode"</font>);
@ -432,7 +432,7 @@ In this example we can see how to discover the node items: <br>
In this example we can see how to get node subscriptions: <br>
<blockquote>
<pre>
<font color="#3f7f5f">// Create a pubsub manager using an existing XMPPConnection</font>
<font color="#3f7f5f">// Create a pubsub manager using an existing Connection</font>
PubSubManager mgr = new PubSubManager(con);
Node node = mgr.getNode(<font color="#0000FF">"testNode"</font>);

View File

@ -126,7 +126,7 @@ received.</p>
<li>Create a class that implements the <i><b>RosterExchangeListener</b></i> interface.</li>
<li>Implement the method <b>entriesReceived(String, Iterator)</b> that will be called when new entries
are received with custom logic.</li>
<li>Add the listener to the <i>RosterExchangeManager</i> that works on the desired <i>XMPPConnection</i>.</li>
<li>Add the listener to the <i>RosterExchangeManager</i> that works on the desired <i>Connection</i>.</li>
</ol></p>
<b>Example</b><p>

View File

@ -97,7 +97,7 @@ the message as you do with any other message.</p>
An XHTML message is like any regular message, therefore to send the message you can follow
the usual steps you do in order to send a message. For example, to send a message as part
of a chat just use the message <b>#send(Message)</b> of <i><b>Chat</b></i> or you can use
the message <b>#send(Packet)</b> of <i><b>XMPPConnection</b></i>.</p>
the message <b>#send(Packet)</b> of <i><b>Connection</b></i>.</p>
<b>Example</b><p>
@ -170,7 +170,7 @@ section explains how to explicitly discover for XHTML support.</p>
<b>Usage</b><p>
In order to discover if a remote user supports XHTML messages send <b>#isServiceEnabled(XMPPConnection
In order to discover if a remote user supports XHTML messages send <b>#isServiceEnabled(Connection
connection, String userID)</b> to the class <i><b>XHTMLManager</b></i> where connection is the connection
to use to perform the service discovery and userID is the user to check (A fully qualified xmpp ID,
e.g. jdoe@example.com). This message will return true if the specified user handles XHTML messages.</p>

View File

@ -50,12 +50,12 @@ XMPP server. Below are code examples for making a connection:<p>
<div class="code">
<pre>
<font color="gray"><i>// Create a connection to the jabber.org server.</i></font>
XMPPConnection conn1 = <font color="navy"><b>new</b></font> XMPPConnection(<font color="green">"jabber.org"</font>);
Connection conn1 = <font color="navy"><b>new</b></font> XMPPConnection(<font color="green">"jabber.org"</font>);
conn1.connect();
<font color="gray"><i>// Create a connection to the jabber.org server on a specific port.</i></font>
ConnectionConfiguration config = new ConnectionConfiguration(<font color="green">"jabber.org"</font>, 5222);
XMPPConnection conn2 = <font color="navy"><b>new</b></font> XMPPConnection(config);
Connection conn2 = <font color="navy"><b>new</b></font> XMPPConnection(config);
conn2.connect();
</pre></div>
@ -65,7 +65,7 @@ conn2.connect();
<a href="connections.html">Connection Management</a> for full details.</p>
<p>Once you've created a connection, you should login using a username and password
with the <tt>XMPPConnection.login(String username, String password)</tt> method.
with the <tt>Connection.login(String username, String password)</tt> method.
Once you've logged in, you can being chatting with other users by creating
new <tt>Chat</tt> or <tt>GroupChat</tt> objects.
@ -76,7 +76,7 @@ The roster lets you keep track of the availability (presence) of other users. Us
can be organized into groups such as "Friends" and "Co-workers", and then you
discover whether each user is online or offline.<p>
Retrieve the roster using the <tt>XMPPConnection.getRoster()</tt> method. The roster
Retrieve the roster using the <tt>Connection.getRoster()</tt> method. The roster
class allows you to find all the roster entries, the groups they belong to, and the
current presence status of each entry.
@ -98,7 +98,7 @@ and "out fishing":<p>
<font color="gray"><i>// Create a new presence. Pass in false to indicate we're unavailable.</i></font>
Presence presence = new Presence(Presence.Type.unavailable);
presence.setStatus(<font color="green">"Gone fishing"</font>);
<font color="gray"><i>// Send the packet (assume we have a XMPPConnection instance called "con").</i></font>
<font color="gray"><i>// Send the packet (assume we have a Connection instance called "con").</i></font>
con.sendPacket(presence);
</pre></div>
<p>
@ -111,7 +111,7 @@ polling and blocking operations on. So, a packet listener is useful when
you want to take some action whenever a packet happens to come in, while a
packet collector is useful when you want to wait for a specific packet
to arrive. Packet collectors and listeners can be created using an
XMPPConnection instance.
Connection instance.
<p><div class="footer">

View File

@ -29,7 +29,7 @@ A chat creates a new thread of messages (using a thread ID) between two users. T
following code snippet demonstrates how to create a new Chat with a user and then send
them a text message:<p>
<div class="code"><pre><font color="gray"><i>// Assume we've created an XMPPConnection name "connection".</i></font>
<div class="code"><pre><font color="gray"><i>// Assume we've created a Connection name "connection".</i></font>
ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat(<font
color="green">"jsmith@jivesoftware.com"</font>, new MessageListener() {

View File

@ -28,7 +28,7 @@ Smack Key Advantages
can be accomplished in only a few lines of code:
<div class="code"><pre>
XMPPConnection connection = <font color="navy"><b>new</b></font> XMPPConnection(<font color="green">"jabber.org"</font>);
Connection connection = <font color="navy"><b>new</b></font> XMPPConnection(<font color="green">"jabber.org"</font>);
connection.connect();
connection.login(<font color="green">"mtucker"</font>, <font color="green">"password"</font>);
Chat chat = connection.getChatManager().createChat(<font color="green">"jsmith@jivesoftware.com"</font>, new MessageListener() {

View File

@ -27,7 +27,7 @@ A packet listener is used for event style programming, while a packet collector
result queue of packets that you can do polling and blocking operations on. So, a packet
listener is useful when you want to take some action whenever a packet happens to come in,
while a packet collector is useful when you want to wait for a specific packet to
arrive. Packet collectors and listeners can be created using an <tt>XMPPConnection</tt> instance.<p>
arrive. Packet collectors and listeners can be created using an <tt>Connection</tt> instance.<p>
The <tt>org.jivesoftware.smack.filter.PacketFilter</tt> interface determines which
specific packets will be delivered to a <tt>PacketCollector</tt> or <tt>PacketListener</tt>.
@ -42,7 +42,7 @@ listener:<p>
<font color="gray"><i>// user. We use an AndFilter to combine two other filters.</i></font>
PacketFilter filter = new AndFilter(new PacketTypeFilter(<b>Message.class</b>),
new FromContainsFilter(<font color="green">"mary@jivesoftware.com"</font>));
<font color="gray"><i>// Assume we've created an XMPPConnection name "connection".</i></font>
<font color="gray"><i>// Assume we've created a Connection name "connection".</i></font>
<font color="gray"><i>// First, register a packet collector using the filter we created.</i></font>
PacketCollector myCollector = connection.createPacketCollector(filter);

View File

@ -21,7 +21,7 @@ A roster also allows you to organize users into groups such as "Friends" and
"Co-workers". Other IM systems refer to the roster as the buddy list, contact list,
etc.<p>
A <tt>Roster</tt> instance is obtained using the <tt>XMPPConnection.getRoster()</tt>
A <tt>Roster</tt> instance is obtained using the <tt>Connection.getRoster()</tt>
method, but only after successfully logging into a server.
<p class="subheader">Roster Entries</p>

View File

@ -27,7 +27,7 @@ import java.util.List;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
@ -99,7 +99,7 @@ import org.jivesoftware.smackx.provider.JingleProvider;
* try {
* <p/>
* // Connect to a XMPP Server
* XMPPConnection x1 = new XMPPConnection("xmpp.com");
* Connection x1 = new XMPPConnection("xmpp.com");
* x1.connect();
* x1.login("juliet", "juliet");
* <p/>
@ -142,7 +142,7 @@ import org.jivesoftware.smackx.provider.JingleProvider;
* try {
* <p/>
* // Connect to a XMPP Server
* XMPPConnection x0 = new XMPPConnection("xmpp.com");
* Connection x0 = new XMPPConnection("xmpp.com");
* x0.connect();
* x0.login("romeo", "romeo");
* <p/>
@ -197,19 +197,19 @@ public class JingleManager implements JingleSessionListener {
private List<CreatedJingleSessionListener> creationListeners = new ArrayList<CreatedJingleSessionListener>();
// The XMPP connection
private XMPPConnection connection;
private Connection connection;
// The Media Managers
private List<JingleMediaManager> jingleMediaManagers;
/**
* Default constructor with a defined XMPPConnection, Transport Resolver and a Media Manager
* Default constructor with a defined Connection, Transport Resolver and a Media Manager
* If a fully implemented JingleMediaSession is entered, JingleManager manage Jingle signalling and jmf
*
* @param connection XMPP Connection to be used
* @param jingleMediaManager an implemeted JingleMediaManager to be used.
*/
public JingleManager(XMPPConnection connection, List<JingleMediaManager> jingleMediaManagers) {
public JingleManager(Connection connection, List<JingleMediaManager> jingleMediaManagers) {
this.connection = connection;
this.jingleMediaManagers = jingleMediaManagers;
@ -249,7 +249,7 @@ public class JingleManager implements JingleSessionListener {
/**
* Setup the jingle system to let the remote clients know we support Jingle.
* (This used to be a static part of construction. The problem is a remote client might
* attempt a Jingle connection to us after we've created an XMPPConnection, but before we've
* attempt a Jingle connection to us after we've created a Connection, but before we've
* setup an instance of a JingleManager. We will appear to not support Jingle. With the new
* method you just call it once and all new connections will report Jingle support.)
*/
@ -260,8 +260,8 @@ public class JingleManager implements JingleSessionListener {
// Enable the Jingle support on every established connection
// The ServiceDiscoveryManager class should have been already
// initialized
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
JingleManager.setServiceEnabled(connection, true);
}
});
@ -279,7 +279,7 @@ public class JingleManager implements JingleSessionListener {
* disabled
* @param enabled indicates if the service will be enabled or disabled
*/
public synchronized static void setServiceEnabled(XMPPConnection connection, boolean enabled) {
public synchronized static void setServiceEnabled(Connection connection, boolean enabled) {
if (isServiceEnabled(connection) == enabled) {
return;
}
@ -298,7 +298,7 @@ public class JingleManager implements JingleSessionListener {
* @return a boolean indicating if the Jingle support is enabled for the
* given connection
*/
public static boolean isServiceEnabled(XMPPConnection connection) {
public static boolean isServiceEnabled(Connection connection) {
return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(Jingle.NAMESPACE);
}
@ -311,7 +311,7 @@ public class JingleManager implements JingleSessionListener {
* @return a boolean indicating whether the specified user handles Jingle
* messages
*/
public static boolean isServiceEnabled(XMPPConnection connection, String userID) {
public static boolean isServiceEnabled(Connection connection, String userID) {
try {
DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(userID);
return result.containsFeature(Jingle.NAMESPACE);

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.jingle;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.listeners.JingleListener;
@ -45,7 +45,7 @@ public abstract class JingleNegotiator {
private static final SmackLogger LOGGER = SmackLogger.getLogger(JingleNegotiator.class);
//private XMPPConnection connection; // The connection associated
//private Connection connection; // The connection associated
protected JingleSession session;
@ -65,7 +65,7 @@ public abstract class JingleNegotiator {
}
/**
* Default constructor with a XMPPConnection
* Default constructor with a Connection
*
* @param connection the connection associated
*/
@ -101,7 +101,7 @@ public abstract class JingleNegotiator {
this.state = stateIs;
}
public XMPPConnection getConnection() {
public Connection getConnection() {
if (session != null) {
return session.getConnection();
} else {

View File

@ -60,7 +60,7 @@ import java.util.Random;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
@ -124,7 +124,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
private JingleSessionRequest sessionRequest;
private XMPPConnection connection;
private Connection connection;
private String sessionInitPacketID;
@ -134,7 +134,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* Full featured JingleSession constructor
*
* @param conn
* XMPPConnection
* the Connection which is used
* @param initiator
* the initiator JID
* @param responder
@ -144,7 +144,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param jingleMediaManager
* the jingleMediaManager
*/
public JingleSession(XMPPConnection conn, String initiator, String responder, String sessionid,
public JingleSession(Connection conn, String initiator, String responder, String sessionid,
List<JingleMediaManager> jingleMediaManagers) {
super();
@ -170,7 +170,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* JingleSession constructor (for an outgoing Jingle session)
*
* @param conn
* XMPPConnection
* Connection
* @param initiator
* the initiator JID
* @param responder
@ -178,7 +178,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param jingleMediaManager
* the jingleMediaManager
*/
public JingleSession(XMPPConnection conn, JingleSessionRequest request, String initiator, String responder,
public JingleSession(Connection conn, JingleSessionRequest request, String initiator, String responder,
List<JingleMediaManager> jingleMediaManagers) {
this(conn, initiator, responder, generateSessionId(), jingleMediaManagers);
sessionRequest = request;
@ -193,7 +193,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
return initiator;
}
public XMPPConnection getConnection() {
public Connection getConnection() {
return connection;
}
@ -640,7 +640,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param connection
* The connection to clean up
*/
private void unregisterInstanceFor(XMPPConnection connection) {
private void unregisterInstanceFor(Connection connection) {
synchronized (sessions) {
sessions.remove(connection);
}
@ -662,7 +662,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* A XMPP connection
* @return a Jingle session
*/
public static JingleSession getInstanceFor(XMPPConnection con) {
public static JingleSession getInstanceFor(Connection con) {
if (con == null) {
throw new IllegalArgumentException("Connection cannot be null");
}
@ -683,7 +683,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param connection
* The connection to set up
*/
private void installConnectionListeners(final XMPPConnection connection) {
private void installConnectionListeners(final Connection connection) {
if (connection != null) {
connectionListener = new ConnectionListener() {
public void connectionClosed() {

View File

@ -19,6 +19,7 @@
*/
package org.jivesoftware.smackx.jingle.mediaimpl.demo;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleManager;
@ -43,7 +44,7 @@ import java.util.List;
public class Demo extends JFrame {
private JingleTransportManager transportManager = null;
private XMPPConnection xmppConnection = null;
private Connection xmppConnection = null;
private String server = null;
private String user = null;

View File

@ -19,7 +19,7 @@
*/
package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
@ -40,7 +40,7 @@ import java.util.Random;
*/
public class BridgedResolver extends TransportResolver {
XMPPConnection connection;
Connection connection;
Random random = new Random();
@ -48,9 +48,9 @@ public class BridgedResolver extends TransportResolver {
/**
* Constructor.
* A Bridged Resolver need a XMPPConnection to connect to a RTP Bridge.
* A Bridged Resolver need a Connection to connect to a RTP Bridge.
*/
public BridgedResolver(XMPPConnection connection) {
public BridgedResolver(Connection connection) {
super();
this.connection = connection;
}

View File

@ -19,7 +19,7 @@
*/
package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.listeners.CreatedJingleSessionListener;
@ -35,9 +35,9 @@ import org.jivesoftware.smackx.jingle.media.PayloadType;
*/
public class BridgedTransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener {
XMPPConnection xmppConnection;
Connection xmppConnection;
public BridgedTransportManager(XMPPConnection xmppConnection) {
public BridgedTransportManager(Connection xmppConnection) {
super();
this.xmppConnection = xmppConnection;
}

View File

@ -29,7 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
@ -49,7 +49,7 @@ public class ICEResolver extends TransportResolver {
private static final SmackLogger LOGGER = SmackLogger.getLogger(ICEResolver.class);
XMPPConnection connection;
Connection connection;
Random random = new Random();
long sid;
String server;
@ -57,7 +57,7 @@ public class ICEResolver extends TransportResolver {
static Map<String, ICENegociator> negociatorsMap = new HashMap<String, ICENegociator>();
//ICENegociator iceNegociator = null;
public ICEResolver(XMPPConnection connection, String server, int port) {
public ICEResolver(Connection connection, String server, int port) {
super();
this.connection = connection;
this.server = server;

View File

@ -1,6 +1,6 @@
package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.listeners.CreatedJingleSessionListener;
@ -30,7 +30,7 @@ public class ICETransportManager extends JingleTransportManager implements Jingl
ICEResolver iceResolver = null;
public ICETransportManager(XMPPConnection xmppConnection, String server, int port) {
public ICETransportManager(Connection xmppConnection, String server, int port) {
iceResolver = new ICEResolver(xmppConnection, server, port);
try {
iceResolver.initializeAndWait();

View File

@ -28,7 +28,7 @@ import java.util.Iterator;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -46,7 +46,7 @@ import org.xmlpull.v1.XmlPullParser;
* <p/>
* High Level Usage Example:
* <p/>
* RTPBridge rtpBridge = RTPBridge.getRTPBridge(xmppConnection, sessionID);
* RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, sessionID);
*
* @author Thiago Camargo
*/
@ -388,23 +388,23 @@ public class RTPBridge extends IQ {
* Get a new RTPBridge Candidate from the server.
* If a error occurs or the server don't support RTPBridge Service, null is returned.
*
* @param xmppConnection
* @param connection
* @param sessionID
* @return
*/
public static RTPBridge getRTPBridge(XMPPConnection xmppConnection, String sessionID) {
public static RTPBridge getRTPBridge(Connection connection, String sessionID) {
if (!xmppConnection.isConnected()) {
if (!connection.isConnected()) {
return null;
}
RTPBridge rtpPacket = new RTPBridge(sessionID);
rtpPacket.setTo(RTPBridge.NAME + "." + xmppConnection.getServiceName());
rtpPacket.setTo(RTPBridge.NAME + "." + connection.getServiceName());
PacketCollector collector = xmppConnection
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));
xmppConnection.sendPacket(rtpPacket);
connection.sendPacket(rtpPacket);
RTPBridge response = (RTPBridge) collector
.nextResult(SmackConfiguration.getPacketReplyTimeout());
@ -418,21 +418,21 @@ public class RTPBridge extends IQ {
/**
* Check if the server support RTPBridge Service.
*
* @param xmppConnection
* @param connection
* @return
*/
public static boolean serviceAvailable(XMPPConnection xmppConnection) {
public static boolean serviceAvailable(Connection connection) {
if (!xmppConnection.isConnected()) {
if (!connection.isConnected()) {
return false;
}
LOGGER.debug("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager
.getInstanceFor(xmppConnection);
.getInstanceFor(connection);
try {
// DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName());
// DiscoverItems items = disco.discoverItems(connection.getServiceName());
// Iterator iter = items.getItems();
// while (iter.hasNext()) {
// DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
@ -441,7 +441,7 @@ public class RTPBridge extends IQ {
// }
// }
DiscoverInfo discoInfo = disco.discoverInfo(xmppConnection.getServiceName());
DiscoverInfo discoInfo = disco.discoverInfo(connection.getServiceName());
Iterator iter = discoInfo.getIdentities();
while (iter.hasNext()) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) iter.next();
@ -460,17 +460,17 @@ public class RTPBridge extends IQ {
/**
* Check if the server support RTPBridge Service.
*
* @param xmppConnection
* @param connection
* @return
*/
public static RTPBridge relaySession(XMPPConnection xmppConnection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) {
public static RTPBridge relaySession(Connection connection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) {
if (!xmppConnection.isConnected()) {
if (!connection.isConnected()) {
return null;
}
RTPBridge rtpPacket = new RTPBridge(sessionID, RTPBridge.BridgeAction.change);
rtpPacket.setTo(RTPBridge.NAME + "." + xmppConnection.getServiceName());
rtpPacket.setTo(RTPBridge.NAME + "." + connection.getServiceName());
rtpPacket.setType(Type.SET);
rtpPacket.setPass(pass);
@ -481,10 +481,10 @@ public class RTPBridge extends IQ {
// LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
PacketCollector collector = xmppConnection
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(rtpPacket.getPacketID()));
xmppConnection.sendPacket(rtpPacket);
connection.sendPacket(rtpPacket);
RTPBridge response = (RTPBridge) collector
.nextResult(SmackConfiguration.getPacketReplyTimeout());
@ -501,7 +501,7 @@ public class RTPBridge extends IQ {
* @param xmppConnection
* @return public IP String or null if not found
*/
public static String getPublicIP(XMPPConnection xmppConnection) {
public static String getPublicIP(Connection xmppConnection) {
if (!xmppConnection.isConnected()) {
return null;

View File

@ -25,7 +25,7 @@ import java.util.List;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -42,7 +42,7 @@ import org.xmlpull.v1.XmlPullParser;
* <p/>
* High Level Usage Example:
* <p/>
* STUN stun = STUN.getSTUNServer(xmppConnection);
* STUN stun = STUN.getSTUNServer(connection);
*
* @author Thiago Camargo
*/
@ -185,22 +185,22 @@ public class STUN extends IQ {
* Get a new STUN Server Address and port from the server.
* If a error occurs or the server don't support STUN Service, null is returned.
*
* @param xmppConnection
* @param connection
* @return
*/
public static STUN getSTUNServer(XMPPConnection xmppConnection) {
public static STUN getSTUNServer(Connection connection) {
if (!xmppConnection.isConnected()) {
if (!connection.isConnected()) {
return null;
}
STUN stunPacket = new STUN();
stunPacket.setTo(DOMAIN + "." + xmppConnection.getServiceName());
stunPacket.setTo(DOMAIN + "." + connection.getServiceName());
PacketCollector collector = xmppConnection
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(stunPacket.getPacketID()));
xmppConnection.sendPacket(stunPacket);
connection.sendPacket(stunPacket);
STUN response = (STUN) collector
.nextResult(SmackConfiguration.getPacketReplyTimeout());
@ -217,18 +217,18 @@ public class STUN extends IQ {
* @param xmppConnection
* @return
*/
public static boolean serviceAvailable(XMPPConnection xmppConnection) {
public static boolean serviceAvailable(Connection connection) {
if (!xmppConnection.isConnected()) {
if (!connection.isConnected()) {
return false;
}
LOGGER.debug("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager
.getInstanceFor(xmppConnection);
.getInstanceFor(connection);
try {
DiscoverItems items = disco.discoverItems(xmppConnection.getServiceName());
DiscoverItems items = disco.discoverItems(connection.getServiceName());
Iterator iter = items.getItems();
while (iter.hasNext()) {

View File

@ -63,7 +63,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;
@ -94,7 +94,7 @@ public abstract class TransportCandidate {
private String sessionId;
private XMPPConnection connection;
private Connection connection;
private TransportCandidate symmetric;
@ -190,20 +190,20 @@ public abstract class TransportCandidate {
}
/**
* Get the XMPPConnection use to send or receive this candidate
* Get the Connection use to send or receive this candidate
*
* @return
*/
public XMPPConnection getConnection() {
public Connection getConnection() {
return connection;
}
/**
* Set the XMPPConnection use to send or receive this candidate
* Set the Connection use to send or receive this candidate
*
* @param connection
*/
public void setConnection(XMPPConnection connection) {
public void setConnection(Connection connection) {
this.connection = connection;
}

View File

@ -36,12 +36,12 @@ import java.util.Map;
/**
* Allows creation and management of accounts on an XMPP server.
*
* @see XMPPConnection#getAccountManager()
* @see Connection#getAccountManager()
* @author Matt Tucker
*/
public class AccountManager {
private XMPPConnection connection;
private Connection connection;
private Registration info = null;
/**
@ -57,7 +57,7 @@ public class AccountManager {
*
* @param connection a connection to a XMPP server.
*/
public AccountManager(XMPPConnection connection) {
public AccountManager(Connection connection) {
this.connection = connection;
}

View File

@ -154,7 +154,7 @@ public class Chat {
/**
* Delivers a message directly to this chat, which will add the message
* to the collector and deliver it to all listeners registered with the
* Chat. This is used by the XMPPConnection class to deliver messages
* Chat. This is used by the Connection class to deliver messages
* without a thread ID.
*
* @param message the message.

View File

@ -80,9 +80,9 @@ public class ChatManager {
private Map<PacketInterceptor, PacketFilter> interceptors
= new WeakHashMap<PacketInterceptor, PacketFilter>();
private XMPPConnection connection;
private Connection connection;
ChatManager(XMPPConnection connection) {
ChatManager(Connection connection) {
this.connection = connection;
PacketFilter filter = new PacketFilter() {

View File

@ -0,0 +1,856 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2009 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
/**
* The abstract Connection class provides an interface for connections to a
* XMPP server and implements shared methods which are used by the
* different types of connections (e.g. XMPPConnection or BoshConnection).
*
* To create a connection to a XMPP server a simple usage of this API might
* look like the following:
* <pre>
* // Create a connection to the igniterealtime.org XMPP server.
* Connection con = new XMPPConnection("igniterealtime.org");
* // Connect to the server
* con.connect();
* // Most servers require you to login before performing other tasks.
* con.login("jsmith", "mypass");
* // Start a new conversation with John Doe and send him a message.
* Chat chat = connection.getChatManager().createChat("jdoe@igniterealtime.org"</font>, new MessageListener() {
* <p/>
* public void processMessage(Chat chat, Message message) {
* // Print out any messages we get back to standard out.
* System.out.println(<font color="green">"Received message: "</font> + message);
* }
* });
* chat.sendMessage(<font color="green">"Howdy!"</font>);
* // Disconnect from the server
* con.disconnect();
* </pre>
* <p/>
* Connections can be reused between connections. This means that an Connection
* may be connected, disconnected and then connected again. Listeners of the Connection
* will be retained accross connections.<p>
* <p/>
* If a connected Connection gets disconnected abruptly then it will try to reconnect
* again. To stop the reconnection process, use {@link #disconnect()}. Once stopped
* you can use {@link #connect()} to manually connect to the server.
*
* @see XMPPConnection
* @author Matt Tucker
* @author Guenther Niess
*/
public abstract class Connection {
/**
* Counter to uniquely identify connections that are created.
*/
private final static AtomicInteger connectionCounter = new AtomicInteger(0);
/**
* A set of listeners which will be invoked if a new connection is created.
*/
private final static Set<ConnectionCreationListener> connectionEstablishedListeners =
new CopyOnWriteArraySet<ConnectionCreationListener>();
/**
* Value that indicates whether debugging is enabled. When enabled, a debug
* window will apear for each new connection that will contain the following
* information:<ul>
* <li> Client Traffic -- raw XML traffic generated by Smack and sent to the server.
* <li> Server Traffic -- raw XML traffic sent by the server to the client.
* <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
* </ul>
* <p/>
* Debugging can be enabled by setting this field to true, or by setting the Java system
* property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
* command line such as "java SomeApp -Dsmack.debugEnabled=true".
*/
public static boolean DEBUG_ENABLED = false;
static {
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
}
catch (Exception e) {
// Ignore.
}
// Ensure the SmackConfiguration class is loaded by calling a method in it.
SmackConfiguration.getVersion();
}
/**
* A collection of ConnectionListeners which listen for connection closing
* and reconnection events.
*/
protected final Collection<ConnectionListener> connectionListeners =
new CopyOnWriteArrayList<ConnectionListener>();
/**
* A collection of PacketCollectors which collects packets for a specified filter
* and perform blocking and polling operations on the result queue.
*/
protected final Collection<PacketCollector> collectors = new ConcurrentLinkedQueue<PacketCollector>();
/**
* List of PacketListeners that will be notified when a new packet was received.
*/
protected final Map<PacketListener, ListenerWrapper> recvListeners =
new ConcurrentHashMap<PacketListener, ListenerWrapper>();
/**
* List of PacketListeners that will be notified when a new packet was sent.
*/
protected final Map<PacketListener, ListenerWrapper> sendListeners =
new ConcurrentHashMap<PacketListener, ListenerWrapper>();
/**
* List of PacketInterceptors that will be notified when a new packet is about to be
* sent to the server. These interceptors may modify the packet before it is being
* actually sent to the server.
*/
protected final Map<PacketInterceptor, InterceptorWrapper> interceptors =
new ConcurrentHashMap<PacketInterceptor, InterceptorWrapper>();
/**
* The AccountManager allows creation and management of accounts on an XMPP server.
*/
private AccountManager accountManager = null;
/**
* The ChatManager keeps track of references to all current chats.
*/
private ChatManager chatManager = null;
/**
* The SmackDebugger allows to log and debug XML traffic.
*/
protected SmackDebugger debugger = null;
/**
* The Reader which is used for the {@see debugger}.
*/
protected Reader reader;
/**
* The Writer which is used for the {@see debugger}.
*/
protected Writer writer;
/**
* The SASLAuthentication manager that is responsible for authenticating with the server.
*/
protected SASLAuthentication saslAuthentication = new SASLAuthentication(this);
/**
* A number to uniquely identify connections that are created. This is distinct from the
* connection ID, which is a value sent by the server once a connection is made.
*/
protected final int connectionCounterValue = connectionCounter.getAndIncrement();
/**
* Holds the initial configuration used while creating the connection.
*/
protected final ConnectionConfiguration config;
/**
* Create a new Connection to a XMPP server.
*
* @param configuration The configuration which is used to establish the connection.
*/
protected Connection(ConnectionConfiguration configuration) {
config = configuration;
}
/**
* Returns the configuration used to connect to the server.
*
* @return the configuration used to connect to the server.
*/
protected ConnectionConfiguration getConfiguration() {
return config;
}
/**
* Returns the name of the service provided by the XMPP server for this connection.
* This is also called XMPP domain of the connected server. After
* authenticating with the server the returned value may be different.
*
* @return the name of the service provided by the XMPP server.
*/
public String getServiceName() {
return config.getServiceName();
}
/**
* Returns the host name of the server where the XMPP server is running. This would be the
* IP address of the server or a name that may be resolved by a DNS server.
*
* @return the host name of the server where the XMPP server is running.
*/
public String getHost() {
return config.getHost();
}
/**
* Returns the port number of the XMPP server for this connection. The default port
* for normal connections is 5222. The default port for SSL connections is 5223.
*
* @return the port number of the XMPP server.
*/
public int getPort() {
return config.getPort();
}
/**
* Returns the full XMPP address of the user that is logged in to the connection or
* <tt>null</tt> if not logged in yet. An XMPP address is in the form
* username@server/resource.
*
* @return the full XMPP address of the user logged in.
*/
public abstract String getUser();
/**
* Returns the connection ID for this connection, which is the value set by the server
* when opening a XMPP stream. If the server does not set a connection ID, this value
* will be null. This value will be <tt>null</tt> if not connected to the server.
*
* @return the ID of this connection returned from the XMPP server or <tt>null</tt> if
* not connected to the server.
*/
public abstract String getConnectionID();
/**
* Returns true if currently connected to the XMPP server.
*
* @return true if connected.
*/
public abstract boolean isConnected();
/**
* Returns true if currently authenticated by successfully calling the login method.
*
* @return true if authenticated.
*/
public abstract boolean isAuthenticated();
/**
* Returns true if currently authenticated anonymously.
*
* @return true if authenticated anonymously.
*/
public abstract boolean isAnonymous();
/**
* Returns true if the connection to the server has successfully negotiated encryption.
*
* @return true if a secure connection to the server.
*/
public abstract boolean isSecureConnection();
/**
* Returns if the reconnection mechanism is allowed to be used. By default
* reconnection is allowed.
*
* @return true if the reconnection mechanism is allowed to be used.
*/
protected boolean isReconnectionAllowed() {
return config.isReconnectionAllowed();
}
/**
* Returns true if network traffic is being compressed. When using stream compression network
* traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow
* speed network connection. However, the server will need to use more CPU time in order to
* un/compress network data so under high load the server performance might be affected.
*
* @return true if network traffic is being compressed.
*/
public abstract boolean isUsingCompression();
/**
* Establishes a connection to the XMPP server and performs an automatic login
* only if the previous connection state was logged (authenticated). It basically
* creates and maintains a connection to the server.<p>
* <p/>
* Listeners will be preserved from a previous connection if the reconnection
* occurs after an abrupt termination.
*
* @throws XMPPException if an error occurs while trying to establish the connection.
*/
public abstract void connect() throws XMPPException;
/**
* Logs in to the server using the strongest authentication mode supported by
* the server, then sets presence to available. If more than five seconds
* (default timeout) elapses in each step of the authentication process without
* a response from the server, or if an error occurs, a XMPPException will be thrown.<p>
*
* It is possible to log in without sending an initial available presence by using
* {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is
* not interested in loading its roster upon login then use
* {@link ConnectionConfiguration#setRosterLoadedAtLogin(boolean)}.
* Finally, if you want to not pass a password and instead use a more advanced mechanism
* while using SASL then you may be interested in using
* {@link ConnectionConfiguration#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}.
* For more advanced login settings see {@link ConnectionConfiguration}.
*
* @param username the username.
* @param password the password or <tt>null</tt> if using a CallbackHandler.
* @throws XMPPException if an error occurs.
*/
public void login(String username, String password) throws XMPPException {
login(username, password, "Smack");
}
/**
* Logs in to the server using the strongest authentication mode supported by
* the server. If the server supports SASL authentication then the user will be
* authenticated using SASL if not Non-SASL authentication will be tried. If more than
* five seconds (default timeout) elapses in each step of the authentication process
* without a response from the server, or if an error occurs, a XMPPException will be
* thrown.<p>
*
* Before logging in (i.e. authenticate) to the server the connection must be connected.
* For compatibility and easiness of use the connection will automatically connect to the
* server if not already connected.<p>
*
* It is possible to log in without sending an initial available presence by using
* {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is
* not interested in loading its roster upon login then use
* {@link ConnectionConfiguration#setRosterLoadedAtLogin(boolean)}.
* Finally, if you want to not pass a password and instead use a more advanced mechanism
* while using SASL then you may be interested in using
* {@link ConnectionConfiguration#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}.
* For more advanced login settings see {@link ConnectionConfiguration}.
*
* @param username the username.
* @param password the password or <tt>null</tt> if using a CallbackHandler.
* @param resource the resource.
* @throws XMPPException if an error occurs.
* @throws IllegalStateException if not connected to the server, or already logged in
* to the serrver.
*/
public abstract void login(String username, String password, String resource) throws XMPPException;
/**
* Logs in to the server anonymously. Very few servers are configured to support anonymous
* authentication, so it's fairly likely logging in anonymously will fail. If anonymous login
* does succeed, your XMPP address will likely be in the form "123ABC@server/789XYZ" or
* "server/123ABC" (where "123ABC" and "789XYZ" is a random value generated by the server).
*
* @throws XMPPException if an error occurs or anonymous logins are not supported by the server.
* @throws IllegalStateException if not connected to the server, or already logged in
* to the serrver.
*/
public abstract void loginAnonymously() throws XMPPException;
/**
* Sends the specified packet to the server.
*
* @param packet the packet to send.
*/
public abstract void sendPacket(Packet packet);
/**
* Returns an account manager instance for this connection.
*
* @return an account manager for this connection.
*/
public AccountManager getAccountManager() {
if (accountManager == null) {
accountManager = new AccountManager(this);
}
return accountManager;
}
/**
* Returns a chat manager instance for this connection. The ChatManager manages all incoming and
* outgoing chats on the current connection.
*
* @return a chat manager instance for this connection.
*/
public synchronized ChatManager getChatManager() {
if (this.chatManager == null) {
this.chatManager = new ChatManager(this);
}
return this.chatManager;
}
/**
* Returns the roster for the user logged into the server. If the user has not yet
* logged into the server (or if the user is logged in anonymously), this method will return
* <tt>null</tt>.
*
* @return the user's roster, or <tt>null</tt> if the user has not logged in yet.
*/
public abstract Roster getRoster();
/**
* Returns the SASLAuthentication manager that is responsible for authenticating with
* the server.
*
* @return the SASLAuthentication manager that is responsible for authenticating with
* the server.
*/
public SASLAuthentication getSASLAuthentication() {
return saslAuthentication;
}
/**
* Closes the connection by setting presence to unavailable then closing the connection to
* the XMPP server. The Connection can still be used for connecting to the server
* again.<p>
* <p/>
* This method cleans up all resources used by the connection. Therefore, the roster,
* listeners and other stateful objects cannot be re-used by simply calling connect()
* on this connection again. This is unlike the behavior during unexpected disconnects
* (and subsequent connections). In that case, all state is preserved to allow for
* more seamless error recovery.
*/
public void disconnect() {
disconnect(new Presence(Presence.Type.unavailable));
}
/**
* Closes the connection. A custom unavailable presence is sent to the server, followed
* by closing the stream. The Connection can still be used for connecting to the server
* again. A custom unavilable presence is useful for communicating offline presence
* information such as "On vacation". Typically, just the status text of the presence
* packet is set with online information, but most XMPP servers will deliver the full
* presence packet with whatever data is set.<p>
* <p/>
* This method cleans up all resources used by the connection. Therefore, the roster,
* listeners and other stateful objects cannot be re-used by simply calling connect()
* on this connection again. This is unlike the behavior during unexpected disconnects
* (and subsequent connections). In that case, all state is preserved to allow for
* more seamless error recovery.
*
* @param unavailablePresence the presence packet to send during shutdown.
*/
public abstract void disconnect(Presence unavailablePresence);
/**
* Adds a new listener that will be notified when new Connections are created. Note
* that newly created connections will not be actually connected to the server.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void addConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.add(connectionCreationListener);
}
/**
* Removes a listener that was interested in connection creation events.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void removeConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.remove(connectionCreationListener);
}
/**
* Get the collection of listeners that are interested in connection creation events.
*
* @return a collection of listeners interested on new connections.
*/
protected static Collection<ConnectionCreationListener> getConnectionCreationListeners() {
return Collections.unmodifiableCollection(connectionEstablishedListeners);
}
/**
* Adds a connection listener to this connection that will be notified when
* the connection closes or fails. The connection needs to already be connected
* or otherwise an IllegalStateException will be thrown.
*
* @param connectionListener a connection listener.
*/
public void addConnectionListener(ConnectionListener connectionListener) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
if (connectionListener == null) {
return;
}
if (!connectionListeners.contains(connectionListener)) {
connectionListeners.add(connectionListener);
}
}
/**
* Removes a connection listener from this connection.
*
* @param connectionListener a connection listener.
*/
public void removeConnectionListener(ConnectionListener connectionListener) {
connectionListeners.remove(connectionListener);
}
/**
* Get the collection of listeners that are interested in connection events.
*
* @return a collection of listeners interested on connection events.
*/
protected Collection<ConnectionListener> getConnectionListeners() {
return connectionListeners;
}
/**
* Creates a new packet collector for this connection. A packet filter determines
* which packets will be accumulated by the collector. A PacketCollector is
* more suitable to use than a {@link PacketListener} when you need to wait for
* a specific result.
*
* @param packetFilter the packet filter to use.
* @return a new packet collector.
*/
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
PacketCollector collector = new PacketCollector(this, packetFilter);
// Add the collector to the list of active collectors.
collectors.add(collector);
return collector;
}
/**
* Remove a packet collector of this connection.
*
* @param collector a packet collectors which was created for this connection.
*/
protected void removePacketCollector(PacketCollector collector) {
collectors.remove(collector);
}
/**
* Get the collection of all packet collectors for this connection.
*
* @return a collection of packet collectors for this connection.
*/
protected Collection<PacketCollector> getPacketCollectors() {
return collectors;
}
/**
* Registers a packet listener with this connection. A packet filter determines
* which packets will be delivered to the listener. If the same packet listener
* is added again with a different filter, only the new filter will be used.
*
* @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use.
*/
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
if (packetListener == null) {
throw new NullPointerException("Packet listener is null.");
}
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
recvListeners.put(packetListener, wrapper);
}
/**
* Removes a packet listener for received packets from this connection.
*
* @param packetListener the packet listener to remove.
*/
public void removePacketListener(PacketListener packetListener) {
recvListeners.remove(packetListener);
}
/**
* Get a map of all packet listeners for received packets of this connection.
*
* @return a map of all packet listeners for received packets.
*/
protected Map<PacketListener, ListenerWrapper> getPacketListeners() {
return recvListeners;
}
/**
* Registers a packet listener with this connection. The listener will be
* notified of every packet that this connection sends. A packet filter determines
* which packets will be delivered to the listener. Note that the thread
* that writes packets will be used to invoke the listeners. Therefore, each
* packet listener should complete all operations quickly or use a different
* thread for processing.
*
* @param packetListener the packet listener to notify of sent packets.
* @param packetFilter the packet filter to use.
*/
public void addPacketSendingListener(PacketListener packetListener, PacketFilter packetFilter) {
if (packetListener == null) {
throw new NullPointerException("Packet listener is null.");
}
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
sendListeners.put(packetListener, wrapper);
}
/**
* Removes a packet listener for sending packets from this connection.
*
* @param packetListener the packet listener to remove.
*/
public void removePacketSendingListener(PacketListener packetListener) {
sendListeners.remove(packetListener);
}
/**
* Get a map of all packet listeners for sending packets of this connection.
*
* @return a map of all packet listeners for sent packets.
*/
protected Map<PacketListener, ListenerWrapper> getPacketSendingListeners() {
return sendListeners;
}
/**
* Process all packet listeners for sending packets.
*
* @param packet the packet to process.
*/
protected void firePacketSendingListeners(Packet packet) {
// Notify the listeners of the new sent packet
for (ListenerWrapper listenerWrapper : sendListeners.values()) {
listenerWrapper.notifyListener(packet);
}
}
/**
* Registers a packet interceptor with this connection. The interceptor will be
* invoked every time a packet is about to be sent by this connection. Interceptors
* may modify the packet to be sent. A packet filter determines which packets
* will be delivered to the interceptor.
*
* @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use.
*/
public void addPacketInterceptor(PacketInterceptor packetInterceptor,
PacketFilter packetFilter) {
if (packetInterceptor == null) {
throw new NullPointerException("Packet interceptor is null.");
}
interceptors.put(packetInterceptor, new InterceptorWrapper(packetInterceptor, packetFilter));
}
/**
* Removes a packet interceptor.
*
* @param packetInterceptor the packet interceptor to remove.
*/
public void removePacketInterceptor(PacketInterceptor packetInterceptor) {
interceptors.remove(packetInterceptor);
}
/**
* Get a map of all packet interceptors for sending packets of this connection.
*
* @return a map of all packet interceptors for sending packets.
*/
protected Map<PacketInterceptor, InterceptorWrapper> getPacketInterceptors() {
return interceptors;
}
/**
* Process interceptors. Interceptors may modify the packet that is about to be sent.
* Since the thread that requested to send the packet will invoke all interceptors, it
* is important that interceptors perform their work as soon as possible so that the
* thread does not remain blocked for a long period.
*
* @param packet the packet that is going to be sent to the server
*/
protected void firePacketInterceptors(Packet packet) {
if (packet != null) {
for (InterceptorWrapper interceptorWrapper : interceptors.values()) {
interceptorWrapper.notifyListener(packet);
}
}
}
/**
* Initialize the {@link #debugger}. You can specify a customized {@link SmackDebugger}
* by setup the system property <code>smack.debuggerClass</code> to the implementation.
*
* @throws IllegalStateException if the reader or writer isn't yet initialized.
* @throws IllegalArgumentException if the SmackDebugger can't be loaded.
*/
protected void initDebugger() {
if (reader == null || writer == null) {
throw new NullPointerException("Reader or writer isn't initialized.");
}
// If debugging is enabled, we open a window and write out all network traffic.
if (config.isDebuggerEnabled()) {
if (debugger == null) {
// Detect the debugger class to use.
String className = null;
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
className = System.getProperty("smack.debuggerClass");
}
catch (Throwable t) {
// Ignore.
}
Class<?> debuggerClass = null;
if (className != null) {
try {
debuggerClass = Class.forName(className);
}
catch (Exception e) {
e.printStackTrace();
}
}
if (debuggerClass == null) {
try {
debuggerClass =
Class.forName("org.jivesoftware.smackx.debugger.EnhancedDebugger");
}
catch (Exception ex) {
try {
debuggerClass =
Class.forName("org.jivesoftware.smack.debugger.LiteDebugger");
}
catch (Exception ex2) {
ex2.printStackTrace();
}
}
}
// Create a new debugger instance. If an exception occurs then disable the debugging
// option
try {
Constructor<?> constructor = debuggerClass
.getConstructor(Connection.class, Writer.class, Reader.class);
debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
reader = debugger.getReader();
writer = debugger.getWriter();
}
catch (Exception e) {
throw new IllegalArgumentException("Can't initialize the configured debugger!", e);
}
}
else {
// Obtain new reader and writer from the existing debugger
reader = debugger.newConnectionReader(reader);
writer = debugger.newConnectionWriter(writer);
}
}
}
/**
* A wrapper class to associate a packet filter with a listener.
*/
protected static class ListenerWrapper {
private PacketListener packetListener;
private PacketFilter packetFilter;
/**
* Create a class which associates a packet filter with a listener.
*
* @param packetListener the packet listener.
* @param packetFilter the associated filter or null if it listen for all packets.
*/
public ListenerWrapper(PacketListener packetListener, PacketFilter packetFilter) {
this.packetListener = packetListener;
this.packetFilter = packetFilter;
}
/**
* Notify and process the packet listener if the filter matches the packet.
*
* @param packet the packet which was sent or received.
*/
public void notifyListener(Packet packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
packetListener.processPacket(packet);
}
}
}
/**
* A wrapper class to associate a packet filter with an interceptor.
*/
protected static class InterceptorWrapper {
private PacketInterceptor packetInterceptor;
private PacketFilter packetFilter;
/**
* Create a class which associates a packet filter with an interceptor.
*
* @param packetInterceptor the interceptor.
* @param packetFilter the associated filter or null if it intercepts all packets.
*/
public InterceptorWrapper(PacketInterceptor packetInterceptor, PacketFilter packetFilter) {
this.packetInterceptor = packetInterceptor;
this.packetFilter = packetFilter;
}
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (object instanceof InterceptorWrapper) {
return ((InterceptorWrapper) object).packetInterceptor
.equals(this.packetInterceptor);
}
else if (object instanceof PacketInterceptor) {
return object.equals(this.packetInterceptor);
}
return false;
}
/**
* Notify and process the packet interceptor if the filter matches the packet.
*
* @param packet the packet which will be sent.
*/
public void notifyListener(Packet packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
packetInterceptor.interceptPacket(packet);
}
}
}
}

View File

@ -38,6 +38,11 @@ import java.io.File;
*/
public class ConnectionConfiguration implements Cloneable {
/**
* Hostname of the XMPP server. Usually servers use the same service name as the name
* of the server. However, there are some servers like google where host would be
* talk.google.com and the serviceName would be gmail.com.
*/
private String serviceName;
private String host;
@ -63,7 +68,7 @@ public class ConnectionConfiguration implements Cloneable {
*/
private CallbackHandler callbackHandler;
private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED;
private boolean debuggerEnabled = Connection.DEBUG_ENABLED;
// Flag that indicates if a reconnection should be attempted when abruptly disconnected
private boolean reconnectionAllowed = true;
@ -80,7 +85,7 @@ public class ConnectionConfiguration implements Cloneable {
private SecurityMode securityMode = SecurityMode.enabled;
// Holds the proxy information (such as proxyhost, proxyport, username, password etc)
private ProxyInfo proxy;
protected ProxyInfo proxy;
/**
* Creates a new ConnectionConfiguration for the specified service name.
@ -175,7 +180,7 @@ public class ConnectionConfiguration implements Cloneable {
this.host = host;
this.port = port;
this.serviceName = serviceName;
this.proxy = proxy;
this.proxy = proxy;
// Build the default path to the cacert truststore file. By default we are
// going to use the file located in $JREHOME/lib/security/cacerts.
@ -197,6 +202,15 @@ public class ConnectionConfiguration implements Cloneable {
socketFactory = proxy.getSocketFactory();
}
/**
* Sets the server name, also known as XMPP domain of the target server.
*
* @param serviceName the XMPP domain of the target server.
*/
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
/**
* Returns the server name of the target server.
*
@ -522,7 +536,7 @@ public class ConnectionConfiguration implements Cloneable {
/**
* Returns true if the new connection about to be establish is going to be debugged. By
* default the value of {@link XMPPConnection#DEBUG_ENABLED} is used.
* default the value of {@link Connection#DEBUG_ENABLED} is used.
*
* @return true if the new connection about to be establish is going to be debugged.
*/
@ -532,7 +546,7 @@ public class ConnectionConfiguration implements Cloneable {
/**
* Sets if the new connection about to be establish is going to be debugged. By
* default the value of {@link XMPPConnection#DEBUG_ENABLED} is used.
* default the value of {@link Connection#DEBUG_ENABLED} is used.
*
* @param debuggerEnabled if the new connection about to be establish is going to be debugged.
*/

View File

@ -21,9 +21,9 @@
package org.jivesoftware.smack;
/**
* Implementors of this interface will be notified when a new {@link XMPPConnection}
* Implementors of this interface will be notified when a new {@link Connection}
* has been created. The newly created connection will not be actually connected to
* the server. Use {@link XMPPConnection#addConnectionCreationListener(ConnectionCreationListener)}
* the server. Use {@link Connection#addConnectionCreationListener(ConnectionCreationListener)}
* to add new listeners.
*
* @author Gaston Dombiak
@ -36,6 +36,6 @@ public interface ConnectionCreationListener {
*
* @param connection the newly created connection.
*/
public void connectionCreated(XMPPConnection connection);
public void connectionCreated(Connection connection);
}

View File

@ -22,10 +22,10 @@ package org.jivesoftware.smack;
/**
* Interface that allows for implementing classes to listen for connection closing
* and reconnection events. Listeners are registered with XMPPConnection objects.
* and reconnection events. Listeners are registered with Connection objects.
*
* @see XMPPConnection#addConnectionListener
* @see XMPPConnection#removeConnectionListener
* @see Connection#addConnectionListener
* @see Connection#removeConnectionListener
*
* @author Matt Tucker
*/

View File

@ -27,7 +27,6 @@ import org.jivesoftware.smack.packet.IQ;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.Callback;
import java.io.IOException;
/**
* Implementation of JEP-0078: Non-SASL Authentication. Follow the following
@ -38,9 +37,9 @@ import java.io.IOException;
*/
class NonSASLAuthentication implements UserAuthentication {
private XMPPConnection connection;
private Connection connection;
public NonSASLAuthentication(XMPPConnection connection) {
public NonSASLAuthentication(Connection connection) {
super();
this.connection = connection;
}
@ -138,7 +137,7 @@ class NonSASLAuthentication implements UserAuthentication {
return response.getTo();
}
else {
return connection.serviceName + "/" + ((Authentication) response).getResource();
return connection.getServiceName() + "/" + ((Authentication) response).getResource();
}
}
}

View File

@ -35,7 +35,7 @@ import java.util.LinkedList;
* Each packet collector will queue up to 2^16 packets for processing before
* older packets are automatically dropped.
*
* @see XMPPConnection#createPacketCollector(PacketFilter)
* @see Connection#createPacketCollector(PacketFilter)
* @author Matt Tucker
*/
public class PacketCollector {
@ -49,18 +49,18 @@ public class PacketCollector {
private PacketFilter packetFilter;
private LinkedList<Packet> resultQueue;
private PacketReader packetReader;
private Connection conection;
private boolean cancelled = false;
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*
* @param packetReader the packetReader the collector is tied to.
* @param conection the connection the collector is tied to.
* @param packetFilter determines which packets will be returned by this collector.
*/
protected PacketCollector(PacketReader packetReader, PacketFilter packetFilter) {
this.packetReader = packetReader;
protected PacketCollector(Connection conection, PacketFilter packetFilter) {
this.conection = conection;
this.packetFilter = packetFilter;
this.resultQueue = new LinkedList<Packet>();
}
@ -74,7 +74,7 @@ public class PacketCollector {
// If the packet collector has already been cancelled, do nothing.
if (!cancelled) {
cancelled = true;
packetReader.cancelPacketCollector(this);
conection.removePacketCollector(this);
}
}

View File

@ -23,14 +23,14 @@ import org.jivesoftware.smack.packet.Packet;
/**
* Provides a mechanism to intercept and modify packets that are going to be
* sent to the server. PacketInterceptors are added to the {@link XMPPConnection}
* sent to the server. PacketInterceptors are added to the {@link Connection}
* together with a {@link org.jivesoftware.smack.filter.PacketFilter} so that only
* certain packets are intercepted and processed by the interceptor.<p>
*
* This allows event-style programming -- every time a new packet is found,
* the {@link #interceptPacket(Packet)} method will be called.
*
* @see XMPPConnection#addPacketWriterInterceptor(PacketInterceptor, org.jivesoftware.smack.filter.PacketFilter)
* @see Connection#addPacketInterceptor(PacketInterceptor, org.jivesoftware.smack.filter.PacketFilter)
* @author Gaston Dombiak
*/
public interface PacketInterceptor {

View File

@ -29,7 +29,7 @@ import org.jivesoftware.smack.packet.Packet;
* opposite approach to the functionality provided by a {@link PacketCollector}
* which lets you block while waiting for results.
*
* @see XMPPConnection#addPacketListener(PacketListener, org.jivesoftware.smack.filter.PacketFilter)
* @see Connection#addPacketListener(PacketListener, org.jivesoftware.smack.filter.PacketFilter)
* @author Matt Tucker
*/
public interface PacketListener {

View File

@ -20,7 +20,7 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.Connection.ListenerWrapper;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager;
@ -30,15 +30,19 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
/**
* Listens for XML traffic from the XMPP server and parses it into packet objects.
* The packet reader also manages all packet listeners and collectors.<p>
* The packet reader also invokes all packet listeners and collectors.<p>
*
* @see PacketCollector
* @see PacketListener
* @see Connection#createPacketCollector
* @see Connection#addPacketListener
* @author Matt Tucker
*/
class PacketReader {
@ -49,11 +53,6 @@ class PacketReader {
private XMPPConnection connection;
private XmlPullParser parser;
private boolean done;
private Collection<PacketCollector> collectors = new ConcurrentLinkedQueue<PacketCollector>();
protected final Map<PacketListener, ListenerWrapper> listeners =
new ConcurrentHashMap<PacketListener, ListenerWrapper>();
protected final Collection<ConnectionListener> connectionListeners =
new CopyOnWriteArrayList<ConnectionListener>();
private String connectionID = null;
private Semaphore connectionSemaphore;
@ -94,45 +93,6 @@ class PacketReader {
resetParser();
}
/**
* Creates a new packet collector for this reader. A packet filter determines
* which packets will be accumulated by the collector.
*
* @param packetFilter the packet filter to use.
* @return a new packet collector.
*/
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
PacketCollector collector = new PacketCollector(this, packetFilter);
collectors.add(collector);
// Add the collector to the list of active collector.
return collector;
}
protected void cancelPacketCollector(PacketCollector packetCollector) {
collectors.remove(packetCollector);
}
/**
* Registers a packet listener with this reader. A packet filter determines
* which packets will be delivered to the listener.
*
* @param packetListener the packet listener to notify of new packets.
* @param packetFilter the packet filter to use.
*/
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
listeners.put(packetListener, wrapper);
}
/**
* Removes a packet listener.
*
* @param packetListener the packet listener to remove.
*/
public void removePacketListener(PacketListener packetListener) {
listeners.remove(packetListener);
}
/**
* Starts the packet reader thread and returns once a connection to the server
* has been established. A connection will be attempted for a maximum of five
@ -174,7 +134,7 @@ class PacketReader {
public void shutdown() {
// Notify connection listeners of the connection closing if done hasn't already been set.
if (!done) {
for (ConnectionListener listener : connectionListeners) {
for (ConnectionListener listener : connection.getConnectionListeners()) {
try {
listener.connectionClosed();
}
@ -195,9 +155,8 @@ class PacketReader {
* Cleans up all resources used by the packet reader.
*/
void cleanup() {
connectionListeners.clear();
listeners.clear();
collectors.clear();
connection.recvListeners.clear();
connection.collectors.clear();
}
/**
@ -213,12 +172,12 @@ class PacketReader {
// Print the stack trace to help catch the problem
e.printStackTrace();
// Notify connection listeners of the error.
for (ConnectionListener listener : connectionListeners) {
for (ConnectionListener listener : connection.getConnectionListeners()) {
try {
listener.connectionClosedOnError(e);
}
catch (Exception e2) {
// Cath and print any exception so we can recover
// Catch and print any exception so we can recover
// from a faulty listener
e2.printStackTrace();
}
@ -230,12 +189,12 @@ class PacketReader {
*/
protected void notifyReconnection() {
// Notify connection listeners of the reconnection.
for (ConnectionListener listener : connectionListeners) {
for (ConnectionListener listener : connection.getConnectionListeners()) {
try {
listener.reconnectionSuccessful();
}
catch (Exception e) {
// Cath and print any exception so we can recover
// Catch and print any exception so we can recover
// from a faulty listener
e.printStackTrace();
}
@ -297,7 +256,7 @@ class PacketReader {
}
else if (parser.getAttributeName(i).equals("from")) {
// Use the server name that the server says that it is.
connection.serviceName = parser.getAttributeValue(i);
connection.config.setServiceName(parser.getAttributeValue(i));
}
}
}
@ -403,7 +362,7 @@ class PacketReader {
}
// Loop through all collectors and notify the appropriate ones.
for (PacketCollector collector: collectors) {
for (PacketCollector collector: connection.getPacketCollectors()) {
collector.processPacket(packet);
}
@ -411,6 +370,7 @@ class PacketReader {
listenerExecutor.submit(new ListenerNotification(packet));
}
private StreamError parseStreamError(XmlPullParser parser) throws IOException,
XmlPullParserException {
StreamError streamError = null;
@ -795,29 +755,9 @@ class PacketReader {
}
public void run() {
for (ListenerWrapper listenerWrapper : listeners.values()) {
for (ListenerWrapper listenerWrapper : connection.recvListeners.values()) {
listenerWrapper.notifyListener(packet);
}
}
}
/**
* A wrapper class to associate a packet filter with a listener.
*/
private static class ListenerWrapper {
private PacketListener packetListener;
private PacketFilter packetFilter;
public ListenerWrapper(PacketListener packetListener, PacketFilter packetFilter) {
this.packetListener = packetListener;
this.packetFilter = packetFilter;
}
public void notifyListener(Packet packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
packetListener.processPacket(packet);
}
}
}
}

View File

@ -20,13 +20,10 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@ -35,6 +32,9 @@ import java.util.concurrent.BlockingQueue;
* interceptors can be registered to dynamically modify packets before they're actually
* sent. Packet listeners can be registered to listen for all outgoing packets.
*
* @see Connection#addPacketInterceptor
* @see Connection#addPacketSendingListener
*
* @author Matt Tucker
*/
class PacketWriter {
@ -45,9 +45,6 @@ class PacketWriter {
private XMPPConnection connection;
private final BlockingQueue<Packet> queue;
private boolean done;
private final Map<PacketListener, ListenerWrapper> listeners =
new ConcurrentHashMap<PacketListener, ListenerWrapper>();
/**
* Timestamp when the last stanza was sent to the server. This information is used
@ -55,14 +52,6 @@ class PacketWriter {
*/
private long lastActive = System.currentTimeMillis();
/**
* List of PacketInterceptors that will be notified when a new packet is about to be
* sent to the server. These interceptors may modify the packet before it is being
* actually sent to the server.
*/
private final Map<PacketInterceptor, InterceptorWrapper> interceptors =
new ConcurrentHashMap<PacketInterceptor, InterceptorWrapper>();
/**
* Creates a new packet writer with the specified connection.
*
@ -100,7 +89,7 @@ class PacketWriter {
if (!done) {
// Invoke interceptors for the new packet that is about to be sent. Interceptors
// may modify the content of the packet.
processInterceptors(packet);
connection.firePacketInterceptors(packet);
try {
queue.put(packet);
@ -115,65 +104,10 @@ class PacketWriter {
// Process packet writer listeners. Note that we're using the sending
// thread so it's expected that listeners are fast.
processListeners(packet);
connection.firePacketSendingListeners(packet);
}
}
/**
* Registers a packet listener with this writer. The listener will be
* notified immediately after every packet this writer sends. A packet filter
* determines which packets will be delivered to the listener. Note that the thread
* that writes packets will be used to invoke the listeners. Therefore, each
* packet listener should complete all operations quickly or use a different
* thread for processing.
*
* @param packetListener the packet listener to notify of sent packets.
* @param packetFilter the packet filter to use.
*/
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
listeners.put(packetListener, new ListenerWrapper(packetListener, packetFilter));
}
/**
* Removes a packet listener.
*
* @param packetListener the packet listener to remove.
*/
public void removePacketListener(PacketListener packetListener) {
listeners.remove(packetListener);
}
/**
* Returns the number of registered packet listeners.
*
* @return the count of packet listeners.
*/
public int getPacketListenerCount() {
return listeners.size();
}
/**
* Registers a packet interceptor with this writer. The interceptor will be
* notified of every packet that this writer is about to send. Interceptors
* may modify the packet to be sent. A packet filter determines which packets
* will be delivered to the interceptor.
*
* @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use.
*/
public void addPacketInterceptor(PacketInterceptor packetInterceptor, PacketFilter packetFilter) {
interceptors.put(packetInterceptor, new InterceptorWrapper(packetInterceptor, packetFilter));
}
/**
* Removes a packet interceptor.
*
* @param packetInterceptor the packet interceptor to remove.
*/
public void removePacketInterceptor(PacketInterceptor packetInterceptor) {
interceptors.remove(packetInterceptor);
}
/**
* Starts the packet writer thread and opens a connection to the server. The
* packet writer will continue writing packets until {@link #shutdown} or an
@ -221,8 +155,8 @@ class PacketWriter {
* Cleans up all resources used by the packet writer.
*/
void cleanup() {
interceptors.clear();
listeners.clear();
connection.interceptors.clear();
connection.sendListeners.clear();
}
/**
@ -306,34 +240,6 @@ class PacketWriter {
}
}
/**
* Process listeners.
*
* @param packet the packet to process.
*/
private void processListeners(Packet packet) {
// Notify the listeners of the new sent packet
for (ListenerWrapper listenerWrapper : listeners.values()) {
listenerWrapper.notifyListener(packet);
}
}
/**
* Process interceptors. Interceptors may modify the packet that is about to be sent.
* Since the thread that requested to send the packet will invoke all interceptors, it
* is important that interceptors perform their work as soon as possible so that the
* thread does not remain blocked for a long period.
*
* @param packet the packet that is going to be sent to the server
*/
private void processInterceptors(Packet packet) {
if (packet != null) {
for (InterceptorWrapper interceptorWrapper : interceptors.values()) {
interceptorWrapper.notifyListener(packet);
}
}
}
/**
* Sends to the server a new stream element. This operation may be requested several times
* so we need to encapsulate the logic in one place. This message will be sent while doing
@ -344,7 +250,7 @@ class PacketWriter {
void openStream() throws IOException {
StringBuilder stream = new StringBuilder();
stream.append("<stream:stream");
stream.append(" to=\"").append(connection.serviceName).append("\"");
stream.append(" to=\"").append(connection.getServiceName()).append("\"");
stream.append(" xmlns=\"jabber:client\"");
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
stream.append(" version=\"1.0\">");
@ -352,61 +258,6 @@ class PacketWriter {
writer.flush();
}
/**
* A wrapper class to associate a packet filter with a listener.
*/
private static class ListenerWrapper {
private PacketListener packetListener;
private PacketFilter packetFilter;
public ListenerWrapper(PacketListener packetListener, PacketFilter packetFilter) {
this.packetListener = packetListener;
this.packetFilter = packetFilter;
}
public void notifyListener(Packet packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
packetListener.processPacket(packet);
}
}
}
/**
* A wrapper class to associate a packet filter with an interceptor.
*/
private static class InterceptorWrapper {
private PacketInterceptor packetInterceptor;
private PacketFilter packetFilter;
public InterceptorWrapper(PacketInterceptor packetInterceptor, PacketFilter packetFilter)
{
this.packetInterceptor = packetInterceptor;
this.packetFilter = packetFilter;
}
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (object instanceof InterceptorWrapper) {
return ((InterceptorWrapper) object).packetInterceptor
.equals(this.packetInterceptor);
}
else if (object instanceof PacketInterceptor) {
return object.equals(this.packetInterceptor);
}
return false;
}
public void notifyListener(Packet packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
packetInterceptor.interceptPacket(packet);
}
}
}
/**
* A TimerTask that keeps connections to the server alive by sending a space
* character on an interval.

View File

@ -43,9 +43,9 @@ import java.util.*;
public class PrivacyListManager {
// Keep the list of instances of this class.
private static Map<XMPPConnection, PrivacyListManager> instances = new Hashtable<XMPPConnection, PrivacyListManager>();
private static Map<Connection, PrivacyListManager> instances = new Hashtable<Connection, PrivacyListManager>();
private XMPPConnection connection;
private Connection connection;
private final List<PrivacyListListener> listeners = new ArrayList<PrivacyListListener>();
PacketFilter packetFilter = new AndFilter(new IQTypeFilter(IQ.Type.SET),
new PacketExtensionFilter("query", "jabber:iq:privacy"));
@ -54,8 +54,8 @@ public class PrivacyListManager {
// Create a new PrivacyListManager on every established connection. In the init()
// method of PrivacyListManager, we'll add a listener that will delete the
// instance when the connection is closed.
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
new PrivacyListManager(connection);
}
});
@ -67,7 +67,7 @@ public class PrivacyListManager {
*
* @param connection the XMPP connection.
*/
private PrivacyListManager(XMPPConnection connection) {
private PrivacyListManager(Connection connection) {
this.connection = connection;
this.init();
}
@ -155,12 +155,12 @@ public class PrivacyListManager {
}
/**
* Returns the PrivacyListManager instance associated with a given XMPPConnection.
* Returns the PrivacyListManager instance associated with a given Connection.
*
* @param connection the connection used to look for the proper PrivacyListManager.
* @return the PrivacyListManager associated with a given XMPPConnection.
* @return the PrivacyListManager associated with a given Connection.
*/
public static PrivacyListManager getInstanceFor(XMPPConnection connection) {
public static PrivacyListManager getInstanceFor(Connection connection) {
return instances.get(connection);
}

View File

@ -19,7 +19,7 @@ import org.jivesoftware.smack.packet.StreamError;
public class ReconnectionManager implements ConnectionListener {
// Holds the connection to the server
private XMPPConnection connection;
private Connection connection;
// Holds the state of the reconnection
boolean done = false;
@ -28,14 +28,14 @@ public class ReconnectionManager implements ConnectionListener {
// Create a new PrivacyListManager on every established connection. In the init()
// method of PrivacyListManager, we'll add a listener that will delete the
// instance when the connection is closed.
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
connection.addConnectionListener(new ReconnectionManager(connection));
}
});
}
private ReconnectionManager(XMPPConnection connection) {
private ReconnectionManager(Connection connection) {
this.connection = connection;
}
@ -46,9 +46,8 @@ public class ReconnectionManager implements ConnectionListener {
* @return true if automatic reconnections are allowed.
*/
private boolean isReconnectionAllowed() {
return !done && !connection.isConnected()
&& connection.getConfiguration().isReconnectionAllowed()
&& connection.packetReader != null;
return !done && !connection.isConnected()
&& connection.isReconnectionAllowed();
}
/**
@ -94,7 +93,7 @@ public class ReconnectionManager implements ConnectionListener {
*/
public void run() {
// The process will try to reconnect until the connection is established or
// the user cancel the reconnection process {@link XMPPConnection#disconnect()}
// the user cancel the reconnection process {@link Connection#disconnect()}
while (ReconnectionManager.this.isReconnectionAllowed()) {
// Find how much time we should wait until the next reconnection
int remainingSeconds = timeDelay();
@ -142,21 +141,21 @@ public class ReconnectionManager implements ConnectionListener {
* @param exception the exception that occured.
*/
protected void notifyReconnectionFailed(Exception exception) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.packetReader.connectionListeners) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectionFailed(exception);
}
}
}
/**
* Fires listeners when The XMPPConnection will retry a reconnection. Expressed in seconds.
* Fires listeners when The Connection will retry a reconnection. Expressed in seconds.
*
* @param seconds the number of seconds that a reconnection will be attempted in.
*/
protected void notifyAttemptToReconnectIn(int seconds) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.packetReader.connectionListeners) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectingIn(seconds);
}
}

View File

@ -45,7 +45,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* </ul>
*
* @author Matt Tucker
* @see XMPPConnection#getRoster()
* @see Connection#getRoster()
*/
public class Roster {
@ -55,7 +55,7 @@ public class Roster {
*/
private static SubscriptionMode defaultSubscriptionMode = SubscriptionMode.accept_all;
private XMPPConnection connection;
private Connection connection;
private final Map<String, RosterGroup> groups;
private final Map<String,RosterEntry> entries;
private final List<RosterEntry> unfiledEntries;
@ -97,7 +97,7 @@ public class Roster {
*
* @param connection an XMPP connection.
*/
Roster(final XMPPConnection connection) {
Roster(final Connection connection) {
this.connection = connection;
groups = new ConcurrentHashMap<String, RosterGroup>();
unfiledEntries = new CopyOnWriteArrayList<RosterEntry>();

View File

@ -37,7 +37,7 @@ public class RosterEntry {
private String name;
private RosterPacket.ItemType type;
private RosterPacket.ItemStatus status;
private XMPPConnection connection;
private Connection connection;
/**
* Creates a new roster entry.
@ -49,7 +49,7 @@ public class RosterEntry {
* @param connection a connection to the XMPP server.
*/
RosterEntry(String user, String name, RosterPacket.ItemType type,
RosterPacket.ItemStatus status, XMPPConnection connection) {
RosterPacket.ItemStatus status, Connection connection) {
this.user = user;
this.name = name;
this.type = type;
@ -114,7 +114,7 @@ public class RosterEntry {
List<RosterGroup> results = new ArrayList<RosterGroup>();
// Loop through all roster groups and find the ones that contain this
// entry. This algorithm should be fine
for (RosterGroup group: connection.roster.getGroups()) {
for (RosterGroup group: connection.getRoster().getGroups()) {
if (group.contains(this)) {
results.add(group);
}

View File

@ -39,7 +39,7 @@ import java.util.List;
public class RosterGroup {
private String name;
private XMPPConnection connection;
private Connection connection;
private final List<RosterEntry> entries;
/**
@ -48,7 +48,7 @@ public class RosterGroup {
* @param name the name of the group.
* @param connection the connection the group belongs to.
*/
RosterGroup(String name, XMPPConnection connection) {
RosterGroup(String name, Connection connection) {
this.name = name;
this.connection = connection;
entries = new ArrayList<RosterEntry>();

View File

@ -66,7 +66,7 @@ public class SASLAuthentication implements UserAuthentication {
private static Map<String, Class> implementedMechanisms = new HashMap<String, Class>();
private static List<String> mechanismsPreferences = new ArrayList<String>();
private XMPPConnection connection;
private Connection connection;
private Collection<String> serverMechanisms = new ArrayList<String>();
private SASLMechanism currentMechanism = null;
/**
@ -171,7 +171,7 @@ public class SASLAuthentication implements UserAuthentication {
return answer;
}
SASLAuthentication(XMPPConnection connection) {
SASLAuthentication(Connection connection) {
super();
this.connection = connection;
this.init();

View File

@ -20,7 +20,6 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
@ -43,102 +42,21 @@ import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Creates a connection to a XMPP server. A simple use of this API might
* look like the following:
* <pre>
* // Create a connection to the igniterealtime.org XMPP server.
* XMPPConnection con = new XMPPConnection("igniterealtime.org");
* // Connect to the server
* con.connect();
* // Most servers require you to login before performing other tasks.
* con.login("jsmith", "mypass");
* // Start a new conversation with John Doe and send him a message.
* Chat chat = connection.getChatManager().createChat("jdoe@igniterealtime.org"</font>, new MessageListener() {
* <p/>
* public void processMessage(Chat chat, Message message) {
* // Print out any messages we get back to standard out.
* System.out.println(<font color="green">"Received message: "</font> + message);
* }
* });
* chat.sendMessage(<font color="green">"Howdy!"</font>);
* // Disconnect from the server
* con.disconnect();
* </pre>
* <p/>
* XMPPConnections can be reused between connections. This means that an XMPPConnection
* may be connected, disconnected and then connected again. Listeners of the XMPPConnection
* will be retained accross connections.<p>
* <p/>
* If a connected XMPPConnection gets disconnected abruptly then it will try to reconnect
* again. To stop the reconnection process, use {@link #disconnect()}. Once stopped
* you can use {@link #connect()} to manually connect to the server.
*
* Creates a socket connection to a XMPP server. This is the default connection
* to a Jabber server and is specified in the XMPP Core (RFC 3920).
*
* @see Connection
* @author Matt Tucker
*/
public class XMPPConnection {
public class XMPPConnection extends Connection {
/**
* Value that indicates whether debugging is enabled. When enabled, a debug
* window will apear for each new connection that will contain the following
* information:<ul>
* <li> Client Traffic -- raw XML traffic generated by Smack and sent to the server.
* <li> Server Traffic -- raw XML traffic sent by the server to the client.
* <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
* </ul>
* <p/>
* Debugging can be enabled by setting this field to true, or by setting the Java system
* property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
* command line such as "java SomeApp -Dsmack.debugEnabled=true".
* The socket which is used for this connection.
*/
public static boolean DEBUG_ENABLED = false;
private final static Set<ConnectionCreationListener> connectionEstablishedListeners =
new CopyOnWriteArraySet<ConnectionCreationListener>();
// Counter to uniquely identify connections that are created. This is distinct from the
// connection ID, which is a value sent by the server once a connection is made.
private static AtomicInteger connectionCounter = new AtomicInteger(0);
// CallbackHandler to handle prompting for theh keystore password.
private CallbackHandler callbackHandler = null;
static {
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
}
catch (Exception e) {
// Ignore.
}
// Ensure the SmackConfiguration class is loaded by calling a method in it.
SmackConfiguration.getVersion();
}
private SmackDebugger debugger = null;
/**
* IP address or host name of the server. This information is only used when
* creating new socket connections to the server. If this information is not
* configured then it will be assumed that the host name matches the service name.
*/
String host;
int port;
Socket socket;
/**
* Hostname of the XMPP server. Usually servers use the same service name as the name
* of the server. However, there are some servers like google where host would be
* talk.google.com and the serviceName would be gmail.com.
*/
String serviceName;
int connectionCounterValue = connectionCounter.getAndIncrement();
String connectionID = null;
private String user = null;
private boolean connected = false;
@ -158,25 +76,15 @@ public class XMPPConnection {
PacketReader packetReader;
Roster roster = null;
private AccountManager accountManager = null;
private SASLAuthentication saslAuthentication = new SASLAuthentication(this);
Writer writer;
Reader reader;
/**
* Collection of available stream compression methods offered by the server.
*/
private Collection compressionMethods;
private Collection<String> compressionMethods;
/**
* Flag that indicates if stream compression is actually in use.
*/
private boolean usingCompression;
/**
* Holds the initial configuration used while creating the connection.
*/
private ConnectionConfiguration configuration;
private ChatManager chatManager;
/**
@ -203,12 +111,11 @@ public class XMPPConnection {
*/
public XMPPConnection(String serviceName, CallbackHandler callbackHandler) {
// Create the configuration for this new connection
ConnectionConfiguration config = new ConnectionConfiguration(serviceName);
super(new ConnectionConfiguration(serviceName));
config.setCompressionEnabled(false);
config.setSASLAuthenticationEnabled(true);
config.setDebuggerEnabled(DEBUG_ENABLED);
this.configuration = config;
this.callbackHandler = callbackHandler;
config.setCallbackHandler(callbackHandler);
}
/**
@ -221,12 +128,10 @@ public class XMPPConnection {
*/
public XMPPConnection(String serviceName) {
// Create the configuration for this new connection
ConnectionConfiguration config = new ConnectionConfiguration(serviceName);
super(new ConnectionConfiguration(serviceName));
config.setCompressionEnabled(false);
config.setSASLAuthenticationEnabled(true);
config.setDebuggerEnabled(DEBUG_ENABLED);
this.configuration = config;
this.callbackHandler = config.getCallbackHandler();
}
/**
@ -239,8 +144,7 @@ public class XMPPConnection {
* @param config the connection configuration.
*/
public XMPPConnection(ConnectionConfiguration config) {
this.configuration = config;
this.callbackHandler = config.getCallbackHandler();
super(config);
}
/**
@ -262,19 +166,10 @@ public class XMPPConnection {
* @param callbackHandler the CallbackHandler used to prompt for the password to the keystore.
*/
public XMPPConnection(ConnectionConfiguration config, CallbackHandler callbackHandler) {
this.configuration = config;
this.callbackHandler = callbackHandler;
super(config);
config.setCallbackHandler(callbackHandler);
}
/**
* Returns the connection ID for this connection, which is the value set by the server
* when opening a XMPP stream. If the server does not set a connection ID, this value
* will be null. This value will be <tt>null</tt> if not connected to the server.
*
* @return the ID of this connection returned from the XMPP server or <tt>null</tt> if
* not connected to the server.
*/
public String getConnectionID() {
if (!isConnected()) {
return null;
@ -282,43 +177,6 @@ public class XMPPConnection {
return connectionID;
}
/**
* Returns the name of the service provided by the XMPP server for this connection. After
* authenticating with the server the returned value may be different.
*
* @return the name of the service provided by the XMPP server.
*/
public String getServiceName() {
return serviceName;
}
/**
* Returns the host name of the server where the XMPP server is running. This would be the
* IP address of the server or a name that may be resolved by a DNS server.
*
* @return the host name of the server where the XMPP server is running.
*/
public String getHost() {
return host;
}
/**
* Returns the port number of the XMPP server for this connection. The default port
* for normal connections is 5222. The default port for SSL connections is 5223.
*
* @return the port number of the XMPP server.
*/
public int getPort() {
return port;
}
/**
* Returns the full XMPP address of the user that is logged in to the connection or
* <tt>null</tt> if not logged in yet. An XMPP address is in the form
* username@server/resource.
*
* @return the full XMPP address of the user logged in.
*/
public String getUser() {
if (!isAuthenticated()) {
return null;
@ -326,29 +184,6 @@ public class XMPPConnection {
return user;
}
/**
* Logs in to the server using the strongest authentication mode supported by
* the server, then sets presence to available. If more than five seconds
* (default timeout) elapses in each step of the authentication process without
* a response from the server, or if an error occurs, a XMPPException will be thrown.<p>
*
* It is possible to log in without sending an initial available presence by using
* {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is
* not interested in loading its roster upon login then use
* {@link ConnectionConfiguration#setRosterLoadedAtLogin(boolean)}.
* Finally, if you want to not pass a password and instead use a more advanced mechanism
* while using SASL then you may be interested in using
* {@link ConnectionConfiguration#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}.
* For more advanced login settings see {@link ConnectionConfiguration}.
*
* @param username the username.
* @param password the password or <tt>null</tt> if using a CallbackHandler.
* @throws XMPPException if an error occurs.
*/
public void login(String username, String password) throws XMPPException {
login(username, password, "Smack");
}
/**
* Logs in to the server using the strongest authentication mode supported by
* the server. If the server supports SASL authentication then the user will be
@ -388,7 +223,7 @@ public class XMPPConnection {
username = username.toLowerCase().trim();
String response;
if (configuration.isSASLAuthenticationEnabled() &&
if (config.isSASLAuthenticationEnabled() &&
saslAuthentication.hasNonAnonymousAuthentication()) {
// Authenticate using SASL
if (password != null) {
@ -396,7 +231,7 @@ public class XMPPConnection {
}
else {
response = saslAuthentication
.authenticate(username, resource, configuration.getCallbackHandler());
.authenticate(username, resource, config.getCallbackHandler());
}
}
else {
@ -408,17 +243,17 @@ public class XMPPConnection {
if (response != null) {
this.user = response;
// Update the serviceName with the one returned by the server
this.serviceName = StringUtils.parseServer(response);
config.setServiceName(StringUtils.parseServer(response));
}
else {
this.user = username + "@" + this.serviceName;
this.user = username + "@" + getServiceName();
if (resource != null) {
this.user += "/" + resource;
}
}
// If compression is enabled then request the server to use stream compression
if (configuration.isCompressionEnabled()) {
if (config.isCompressionEnabled()) {
useCompression();
}
@ -426,12 +261,12 @@ public class XMPPConnection {
if (this.roster == null) {
this.roster = new Roster(this);
}
if (configuration.isRosterLoadedAtLogin()) {
roster.reload();
if (config.isRosterLoadedAtLogin()) {
this.roster.reload();
}
// Set presence to online.
if (configuration.isSendPresence()) {
if (config.isSendPresence()) {
packetWriter.sendPacket(new Presence(Presence.Type.available));
}
@ -440,13 +275,13 @@ public class XMPPConnection {
anonymous = false;
// Stores the autentication for future reconnection
this.getConfiguration().setLoginInfo(username, password, resource);
config.setLoginInfo(username, password, resource);
// If debugging is enabled, change the the debug window title to include the
// name we are now logged-in as.
// If DEBUG_ENABLED was set to true AFTER the connection was created the debugger
// will be null
if (configuration.isDebuggerEnabled() && debugger != null) {
if (config.isDebuggerEnabled() && debugger != null) {
debugger.userHasLogged(user);
}
}
@ -470,7 +305,7 @@ public class XMPPConnection {
}
String response;
if (configuration.isSASLAuthenticationEnabled() &&
if (config.isSASLAuthenticationEnabled() &&
saslAuthentication.hasAnonymousAuthentication()) {
response = saslAuthentication.authenticateAnonymously();
}
@ -482,10 +317,10 @@ public class XMPPConnection {
// Set the user value.
this.user = response;
// Update the serviceName with the one returned by the server
this.serviceName = StringUtils.parseServer(response);
config.setServiceName(StringUtils.parseServer(response));
// If compression is enabled then request the server to use stream compression
if (configuration.isCompressionEnabled()) {
if (config.isCompressionEnabled()) {
useCompression();
}
@ -503,25 +338,18 @@ public class XMPPConnection {
// name we are now logged-in as.
// If DEBUG_ENABLED was set to true AFTER the connection was created the debugger
// will be null
if (configuration.isDebuggerEnabled() && debugger != null) {
if (config.isDebuggerEnabled() && debugger != null) {
debugger.userHasLogged(user);
}
}
/**
* Returns the roster for the user logged into the server. If the user has not yet
* logged into the server (or if the user is logged in anonymously), this method will return
* <tt>null</tt>.
*
* @return the user's roster, or <tt>null</tt> if the user has not logged in yet.
*/
public Roster getRoster() {
if (!configuration.isRosterLoadedAtLogin()) {
roster.reload();
}
if (roster == null) {
return null;
}
if (!config.isRosterLoadedAtLogin()) {
roster.reload();
}
// If this is the first time the user has asked for the roster after calling
// login, we want to wait for the server to send back the user's roster. This
// behavior shields API users from having to worry about the fact that roster
@ -552,64 +380,18 @@ public class XMPPConnection {
return roster;
}
/**
* Returns an account manager instance for this connection.
*
* @return an account manager for this connection.
*/
public AccountManager getAccountManager() {
if (accountManager == null) {
accountManager = new AccountManager(this);
}
return accountManager;
}
/**
* Returns a chat manager instance for this connection. The ChatManager manages all incoming and
* outgoing chats on the current connection.
*
* @return a chat manager instance for this connection.
*/
public synchronized ChatManager getChatManager() {
if (this.chatManager == null) {
this.chatManager = new ChatManager(this);
}
return this.chatManager;
}
/**
* Returns true if currently connected to the XMPP server.
*
* @return true if connected.
*/
public boolean isConnected() {
return connected;
}
/**
* Returns true if the connection to the server has successfully negotiated TLS. Once TLS
* has been negotiatied the connection has been secured. @see #isUsingTLS.
*
* @return true if a secure connection to the server.
*/
public boolean isSecureConnection() {
return isUsingTLS();
}
/**
* Returns true if currently authenticated by successfully calling the login method.
*
* @return true if authenticated.
*/
public boolean isAuthenticated() {
return authenticated;
}
/**
* Returns true if currently authenticated anonymously.
*
* @return true if authenticated anonymously.
*/
public boolean isAnonymous() {
return anonymous;
}
@ -667,37 +449,6 @@ public class XMPPConnection {
saslAuthentication.init();
}
/**
* Closes the connection by setting presence to unavailable then closing the stream to
* the XMPP server. The XMPPConnection can still be used for connecting to the server
* again.<p>
* <p/>
* This method cleans up all resources used by the connection. Therefore, the roster,
* listeners and other stateful objects cannot be re-used by simply calling connect()
* on this connection again. This is unlike the behavior during unexpected disconnects
* (and subsequent connections). In that case, all state is preserved to allow for
* more seamless error recovery.
*/
public void disconnect() {
disconnect(new Presence(Presence.Type.unavailable));
}
/**
* Closes the connection. A custom unavailable presence is sent to the server, followed
* by closing the stream. The XMPPConnection can still be used for connecting to the server
* again. A custom unavilable presence is useful for communicating offline presence
* information such as "On vacation". Typically, just the status text of the presence
* packet is set with online information, but most XMPP servers will deliver the full
* presence packet with whatever data is set.<p>
* <p/>
* This method cleans up all resources used by the connection. Therefore, the roster,
* listeners and other stateful objects cannot be re-used by simply calling connect()
* on this connection again. This is unlike the behavior during unexpected disconnects
* (and subsequent connections). In that case, all state is preserved to allow for
* more seamless error recovery.
*
* @param unavailablePresence the presence packet to send during shutdown.
*/
public void disconnect(Presence unavailablePresence) {
// If not connected, ignore this request.
if (packetReader == null || packetWriter == null) {
@ -719,11 +470,6 @@ public class XMPPConnection {
packetReader = null;
}
/**
* Sends the specified packet to the server.
*
* @param packet the packet to send.
*/
public void sendPacket(Packet packet) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
@ -735,29 +481,28 @@ public class XMPPConnection {
}
/**
* Registers a packet listener with this connection. A packet filter determines
* which packets will be delivered to the listener. If the same packet listener
* is added again with a different filter, only the new filter will be used.
* Registers a packet interceptor with this connection. The interceptor will be
* invoked every time a packet is about to be sent by this connection. Interceptors
* may modify the packet to be sent. A packet filter determines which packets
* will be delivered to the interceptor.
*
* @param packetListener the packet listener to notify of new packets.
* @param packetFilter the packet filter to use.
* @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use.
* @deprecated replaced by {@link Connection#addPacketInterceptor(PacketInterceptor, PacketFilter)}.
*/
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
packetReader.addPacketListener(packetListener, packetFilter);
public void addPacketWriterInterceptor(PacketInterceptor packetInterceptor,
PacketFilter packetFilter) {
addPacketInterceptor(packetInterceptor, packetFilter);
}
/**
* Removes a packet listener from this connection.
* Removes a packet interceptor.
*
* @param packetListener the packet listener to remove.
* @param packetInterceptor the packet interceptor to remove.
* @deprecated replaced by {@link Connection#removePacketInterceptor(PacketInterceptor)}.
*/
public void removePacketListener(PacketListener packetListener) {
if (packetReader != null) {
packetReader.removePacketListener(packetListener);
}
public void removePacketWriterInterceptor(PacketInterceptor packetInterceptor) {
removePacketInterceptor(packetInterceptor);
}
/**
@ -770,116 +515,25 @@ public class XMPPConnection {
*
* @param packetListener the packet listener to notify of sent packets.
* @param packetFilter the packet filter to use.
* @deprecated replaced by {@link #addPacketSendingListener(PacketListener, PacketFilter)}.
*/
public void addPacketWriterListener(PacketListener packetListener, PacketFilter packetFilter) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
packetWriter.addPacketListener(packetListener, packetFilter);
addPacketSendingListener(packetListener, packetFilter);
}
/**
* Removes a packet listener from this connection.
* Removes a packet listener for sending packets from this connection.
*
* @param packetListener the packet listener to remove.
* @deprecated replaced by {@link #removePacketSendingListener(PacketListener)}.
*/
public void removePacketWriterListener(PacketListener packetListener) {
if (packetWriter != null) {
packetWriter.removePacketListener(packetListener);
}
}
/**
* Registers a packet interceptor with this connection. The interceptor will be
* invoked every time a packet is about to be sent by this connection. Interceptors
* may modify the packet to be sent. A packet filter determines which packets
* will be delivered to the interceptor.
*
* @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use.
*/
public void addPacketWriterInterceptor(PacketInterceptor packetInterceptor,
PacketFilter packetFilter) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
packetWriter.addPacketInterceptor(packetInterceptor, packetFilter);
}
/**
* Removes a packet interceptor.
*
* @param packetInterceptor the packet interceptor to remove.
*/
public void removePacketWriterInterceptor(PacketInterceptor packetInterceptor) {
packetWriter.removePacketInterceptor(packetInterceptor);
}
/**
* Creates a new packet collector for this connection. A packet filter determines
* which packets will be accumulated by the collector.
*
* @param packetFilter the packet filter to use.
* @return a new packet collector.
*/
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
return packetReader.createPacketCollector(packetFilter);
}
/**
* Adds a connection listener to this connection that will be notified when
* the connection closes or fails. The connection needs to already be connected
* or otherwise an IllegalStateException will be thrown.
*
* @param connectionListener a connection listener.
*/
public void addConnectionListener(ConnectionListener connectionListener) {
if (!isConnected()) {
throw new IllegalStateException("Not connected to server.");
}
if (connectionListener == null) {
return;
}
if (!packetReader.connectionListeners.contains(connectionListener)) {
packetReader.connectionListeners.add(connectionListener);
}
}
/**
* Removes a connection listener from this connection.
*
* @param connectionListener a connection listener.
*/
public void removeConnectionListener(ConnectionListener connectionListener) {
if (packetReader != null) {
packetReader.connectionListeners.remove(connectionListener);
}
}
/**
* Adds a new listener that will be notified when new XMPPConnections are created. Note
* that newly created connections will not be actually connected to the server.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void addConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.add(connectionCreationListener);
}
/**
* Removes a listener that was interested in connection creation events.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void removeConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.remove(connectionCreationListener);
removePacketSendingListener(packetListener);
}
private void connectUsingConfiguration(ConnectionConfiguration config) throws XMPPException {
this.host = config.getHost();
this.port = config.getPort();
String host = config.getHost();
int port = config.getPort();
try {
if (config.getSocketFactory() == null) {
this.socket = new Socket(host, port);
@ -900,7 +554,6 @@ public class XMPPConnection {
throw new XMPPException(errorMessage, new XMPPError(
XMPPError.Condition.remote_server_error, errorMessage), ioe);
}
this.serviceName = config.getServiceName();
initConnection();
}
@ -926,10 +579,10 @@ public class XMPPConnection {
// If debugging is enabled, we should start the thread that will listen for
// all packets and then log them.
if (configuration.isDebuggerEnabled()) {
packetReader.addPacketListener(debugger.getReaderListener(), null);
if (config.isDebuggerEnabled()) {
addPacketListener(debugger.getReaderListener(), null);
if (debugger.getWriterListener() != null) {
packetWriter.addPacketListener(debugger.getWriterListener(), null);
addPacketSendingListener(debugger.getWriterListener(), null);
}
}
}
@ -953,7 +606,7 @@ public class XMPPConnection {
if (isFirstInitialization) {
// Notify listeners that a new connection has been established
for (ConnectionCreationListener listener : connectionEstablishedListeners) {
for (ConnectionCreationListener listener : getConnectionCreationListeners()) {
listener.connectionCreated(this);
}
}
@ -1053,62 +706,7 @@ public class XMPPConnection {
}
// If debugging is enabled, we open a window and write out all network traffic.
if (configuration.isDebuggerEnabled()) {
if (debugger == null) {
// Detect the debugger class to use.
String className = null;
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
className = System.getProperty("smack.debuggerClass");
}
catch (Throwable t) {
// Ignore.
}
Class<?> debuggerClass = null;
if (className != null) {
try {
debuggerClass = Class.forName(className);
}
catch (Exception e) {
e.printStackTrace();
}
}
if (debuggerClass == null) {
try {
debuggerClass =
Class.forName("org.jivesoftware.smackx.debugger.EnhancedDebugger");
}
catch (Exception ex) {
try {
debuggerClass =
Class.forName("org.jivesoftware.smack.debugger.LiteDebugger");
}
catch (Exception ex2) {
ex2.printStackTrace();
}
}
}
// Create a new debugger instance. If an exception occurs then disable the debugging
// option
try {
Constructor<?> constructor = debuggerClass
.getConstructor(XMPPConnection.class, Writer.class, Reader.class);
debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
reader = debugger.getReader();
writer = debugger.getWriter();
}
catch (Exception e) {
e.printStackTrace();
DEBUG_ENABLED = false;
}
}
else {
// Obtain new reader and writer from the existing debugger
reader = debugger.newConnectionReader(reader);
writer = debugger.newConnectionWriter(writer);
}
}
initDebugger();
}
/***********************************************
@ -1125,26 +723,6 @@ public class XMPPConnection {
return usingTLS;
}
/**
* Returns the SASLAuthentication manager that is responsible for authenticating with
* the server.
*
* @return the SASLAuthentication manager that is responsible for authenticating with
* the server.
*/
public SASLAuthentication getSASLAuthentication() {
return saslAuthentication;
}
/**
* Returns the configuration used to connect to the server.
*
* @return the configuration used to connect to the server.
*/
protected ConnectionConfiguration getConfiguration() {
return configuration;
}
/**
* Notification message saying that the server supports TLS so confirm the server that we
* want to secure the connection.
@ -1152,14 +730,14 @@ public class XMPPConnection {
* @param required true when the server indicates that TLS is required.
*/
void startTLSReceived(boolean required) {
if (required && configuration.getSecurityMode() ==
if (required && config.getSecurityMode() ==
ConnectionConfiguration.SecurityMode.disabled) {
packetReader.notifyConnectionError(new IllegalStateException(
"TLS required by server but not allowed by connection configuration"));
return;
}
if (configuration.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled) {
if (config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled) {
// Do not secure the connection using TLS since TLS was disabled
return;
}
@ -1185,24 +763,24 @@ public class XMPPConnection {
KeyManager[] kms = null;
PasswordCallback pcb = null;
if(callbackHandler == null) {
if(config.getCallbackHandler() == null) {
ks = null;
} else {
//System.out.println("Keystore type: "+configuration.getKeystoreType());
if(configuration.getKeystoreType().equals("NONE")) {
if(config.getKeystoreType().equals("NONE")) {
ks = null;
pcb = null;
}
else if(configuration.getKeystoreType().equals("PKCS11")) {
else if(config.getKeystoreType().equals("PKCS11")) {
try {
Constructor c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class);
String pkcs11Config = "name = SmartCard\nlibrary = "+configuration.getPKCS11Library();
String pkcs11Config = "name = SmartCard\nlibrary = "+config.getPKCS11Library();
ByteArrayInputStream config = new ByteArrayInputStream(pkcs11Config.getBytes());
Provider p = (Provider)c.newInstance(config);
Security.addProvider(p);
ks = KeyStore.getInstance("PKCS11",p);
pcb = new PasswordCallback("PKCS11 Password: ",false);
callbackHandler.handle(new Callback[]{pcb});
this.config.getCallbackHandler().handle(new Callback[]{pcb});
ks.load(null,pcb.getPassword());
}
catch (Exception e) {
@ -1210,18 +788,18 @@ public class XMPPConnection {
pcb = null;
}
}
else if(configuration.getKeystoreType().equals("Apple")) {
else if(config.getKeystoreType().equals("Apple")) {
ks = KeyStore.getInstance("KeychainStore","Apple");
ks.load(null,null);
//pcb = new PasswordCallback("Apple Keychain",false);
//pcb.setPassword(null);
}
else {
ks = KeyStore.getInstance(configuration.getKeystoreType());
ks = KeyStore.getInstance(config.getKeystoreType());
try {
pcb = new PasswordCallback("Keystore Password: ",false);
callbackHandler.handle(new Callback[]{pcb});
ks.load(new FileInputStream(configuration.getKeystorePath()), pcb.getPassword());
config.getCallbackHandler().handle(new Callback[]{pcb});
ks.load(new FileInputStream(config.getKeystorePath()), pcb.getPassword());
}
catch(Exception e) {
ks = null;
@ -1244,7 +822,8 @@ public class XMPPConnection {
// Verify certificate presented by the server
context.init(kms,
new javax.net.ssl.TrustManager[]{new ServerTrustManager(serviceName, configuration)},
new javax.net.ssl.TrustManager[]{new ServerTrustManager(getServiceName(), config)},
//new javax.net.ssl.TrustManager[]{new OpenTrustManager()},
new java.security.SecureRandom());
Socket plain = socket;
// Secure the plain connection
@ -1279,7 +858,7 @@ public class XMPPConnection {
*
* @param methods compression methods offered by the server.
*/
void setAvailableCompressionMethods(Collection methods) {
void setAvailableCompressionMethods(Collection<String> methods) {
compressionMethods = methods;
}
@ -1293,16 +872,6 @@ public class XMPPConnection {
return compressionMethods != null && compressionMethods.contains(method);
}
/**
* Returns true if network traffic is being compressed. When using stream compression network
* traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow
* speed network connection. However, the server will need to use more CPU time in order to
* un/compress network data so under high load the server performance might be affected.<p>
* <p/>
* Note: to use stream compression the smackx.jar file has to be present in the classpath.
*
* @return true if network traffic is being compressed.
*/
public boolean isUsingCompression() {
return usingCompression;
}
@ -1412,7 +981,7 @@ public class XMPPConnection {
*/
public void connect() throws XMPPException {
// Stablishes the connection, readers and writers
connectUsingConfiguration(configuration);
connectUsingConfiguration(config);
// Automatically makes the login if the user was previouslly connected successfully
// to the server and the connection was terminated abruptly
if (connected && wasAuthenticated) {
@ -1423,8 +992,8 @@ public class XMPPConnection {
loginAnonymously();
}
else {
login(getConfiguration().getUsername(), getConfiguration().getPassword(),
getConfiguration().getResource());
login(config.getUsername(), config.getPassword(),
config.getResource());
}
}
catch (XMPPException e) {

View File

@ -2,7 +2,7 @@ package org.jivesoftware.smack.debugger;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.*;
@ -27,7 +27,7 @@ public class ConsoleDebugger implements SmackDebugger {
public static boolean printInterpreted = false;
private SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");
private XMPPConnection connection = null;
private Connection connection = null;
private PacketListener listener = null;
private ConnectionListener connListener = null;
@ -37,7 +37,7 @@ public class ConsoleDebugger implements SmackDebugger {
private ReaderListener readerListener;
private WriterListener writerListener;
public ConsoleDebugger(XMPPConnection connection, Writer writer, Reader reader) {
public ConsoleDebugger(Connection connection, Writer writer, Reader reader) {
this.connection = connection;
this.writer = writer;
this.reader = reader;

View File

@ -42,7 +42,7 @@ public class LiteDebugger implements SmackDebugger {
private static final String NEWLINE = "\n";
private JFrame frame = null;
private XMPPConnection connection = null;
private Connection connection = null;
private PacketListener listener = null;
@ -51,7 +51,7 @@ public class LiteDebugger implements SmackDebugger {
private ReaderListener readerListener;
private WriterListener writerListener;
public LiteDebugger(XMPPConnection connection, Writer writer, Reader reader) {
public LiteDebugger(Connection connection, Writer writer, Reader reader) {
this.connection = connection;
this.writer = writer;
this.reader = reader;

View File

@ -29,7 +29,7 @@ import org.jivesoftware.smack.*;
* displays XML traffic.<p>
*
* Every implementation of this interface <b>must</b> have a public constructor with the following
* arguments: XMPPConnection, Writer, Reader.
* arguments: Connection, Writer, Reader.
*
* @author Gaston Dombiak
*/

View File

@ -106,7 +106,7 @@ public class Authentication extends IQ {
*
* @param connectionID the connection ID.
* @param password the password.
* @see org.jivesoftware.smack.XMPPConnection#getConnectionID()
* @see org.jivesoftware.smack.Connection#getConnectionID()
*/
public void setDigest(String connectionID, String password) {
this.digest = StringUtils.hash(connectionID + password);
@ -121,7 +121,7 @@ public class Authentication extends IQ {
*
* @param digest the digest, which is the SHA-1 hash of the connection ID
* the user's password, encoded as hex.
* @see org.jivesoftware.smack.XMPPConnection#getConnectionID()
* @see org.jivesoftware.smack.Connection#getConnectionID()
*/
public void setDigest(String digest) {
this.digest = digest;

View File

@ -109,9 +109,9 @@ import java.util.concurrent.ConcurrentHashMap;
*
* It is possible to provide a custom provider manager instead of the default implementation
* provided by Smack. If you want to provide your own provider manager then you need to do it
* before creating any {@link org.jivesoftware.smack.XMPPConnection} by sending the static
* before creating any {@link org.jivesoftware.smack.Connection} by sending the static
* {@link #setInstance(ProviderManager)} message. Trying to change the provider manager after
* an XMPPConnection was created will result in an {@link IllegalStateException} error.
* an Connection was created will result in an {@link IllegalStateException} error.
*
* @author Matt Tucker
*/
@ -137,9 +137,9 @@ public class ProviderManager {
}
/**
* Sets the only ProviderManager valid instance to be used by all XMPPConnections. If you
* Sets the only ProviderManager valid instance to be used by all Connections. If you
* want to provide your own provider manager then you need to do it before creating
* any XMPPConnection. Otherwise an IllegalStateException will be thrown.
* any Connection. Otherwise an IllegalStateException will be thrown.
*
* @param providerManager the only ProviderManager valid instance to be used.
* @throws IllegalStateException if a provider manager was already configued.

View File

@ -34,11 +34,11 @@ import java.util.Map;
import java.util.WeakHashMap;
/**
* Handles chat state for all chats on a particular XMPPConnection. This class manages both the
* Handles chat state for all chats on a particular Connection. This class manages both the
* packet extensions and the disco response neccesary for compliance with
* <a href="http://www.xmpp.org/extensions/xep-0085.html">XEP-0085</a>.
*
* NOTE: {@link org.jivesoftware.smackx.ChatStateManager#getInstance(org.jivesoftware.smack.XMPPConnection)}
* NOTE: {@link org.jivesoftware.smackx.ChatStateManager#getInstance(org.jivesoftware.smack.Connection)}
* needs to be called in order for the listeners to be registered appropriately with the connection.
* If this does not occur you will not receive the update notifications.
*
@ -48,20 +48,20 @@ import java.util.WeakHashMap;
*/
public class ChatStateManager {
private static final Map<XMPPConnection, ChatStateManager> managers =
new WeakHashMap<XMPPConnection, ChatStateManager>();
private static final Map<Connection, ChatStateManager> managers =
new WeakHashMap<Connection, ChatStateManager>();
private static final PacketFilter filter = new NotFilter(
new PacketExtensionFilter("http://jabber.org/protocol/chatstates"));
/**
* Returns the ChatStateManager related to the XMPPConnection and it will create one if it does
* Returns the ChatStateManager related to the Connection and it will create one if it does
* not yet exist.
*
* @param connection the connection to return the ChatStateManager
* @return the ChatStateManager related the the connection.
*/
public static ChatStateManager getInstance(final XMPPConnection connection) {
public static ChatStateManager getInstance(final Connection connection) {
if(connection == null) {
return null;
}
@ -77,7 +77,7 @@ public class ChatStateManager {
}
}
private final XMPPConnection connection;
private final Connection connection;
private final OutgoingMessageInterceptor outgoingInterceptor = new OutgoingMessageInterceptor();
@ -89,7 +89,7 @@ public class ChatStateManager {
private final Map<Chat, ChatState> chatStates =
new ReferenceMap<Chat, ChatState>(ReferenceMap.WEAK, ReferenceMap.HARD);
private ChatStateManager(XMPPConnection connection) {
private ChatStateManager(Connection connection) {
this.connection = connection;
}

View File

@ -32,7 +32,7 @@ import org.jivesoftware.smackx.packet.LastActivity;
/**
* A last activity manager for handling information about the last activity associated
* with a Jabber ID. A manager handles incoming LastActivity requests of existing
* XMPPConnections. It also allows to request last activity information of other users.<p>
* Connections. It also allows to request last activity information of other users.<p>
*
* LastActivity (JEP-012) based on the sending JID's type allows for retrieval of:
* <ol>
@ -46,7 +46,7 @@ import org.jivesoftware.smackx.packet.LastActivity;
* LastActivity packet to them, as in the following code:<p>
*
* <pre>
* XMPPConnection con = new XMPPConnection("jabber.org");
* Connection con = new XMPPConnection("jabber.org");
* con.login("john", "doe");
* LastActivity activity = LastActivity.getLastActivity(con, "xray@jabber.org/Smack");
* </pre>
@ -71,12 +71,12 @@ public class LastActivityManager {
private long lastMessageSent;
private XMPPConnection connection;
private Connection connection;
// Enable the LastActivity support on every established connection
static {
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
new LastActivityManager(connection);
}
});
@ -85,13 +85,13 @@ public class LastActivityManager {
/**
* Creates a last activity manager to response last activity requests.
*
* @param connection The XMPPConnection that the last activity requests will use.
* @param connection The Connection that the last activity requests will use.
*/
private LastActivityManager(XMPPConnection connection) {
private LastActivityManager(Connection connection) {
this.connection = connection;
// Listen to all the sent messages to reset the idle time on each one
connection.addPacketWriterListener(new PacketListener() {
connection.addPacketSendingListener(new PacketListener() {
public void processPacket(Packet packet) {
resetIdleTime();
}
@ -141,12 +141,12 @@ public class LastActivityManager {
* when the jid is a server or component (e.g., a JID of the form 'host') the
* last activity is the uptime.
*
* @param con the current XMPPConnection.
* @param con the current Connection.
* @param jid the JID of the user.
* @return the LastActivity packet of the jid.
* @throws XMPPException thrown if a server error has occured.
*/
public static LastActivity getLastActivity(XMPPConnection con, String jid)
public static LastActivity getLastActivity(Connection con, String jid)
throws XMPPException {
LastActivity activity = new LastActivity();
activity.setTo(jid);

View File

@ -27,7 +27,7 @@ import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
@ -46,7 +46,7 @@ public class MessageEventManager {
private List<MessageEventNotificationListener> messageEventNotificationListeners = new ArrayList<MessageEventNotificationListener>();
private List<MessageEventRequestListener> messageEventRequestListeners = new ArrayList<MessageEventRequestListener>();
private XMPPConnection con;
private Connection con;
private PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:event");
private PacketListener packetListener;
@ -54,9 +54,9 @@ public class MessageEventManager {
/**
* Creates a new message event manager.
*
* @param con an XMPPConnection.
* @param con a Connection to a XMPP server.
*/
public MessageEventManager(XMPPConnection con) {
public MessageEventManager(Connection con) {
this.con = con;
init();
}

View File

@ -74,7 +74,7 @@ public class MultipleRecipientInfo {
/**
* Returns true if the received packet should not be replied. Use
* {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
* {@link MultipleRecipientManager#reply(org.jivesoftware.smack.Connection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
* to send replies.
*
* @return true if the received packet should not be replied.

View File

@ -20,7 +20,7 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
@ -67,7 +67,7 @@ public class MultipleRecipientManager {
* @throws XMPPException if server does not support JEP-33: Extended Stanza Addressing and
* some JEP-33 specific features were requested.
*/
public static void send(XMPPConnection connection, Packet packet, List to, List cc, List bcc)
public static void send(Connection connection, Packet packet, List to, List cc, List bcc)
throws XMPPException {
send(connection, packet, to, cc, bcc, null, null, false);
}
@ -95,7 +95,7 @@ public class MultipleRecipientManager {
* @throws XMPPException if server does not support JEP-33: Extended Stanza Addressing and
* some JEP-33 specific features were requested.
*/
public static void send(XMPPConnection connection, Packet packet, List to, List cc, List bcc,
public static void send(Connection connection, Packet packet, List to, List cc, List bcc,
String replyTo, String replyRoom, boolean noReply) throws XMPPException {
String serviceAddress = getMultipleRecipienServiceAddress(connection);
if (serviceAddress != null) {
@ -127,7 +127,7 @@ public class MultipleRecipientManager {
* @throws XMPPException if the original message was not sent to multiple recipients, or the
* original message cannot be replied or reply should be sent to a room.
*/
public static void reply(XMPPConnection connection, Message original, Message reply)
public static void reply(Connection connection, Message original, Message reply)
throws XMPPException {
MultipleRecipientInfo info = getMultipleRecipientInfo(original);
if (info == null) {
@ -201,7 +201,7 @@ public class MultipleRecipientManager {
return extension == null ? null : new MultipleRecipientInfo(extension);
}
private static void sendToIndividualRecipients(XMPPConnection connection, Packet packet,
private static void sendToIndividualRecipients(Connection connection, Packet packet,
List to, List cc, List bcc) {
if (to != null) {
for (Iterator it = to.iterator(); it.hasNext();) {
@ -226,7 +226,7 @@ public class MultipleRecipientManager {
}
}
private static void sendThroughService(XMPPConnection connection, Packet packet, List to,
private static void sendThroughService(Connection connection, Packet packet, List to,
List cc, List bcc, String replyTo, String replyRoom, boolean noReply,
String serviceAddress) {
// Create multiple recipient extension
@ -280,7 +280,7 @@ public class MultipleRecipientManager {
* queried.
* @return the address of the multiple recipients service or <tt>null</tt> if none was found.
*/
private static String getMultipleRecipienServiceAddress(XMPPConnection connection) {
private static String getMultipleRecipienServiceAddress(Connection connection) {
String serviceName = connection.getServiceName();
String serviceAddress = (String) services.get(serviceName);
if (serviceAddress == null) {

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.IQ;
@ -57,11 +57,11 @@ public class OfflineMessageManager {
private final static String namespace = "http://jabber.org/protocol/offline";
private XMPPConnection connection;
private Connection connection;
private PacketFilter packetFilter;
public OfflineMessageManager(XMPPConnection connection) {
public OfflineMessageManager(Connection connection) {
this.connection = connection;
packetFilter =
new AndFilter(new PacketExtensionFilter("offline", namespace),

View File

@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
@ -64,7 +64,7 @@ public class PEPManager {
private List<PEPListener> pepListeners = new ArrayList<PEPListener>();
private XMPPConnection connection;
private Connection connection;
private PacketFilter packetFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event");
private PacketListener packetListener;
@ -72,9 +72,9 @@ public class PEPManager {
/**
* Creates a new PEP exchange manager.
*
* @param connection an XMPPConnection.
* @param connection a Connection which is used to send and receive messages.
*/
public PEPManager(XMPPConnection connection) {
public PEPManager(Connection connection) {
this.connection = connection;
init();
}

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -118,7 +118,7 @@ public class PrivateDataManager {
}
private XMPPConnection connection;
private Connection connection;
/**
* The user to get and set private data for. In most cases, this value should
@ -135,7 +135,7 @@ public class PrivateDataManager {
* @param connection an XMPP connection which must have already undergone a
* successful login.
*/
public PrivateDataManager(XMPPConnection connection) {
public PrivateDataManager(Connection connection) {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must be logged in to XMPP server.");
}
@ -154,7 +154,7 @@ public class PrivateDataManager {
* successful login.
* @param user the XMPP address of the user to get and set private data for.
*/
public PrivateDataManager(XMPPConnection connection, String user) {
public PrivateDataManager(Connection connection, String user) {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must be logged in to XMPP server.");
}

View File

@ -28,7 +28,7 @@ import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
@ -48,7 +48,7 @@ public class RosterExchangeManager {
private List<RosterExchangeListener> rosterExchangeListeners = new ArrayList<RosterExchangeListener>();
private XMPPConnection con;
private Connection con;
private PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:roster");
private PacketListener packetListener;
@ -56,9 +56,9 @@ public class RosterExchangeManager {
/**
* Creates a new roster exchange manager.
*
* @param con an XMPPConnection.
* @param con a Connection which is used to send and receive messages.
*/
public RosterExchangeManager(XMPPConnection con) {
public RosterExchangeManager(Connection con) {
this.con = con;
init();
}

View File

@ -50,10 +50,10 @@ public class ServiceDiscoveryManager {
private static String identityName = "Smack";
private static String identityType = "pc";
private static Map<XMPPConnection, ServiceDiscoveryManager> instances =
new ConcurrentHashMap<XMPPConnection, ServiceDiscoveryManager>();
private static Map<Connection, ServiceDiscoveryManager> instances =
new ConcurrentHashMap<Connection, ServiceDiscoveryManager>();
private XMPPConnection connection;
private Connection connection;
private final List<String> features = new ArrayList<String>();
private DataForm extendedInfo = null;
private Map<String, NodeInformationProvider> nodeInformationProviders =
@ -61,32 +61,32 @@ public class ServiceDiscoveryManager {
// Create a new ServiceDiscoveryManager on every established connection
static {
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
new ServiceDiscoveryManager(connection);
}
});
}
/**
* Creates a new ServiceDiscoveryManager for a given XMPPConnection. This means that the
* Creates a new ServiceDiscoveryManager for a given Connection. This means that the
* service manager will respond to any service discovery request that the connection may
* receive.
*
* @param connection the connection to which a ServiceDiscoveryManager is going to be created.
*/
public ServiceDiscoveryManager(XMPPConnection connection) {
public ServiceDiscoveryManager(Connection connection) {
this.connection = connection;
init();
}
/**
* Returns the ServiceDiscoveryManager instance associated with a given XMPPConnection.
* Returns the ServiceDiscoveryManager instance associated with a given Connection.
*
* @param connection the connection used to look for the proper ServiceDiscoveryManager.
* @return the ServiceDiscoveryManager associated with a given XMPPConnection.
* @return the ServiceDiscoveryManager associated with a given Connection.
*/
public static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection) {
public static ServiceDiscoveryManager getInstanceFor(Connection connection) {
return instances.get(connection);
}

View File

@ -1,6 +1,6 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
@ -27,7 +27,7 @@ public class SharedGroupManager {
* @param connection connection to use to get the user's shared groups.
* @return collection with the shared groups' name of the logged user.
*/
public static List getSharedGroups(XMPPConnection connection) throws XMPPException {
public static List getSharedGroups(Connection connection) throws XMPPException {
// Discover the shared groups of the logged user
SharedGroupsInfo info = new SharedGroupsInfo();
info.setType(IQ.Type.GET);

View File

@ -21,7 +21,7 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.packet.DiscoverInfo;
@ -43,8 +43,8 @@ public class XHTMLManager {
// Enable the XHTML support on every established connection
// The ServiceDiscoveryManager class should have been already initialized
static {
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
XHTMLManager.setServiceEnabled(connection, true);
}
});
@ -101,7 +101,7 @@ public class XHTMLManager {
* @param connection the connection where the service will be enabled or disabled
* @param enabled indicates if the service will be enabled or disabled
*/
public synchronized static void setServiceEnabled(XMPPConnection connection, boolean enabled) {
public synchronized static void setServiceEnabled(Connection connection, boolean enabled) {
if (isServiceEnabled(connection) == enabled)
return;
@ -119,7 +119,7 @@ public class XHTMLManager {
* @param connection the connection to look for XHTML support
* @return a boolean indicating if the XHTML support is enabled for the given connection
*/
public static boolean isServiceEnabled(XMPPConnection connection) {
public static boolean isServiceEnabled(Connection connection) {
return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(namespace);
}
@ -130,7 +130,7 @@ public class XHTMLManager {
* @param userID the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com
* @return a boolean indicating whether the specified user handles XHTML messages
*/
public static boolean isServiceEnabled(XMPPConnection connection, String userID) {
public static boolean isServiceEnabled(Connection connection, String userID) {
try {
DiscoverInfo result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(userID);

View File

@ -19,7 +19,7 @@
package org.jivesoftware.smackx.bookmark;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.PrivateDataManager;
@ -36,7 +36,7 @@ import java.util.*;
* @author Alexander Wenckus
*/
public class BookmarkManager {
private static final Map<XMPPConnection, BookmarkManager> bookmarkManagerMap = new HashMap<XMPPConnection, BookmarkManager>();
private static final Map<Connection, BookmarkManager> bookmarkManagerMap = new HashMap<Connection, BookmarkManager>();
static {
PrivateDataManager.addPrivateDataProvider("storage", "storage:bookmarks",
new Bookmarks.Provider());
@ -50,7 +50,7 @@ public class BookmarkManager {
* exist it is created.
* @throws XMPPException Thrown if the connection is null or has not yet been authenticated.
*/
public synchronized static BookmarkManager getBookmarkManager(XMPPConnection connection)
public synchronized static BookmarkManager getBookmarkManager(Connection connection)
throws XMPPException
{
BookmarkManager manager = (BookmarkManager) bookmarkManagerMap.get(connection);
@ -72,7 +72,7 @@ public class BookmarkManager {
* @param connection the connection for persisting and retrieving bookmarks.
* @throws XMPPException thrown when the connection is null or has not been authenticated.
*/
private BookmarkManager(XMPPConnection connection) throws XMPPException {
private BookmarkManager(Connection connection) throws XMPPException {
if(connection == null || !connection.isAuthenticated()) {
throw new XMPPException("Invalid connection.");
}

View File

@ -35,7 +35,7 @@ import java.util.List;
* See the following code sample for saving Bookmarks:
* <p/>
* <pre>
* XMPPConnection con = new XMPPConnection("jabber.org");
* Connection con = new XMPPConnection("jabber.org");
* con.login("john", "doe");
* Bookmarks bookmarks = new Bookmarks();
* <p/>

View File

@ -47,8 +47,8 @@ import java.util.concurrent.ConcurrentHashMap;
* An AdHocCommandManager is responsible for keeping the list of available
* commands offered by a service and for processing commands requests.
*
* Pass in an XMPPConnection isntance to
* {@link #getAddHocCommandsManager(org.jivesoftware.smack.XMPPConnection)} in order to
* Pass in a Connection instance to
* {@link #getAddHocCommandsManager(org.jivesoftware.smack.Connection)} in order to
* get an instance of this class.
*
* @author Gabriel Guardincerri
@ -65,11 +65,11 @@ public class AdHocCommandManager {
private static final int SESSION_TIMEOUT = 2 * 60;
/**
* Map a XMPPConnection with it AdHocCommandManager. This map have a key-value
* Map a Connection with it AdHocCommandManager. This map have a key-value
* pair for every active connection.
*/
private static Map<XMPPConnection, AdHocCommandManager> instances =
new ConcurrentHashMap<XMPPConnection, AdHocCommandManager>();
private static Map<Connection, AdHocCommandManager> instances =
new ConcurrentHashMap<Connection, AdHocCommandManager>();
/**
* Register the listener for all the connection creations. When a new
@ -77,8 +77,8 @@ public class AdHocCommandManager {
* related to that connection.
*/
static {
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
new AdHocCommandManager(connection);
}
});
@ -91,7 +91,7 @@ public class AdHocCommandManager {
* @param connection the XMPP connection.
* @return the AdHocCommandManager associated with the connection.
*/
public static AdHocCommandManager getAddHocCommandsManager(XMPPConnection connection) {
public static AdHocCommandManager getAddHocCommandsManager(Connection connection) {
return instances.get(connection);
}
@ -101,9 +101,9 @@ public class AdHocCommandManager {
private Thread sessionsSweeper;
/**
* The XMPPConnection that this instances of AdHocCommandManager manages
* The Connection that this instances of AdHocCommandManager manages
*/
private XMPPConnection connection;
private Connection connection;
/**
* Map a command node with its AdHocCommandInfo. Note: Key=command node,
@ -120,7 +120,7 @@ public class AdHocCommandManager {
*/
private Map<String, LocalCommand> executingCommands = new ConcurrentHashMap<String, LocalCommand>();
private AdHocCommandManager(XMPPConnection connection) {
private AdHocCommandManager(Connection connection) {
super();
this.connection = connection;
init();

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.commands;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -49,7 +49,7 @@ public class RemoteCommand extends AdHocCommand {
/**
* The connection that is used to execute this command
*/
private XMPPConnection connection;
private Connection connection;
/**
* The full JID of the command host
@ -77,7 +77,7 @@ public class RemoteCommand extends AdHocCommand {
* @param node the identifier of the command.
* @param jid the JID of the host.
*/
protected RemoteCommand(XMPPConnection connection, String node, String jid) {
protected RemoteCommand(Connection connection, String node, String jid) {
super();
this.connection = connection;
this.jid = jid;

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.debugger;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
@ -112,7 +112,7 @@ public class EnhancedDebugger implements SmackDebugger {
private JFormattedTextField userField = null;
private JFormattedTextField statusField = null;
private XMPPConnection connection = null;
private Connection connection = null;
private PacketListener packetReaderListener = null;
private PacketListener packetWriterListener = null;
@ -140,7 +140,7 @@ public class EnhancedDebugger implements SmackDebugger {
JTabbedPane tabbedPane;
public EnhancedDebugger(XMPPConnection connection, Writer writer, Reader reader) {
public EnhancedDebugger(Connection connection, Writer writer, Reader reader) {
this.connection = connection;
this.writer = writer;
this.reader = reader;
@ -919,7 +919,7 @@ public class EnhancedDebugger implements SmackDebugger {
void cancel() {
connection.removeConnectionListener(connListener);
connection.removePacketListener(packetReaderListener);
connection.removePacketWriterListener(packetWriterListener);
connection.removePacketSendingListener(packetWriterListener);
((ObservableReader) reader).removeReaderListener(readerListener);
((ObservableWriter) writer).removeWriterListener(writerListener);
messagesTable = null;

View File

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
@ -44,11 +44,11 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
private StreamNegotiator primaryNegotiator;
private StreamNegotiator secondaryNegotiator;
private XMPPConnection connection;
private Connection connection;
private PacketFilter primaryFilter;
private PacketFilter secondaryFilter;
public FaultTolerantNegotiator(XMPPConnection connection, StreamNegotiator primary,
public FaultTolerantNegotiator(Connection connection, StreamNegotiator primary,
StreamNegotiator secondary) {
this.primaryNegotiator = primary;
this.secondaryNegotiator = secondary;
@ -68,7 +68,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
"stream method.");
}
final Packet initiateIncomingStream(XMPPConnection connection, StreamInitiation initiation) {
final Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) {
throw new UnsupportedOperationException("Initiation handled by createIncomingStream " +
"method");
}

View File

@ -20,7 +20,7 @@
package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.IQTypeFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
@ -50,15 +50,15 @@ public class FileTransferManager {
private List<FileTransferListener> listeners;
private XMPPConnection connection;
private Connection connection;
/**
* Creates a file transfer manager to initiate and receive file transfers.
*
* @param connection
* The XMPPConnection that the file transfers will use.
* The Connection that the file transfers will use.
*/
public FileTransferManager(XMPPConnection connection) {
public FileTransferManager(Connection connection) {
this.connection = connection;
this.fileTransferNegotiator = FileTransferNegotiator
.getInstanceFor(connection);

View File

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -65,8 +65,8 @@ public class FileTransferNegotiator {
private static final String[] PROTOCOLS = {BYTE_STREAM, INBAND_BYTE_STREAM};
private static final Map<XMPPConnection, FileTransferNegotiator> transferObject =
new ConcurrentHashMap<XMPPConnection, FileTransferNegotiator>();
private static final Map<Connection, FileTransferNegotiator> transferObject =
new ConcurrentHashMap<Connection, FileTransferNegotiator>();
private static final String STREAM_INIT_PREFIX = "jsi_";
@ -90,7 +90,7 @@ public class FileTransferNegotiator {
* @return The IMFileTransferManager
*/
public static FileTransferNegotiator getInstanceFor(
final XMPPConnection connection) {
final Connection connection) {
if (connection == null) {
throw new IllegalArgumentException("Connection cannot be null");
}
@ -117,7 +117,7 @@ public class FileTransferNegotiator {
* @param connection The connection on which to enable or disable the services.
* @param isEnabled True to enable, false to disable.
*/
public static void setServiceEnabled(final XMPPConnection connection,
public static void setServiceEnabled(final Connection connection,
final boolean isEnabled) {
ServiceDiscoveryManager manager = ServiceDiscoveryManager
.getInstanceFor(connection);
@ -138,7 +138,7 @@ public class FileTransferNegotiator {
* @param connection The connection to check
* @return True if all related services are enabled, false if they are not.
*/
public static boolean isServiceEnabled(final XMPPConnection connection) {
public static boolean isServiceEnabled(final Connection connection) {
for (String ns : NAMESPACE) {
if (!ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(ns))
return false;
@ -181,13 +181,13 @@ public class FileTransferNegotiator {
// non-static
private final XMPPConnection connection;
private final Connection connection;
private final Socks5TransferNegotiatorManager byteStreamTransferManager;
private final StreamNegotiator inbandTransferManager;
private FileTransferNegotiator(final XMPPConnection connection) {
private FileTransferNegotiator(final Connection connection) {
configureConnection(connection);
this.connection = connection;
@ -195,7 +195,7 @@ public class FileTransferNegotiator {
inbandTransferManager = new IBBTransferNegotiator(connection);
}
private void configureConnection(final XMPPConnection connection) {
private void configureConnection(final Connection connection) {
connection.addConnectionListener(new ConnectionListener() {
public void connectionClosed() {
cleanup(connection);
@ -219,7 +219,7 @@ public class FileTransferNegotiator {
});
}
private void cleanup(final XMPPConnection connection) {
private void cleanup(final Connection connection) {
if (transferObject.remove(connection) != null) {
byteStreamTransferManager.cleanup();
inbandTransferManager.cleanup();

View File

@ -49,14 +49,14 @@ public class IBBTransferNegotiator extends StreamNegotiator {
public static final int DEFAULT_BLOCK_SIZE = 4096;
private XMPPConnection connection;
private Connection connection;
/**
* The default constructor for the In-Band Bystream Negotiator.
*
* @param connection The connection which this negotiator works on.
*/
protected IBBTransferNegotiator(XMPPConnection connection) {
protected IBBTransferNegotiator(Connection connection) {
this.connection = connection;
}

View File

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
@ -79,12 +79,12 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
public static boolean isAllowLocalProxyHost = true;
private final XMPPConnection connection;
private final Connection connection;
private Socks5TransferNegotiatorManager transferNegotiatorManager;
public Socks5TransferNegotiator(Socks5TransferNegotiatorManager transferNegotiatorManager,
final XMPPConnection connection)
final Connection connection)
{
this.connection = connection;
this.transferNegotiatorManager = transferNegotiatorManager;

View File

@ -22,7 +22,7 @@ import org.jivesoftware.smack.util.Cache;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
@ -54,13 +54,13 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
private final Cache<String, Integer> addressBlacklist
= new Cache<String, Integer>(100, BLACKLIST_LIFETIME);
private XMPPConnection connection;
private Connection connection;
private List<String> proxies;
private List<Bytestream.StreamHost> streamHosts;
public Socks5TransferNegotiatorManager(XMPPConnection connection) {
public Socks5TransferNegotiatorManager(Connection connection) {
this.connection = connection;
}

View File

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
@ -81,7 +81,7 @@ public abstract class StreamNegotiator {
return iq;
}
Packet initiateIncomingStream(XMPPConnection connection, StreamInitiation initiation) throws XMPPException {
Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException {
StreamInitiation response = createInitiationAccept(initiation,
getNamespaces());

View File

@ -26,7 +26,7 @@ import java.util.LinkedList;
/**
* A variant of the {@link org.jivesoftware.smack.PacketCollector} class
* that does not force attachment to an <code>XMPPConnection</code>
* that does not force attachment to a <code>Connection</code>
* on creation and no filter is required. Used to collect message
* packets targeted to a group chat room.
*

View File

@ -25,9 +25,9 @@ import org.jivesoftware.smackx.packet.DiscoverItems;
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
* directory . The information that may be discovered is the XMPP address of the room and the room
* name. The address of the room may be used for obtaining more detailed information
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.XMPPConnection, String)}
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.Connection, String)}
* or could be used for joining the room
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.XMPPConnection, String)}
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.Connection, String)}
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
*
* @author Gaston Dombiak

View File

@ -20,7 +20,7 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.Message;
/**
@ -36,14 +36,14 @@ public interface InvitationListener {
* If the room is password-protected, the invitee will receive a password to use to join
* the room. If the room is members-only, the the invitee may be added to the member list.
*
* @param conn the XMPPConnection that received the invitation.
* @param conn the Connection that received the invitation.
* @param room the room that invitation refers to.
* @param inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
* @param reason the reason why the inviter sent the invitation.
* @param password the password to use when joining the room.
* @param message the message used by the inviter to send the invitation.
*/
public abstract void invitationReceived(XMPPConnection conn, String room, String inviter, String reason,
public abstract void invitationReceived(Connection conn, String room, String inviter, String reason,
String password, Message message);
}

View File

@ -40,7 +40,7 @@ import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
@ -79,10 +79,10 @@ public class MultiUserChat {
private final static String discoNamespace = "http://jabber.org/protocol/muc";
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
private static Map<XMPPConnection, List<String>> joinedRooms =
new WeakHashMap<XMPPConnection, List<String>>();
private static Map<Connection, List<String>> joinedRooms =
new WeakHashMap<Connection, List<String>>();
private XMPPConnection connection;
private Connection connection;
private String room;
private String subject;
private String nickname = null;
@ -106,8 +106,8 @@ public class MultiUserChat {
private List<PacketListener> connectionListeners = new ArrayList<PacketListener>();
static {
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(final XMPPConnection connection) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(final Connection connection) {
// Set on every established connection that this client supports the Multi-User
// Chat protocol. This information will be used when another client tries to
// discover whether this client supports MUC or not.
@ -153,7 +153,7 @@ public class MultiUserChat {
* "service" is the hostname at which the multi-user chat
* service is running. Make sure to provide a valid JID.
*/
public MultiUserChat(XMPPConnection connection, String room) {
public MultiUserChat(Connection connection, String room) {
this.connection = connection;
this.room = room.toLowerCase();
init();
@ -166,7 +166,7 @@ public class MultiUserChat {
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return a boolean indicating whether the specified user supports the MUC protocol.
*/
public static boolean isServiceEnabled(XMPPConnection connection, String user) {
public static boolean isServiceEnabled(Connection connection, String user) {
try {
DiscoverInfo result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(user);
@ -186,7 +186,7 @@ public class MultiUserChat {
* @param connection the connection used to join the rooms.
* @return an Iterator on the rooms where the user has joined using a given connection.
*/
private static Iterator<String> getJoinedRooms(XMPPConnection connection) {
private static Iterator<String> getJoinedRooms(Connection connection) {
List<String> rooms = joinedRooms.get(connection);
if (rooms != null) {
return rooms.iterator();
@ -203,7 +203,7 @@ public class MultiUserChat {
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(XMPPConnection connection, String user) {
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
@ -232,7 +232,7 @@ public class MultiUserChat {
* @return the discovered information of a given room without actually having to join the room.
* @throws XMPPException if an error occured while trying to discover information of a room.
*/
public static RoomInfo getRoomInfo(XMPPConnection connection, String room)
public static RoomInfo getRoomInfo(Connection connection, String room)
throws XMPPException {
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(room);
return new RoomInfo(info);
@ -245,7 +245,7 @@ public class MultiUserChat {
* @return a collection with the XMPP addresses of the Multi-User Chat services.
* @throws XMPPException if an error occured while trying to discover MUC services.
*/
public static Collection<String> getServiceNames(XMPPConnection connection) throws XMPPException {
public static Collection<String> getServiceNames(Connection connection) throws XMPPException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
@ -275,7 +275,7 @@ public class MultiUserChat {
* @return a collection of HostedRooms.
* @throws XMPPException if an error occured while trying to discover the information.
*/
public static Collection<HostedRoom> getHostedRooms(XMPPConnection connection, String serviceName)
public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName)
throws XMPPException {
List<HostedRoom> answer = new ArrayList<HostedRoom>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
@ -768,7 +768,7 @@ public class MultiUserChat {
* @param inviter the inviter of the declined invitation.
* @param reason the reason why the invitee is declining the invitation.
*/
public static void decline(XMPPConnection conn, String room, String inviter, String reason) {
public static void decline(Connection conn, String room, String inviter, String reason) {
Message message = new Message(room);
// Create the MUCUser packet that will include the rejection
@ -790,7 +790,7 @@ public class MultiUserChat {
* @param conn the connection where the listener will be applied.
* @param listener an invitation listener.
*/
public static void addInvitationListener(XMPPConnection conn, InvitationListener listener) {
public static void addInvitationListener(Connection conn, InvitationListener listener) {
InvitationsMonitor.getInvitationsMonitor(conn).addInvitationListener(listener);
}
@ -801,7 +801,7 @@ public class MultiUserChat {
* @param conn the connection where the listener was applied.
* @param listener an invitation listener.
*/
public static void removeInvitationListener(XMPPConnection conn, InvitationListener listener) {
public static void removeInvitationListener(Connection conn, InvitationListener listener) {
InvitationsMonitor.getInvitationsMonitor(conn).removeInvitationListener(listener);
}
@ -1901,7 +1901,7 @@ public class MultiUserChat {
* group chat. Only "group chat" messages addressed to this group chat will
* be delivered to the listener. If you wish to listen for other packets
* that may be associated with this group chat, you should register a
* PacketListener directly with the XMPPConnection with the appropriate
* PacketListener directly with the Connection with the appropriate
* PacketListener.
*
* @param listener a packet listener.
@ -2555,12 +2555,12 @@ public class MultiUserChat {
private static class InvitationsMonitor implements ConnectionListener {
// We use a WeakHashMap so that the GC can collect the monitor when the
// connection is no longer referenced by any object.
private final static Map<XMPPConnection, WeakReference<InvitationsMonitor>> monitors =
new WeakHashMap<XMPPConnection, WeakReference<InvitationsMonitor>>();
private final static Map<Connection, WeakReference<InvitationsMonitor>> monitors =
new WeakHashMap<Connection, WeakReference<InvitationsMonitor>>();
private final List<InvitationListener> invitationsListeners =
new ArrayList<InvitationListener>();
private XMPPConnection connection;
private Connection connection;
private PacketFilter invitationFilter;
private PacketListener invitationPacketListener;
@ -2570,7 +2570,7 @@ public class MultiUserChat {
* @param conn the connection to monitor for room invitations.
* @return a new or existing InvitationsMonitor for a given connection.
*/
public static InvitationsMonitor getInvitationsMonitor(XMPPConnection conn) {
public static InvitationsMonitor getInvitationsMonitor(Connection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn)) {
// We need to use a WeakReference because the monitor references the
@ -2589,7 +2589,7 @@ public class MultiUserChat {
*
* @param connection the connection to monitor for possible room invitations
*/
private InvitationsMonitor(XMPPConnection connection) {
private InvitationsMonitor(Connection connection) {
this.connection = connection;
}

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;
@ -34,9 +34,9 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* A <code>RoomListenerMultiplexor</code> multiplexes incoming packets on
* an <code>XMPPConnection</code> using a single listener/filter pair.
* a <code>Connection</code> using a single listener/filter pair.
* A single <code>RoomListenerMultiplexor</code> is created for each
* {@link org.jivesoftware.smack.XMPPConnection} that has joined MUC rooms
* {@link org.jivesoftware.smack.Connection} that has joined MUC rooms
* within its session.
*
* @author Larry Kirschner
@ -45,10 +45,10 @@ class RoomListenerMultiplexor implements ConnectionListener {
// We use a WeakHashMap so that the GC can collect the monitor when the
// connection is no longer referenced by any object.
private static final Map<XMPPConnection, WeakReference<RoomListenerMultiplexor>> monitors =
new WeakHashMap<XMPPConnection, WeakReference<RoomListenerMultiplexor>>();
private static final Map<Connection, WeakReference<RoomListenerMultiplexor>> monitors =
new WeakHashMap<Connection, WeakReference<RoomListenerMultiplexor>>();
private XMPPConnection connection;
private Connection connection;
private RoomMultiplexFilter filter;
private RoomMultiplexListener listener;
@ -58,7 +58,7 @@ class RoomListenerMultiplexor implements ConnectionListener {
* @param conn the connection to monitor for room invitations.
* @return a new or existing RoomListenerMultiplexor for a given connection.
*/
public static RoomListenerMultiplexor getRoomMultiplexor(XMPPConnection conn) {
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn)) {
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
@ -78,9 +78,9 @@ class RoomListenerMultiplexor implements ConnectionListener {
/**
* All access should be through
* the static method {@link #getRoomMultiplexor(XMPPConnection)}.
* the static method {@link #getRoomMultiplexor(Connection)}.
*/
private RoomListenerMultiplexor(XMPPConnection connection, RoomMultiplexFilter filter,
private RoomListenerMultiplexor(Connection connection, RoomMultiplexFilter filter,
RoomMultiplexListener listener) {
if (connection == null) {
throw new IllegalArgumentException("Connection is null");
@ -146,11 +146,11 @@ class RoomListenerMultiplexor implements ConnectionListener {
}
/**
* The single <code>XMPPConnection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
* for all muc chat rooms on an <code>XMPPConnection</code>.
* The single <code>Connection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
* for all muc chat rooms on an <code>Connection</code>.
* Each time a muc chat room is added to/removed from an
* <code>XMPPConnection</code> the address for that chat room
* is added to/removed from that <code>XMPPConnection</code>'s
* <code>Connection</code> the address for that chat room
* is added to/removed from that <code>Connection</code>'s
* <code>RoomMultiplexFilter</code>.
*/
private static class RoomMultiplexFilter implements PacketFilter {
@ -181,12 +181,12 @@ class RoomListenerMultiplexor implements ConnectionListener {
}
/**
* The single <code>XMPPConnection</code>-level <code>PacketListener</code>
* The single <code>Connection</code>-level <code>PacketListener</code>
* used by a {@link RoomListenerMultiplexor}
* for all muc chat rooms on an <code>XMPPConnection</code>.
* for all muc chat rooms on an <code>Connection</code>.
* Each time a muc chat room is added to/removed from an
* <code>XMPPConnection</code> the address and listener for that chat room
* are added to/removed from that <code>XMPPConnection</code>'s
* <code>Connection</code> the address and listener for that chat room
* are added to/removed from that <code>Connection</code>'s
* <code>RoomMultiplexListener</code>.
*
* @author Larry Kirschner

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -127,14 +127,14 @@ public class LastActivity extends IQ {
/**
* Retrieve the last activity of a particular jid.
* @param con the current XMPPConnection.
* @param con the current Connection.
* @param jid the JID of the user.
* @return the LastActivity packet of the jid.
* @throws XMPPException thrown if a server error has occured.
* @deprecated This method only retreives the lapsed time since the last logout of a particular jid.
* Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(XMPPConnection, String) getLastActivity}
* Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity}
*/
public static LastActivity getLastActivity(XMPPConnection con, String jid) throws XMPPException {
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
LastActivity activity = new LastActivity();
jid = StringUtils.parseBareAddress(jid);
activity.setTo(jid);

View File

@ -64,7 +64,6 @@ public class Nick implements PacketExtension {
*
* @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
*/
@Override
public String getElementName() {
return ELEMENT_NAME;
}
@ -74,7 +73,6 @@ public class Nick implements PacketExtension {
*
* @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
*/
@Override
public String getNamespace() {
return NAMESPACE;
}
@ -84,7 +82,6 @@ public class Nick implements PacketExtension {
*
* @see org.jivesoftware.smack.packet.PacketExtension#toXML()
*/
@Override
public String toXML() {
final StringBuilder buf = new StringBuilder();

View File

@ -15,7 +15,7 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
@ -32,7 +32,7 @@ final public class SyncPacketSend
private SyncPacketSend()
{ }
static public Packet getReply(XMPPConnection connection, Packet packet, long timeout)
static public Packet getReply(Connection connection, Packet packet, long timeout)
throws XMPPException
{
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
@ -55,7 +55,7 @@ final public class SyncPacketSend
return result;
}
static public Packet getReply(XMPPConnection connection, Packet packet)
static public Packet getReply(Connection connection, Packet packet)
throws XMPPException
{
return getReply(connection, packet, SmackConfiguration.getPacketReplyTimeout());

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -493,10 +493,10 @@ public class VCard extends IQ {
* <p/>
* NOTE: the method is asynchronous and does not wait for the returned value.
*
* @param connection the XMPPConnection to use.
* @param connection the Connection to use.
* @throws XMPPException thrown if there was an issue setting the VCard in the server.
*/
public void save(XMPPConnection connection) throws XMPPException {
public void save(Connection connection) throws XMPPException {
checkAuthenticated(connection, true);
setType(IQ.Type.SET);
@ -520,7 +520,7 @@ public class VCard extends IQ {
* Load VCard information for a connected user. Connection should be authenticated
* and not anonymous.
*/
public void load(XMPPConnection connection) throws XMPPException {
public void load(Connection connection) throws XMPPException {
checkAuthenticated(connection, true);
setFrom(connection.getUser());
@ -530,14 +530,14 @@ public class VCard extends IQ {
/**
* Load VCard information for a given user. Connection should be authenticated and not anonymous.
*/
public void load(XMPPConnection connection, String user) throws XMPPException {
public void load(Connection connection, String user) throws XMPPException {
checkAuthenticated(connection, false);
setTo(user);
doLoad(connection, user);
}
private void doLoad(XMPPConnection connection, String user) throws XMPPException {
private void doLoad(Connection connection, String user) throws XMPPException {
setType(Type.GET);
PacketCollector collector = connection.createPacketCollector(
new PacketIDFilter(getPacketID()));
@ -587,7 +587,7 @@ public class VCard extends IQ {
}
}
private void checkAuthenticated(XMPPConnection connection, boolean checkForAnonymous) {
private void checkAuthenticated(Connection connection, boolean checkForAnonymous) {
if (connection == null) {
throw new IllegalArgumentException("No connection was provided");
}

View File

@ -13,7 +13,7 @@
*/
package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.PacketExtension;
/**
@ -22,7 +22,7 @@ import org.jivesoftware.smack.packet.PacketExtension;
*
* Affiliations are retrieved from the {@link PubSubManager#getAffiliations()} method, which
* gets affiliations for the calling user, based on the identity that is associated with
* the {@link XMPPConnection}.
* the {@link Connection}.
*
* @author Robin Collier
*/

View File

@ -3,11 +3,11 @@
*/
package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
public class CollectionNode extends Node
{
CollectionNode(XMPPConnection connection, String nodeId)
CollectionNode(Connection connection, String nodeId)
{
super(connection, nodeId);
}

View File

@ -17,7 +17,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.packet.DiscoverItems;
@ -34,7 +34,7 @@ import org.jivesoftware.smackx.pubsub.packet.SyncPacketSend;
*/
public class LeafNode extends Node
{
LeafNode(XMPPConnection connection, String nodeName)
LeafNode(Connection connection, String nodeName)
{
super(connection, nodeName);
}

View File

@ -10,7 +10,7 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
@ -33,7 +33,7 @@ import org.jivesoftware.smackx.pubsub.util.NodeUtils;
abstract public class Node
{
protected XMPPConnection con;
protected Connection con;
protected String id;
protected String to;
@ -48,7 +48,7 @@ abstract public class Node
* @param connection The connection the node is associated with
* @param nodeName The node id
*/
Node(XMPPConnection connection, String nodeName)
Node(Connection connection, String nodeName)
{
con = connection;
id = nodeName;

View File

@ -17,7 +17,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
@ -43,7 +43,7 @@ import org.jivesoftware.smackx.pubsub.util.NodeUtils;
*/
final public class PubSubManager
{
private XMPPConnection con;
private Connection con;
private String to;
private Map<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
@ -52,7 +52,7 @@ final public class PubSubManager
*
* @param connection The XMPP connection
*/
public PubSubManager(XMPPConnection connection)
public PubSubManager(Connection connection)
{
con = connection;
}
@ -64,7 +64,7 @@ final public class PubSubManager
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
public PubSubManager(XMPPConnection connection, String toAddress)
public PubSubManager(Connection connection, String toAddress)
{
con = connection;
to = toAddress;
@ -300,25 +300,25 @@ final public class PubSubManager
return request;
}
static Packet sendPubsubPacket(XMPPConnection con, String to, Type type, PacketExtension ext)
static Packet sendPubsubPacket(Connection con, String to, Type type, PacketExtension ext)
throws XMPPException
{
return sendPubsubPacket(con, to, type, ext, null);
}
static Packet sendPubsubPacket(XMPPConnection con, String to, Type type, PacketExtension ext, PubSubNamespace ns)
static Packet sendPubsubPacket(Connection con, String to, Type type, PacketExtension ext, PubSubNamespace ns)
throws XMPPException
{
return SyncPacketSend.getReply(con, createPubsubPacket(to, type, ext, ns));
}
static Packet sendPubsubPacket(XMPPConnection con, String to, Type type, PubSub packet)
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet)
throws XMPPException
{
return sendPubsubPacket(con, to, type, packet, null);
}
static Packet sendPubsubPacket(XMPPConnection con, String to, Type type, PubSub packet, PubSubNamespace ns)
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet, PubSubNamespace ns)
throws XMPPException
{
return SyncPacketSend.getReply(con, packet);

View File

@ -15,7 +15,7 @@ package org.jivesoftware.smackx.pubsub.packet;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
@ -32,7 +32,7 @@ final public class SyncPacketSend
private SyncPacketSend()
{ }
static public Packet getReply(XMPPConnection connection, Packet packet, long timeout)
static public Packet getReply(Connection connection, Packet packet, long timeout)
throws XMPPException
{
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
@ -55,7 +55,7 @@ final public class SyncPacketSend
return result;
}
static public Packet getReply(XMPPConnection connection, Packet packet)
static public Packet getReply(Connection connection, Packet packet)
throws XMPPException
{
return getReply(connection, packet, SmackConfiguration.getPacketReplyTimeout());

View File

@ -18,7 +18,7 @@ package org.jivesoftware.smackx.search;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -59,13 +59,13 @@ public class UserSearch extends IQ {
/**
* Returns the form for all search fields supported by the search service.
*
* @param con the current XMPPConnection.
* @param con the current Connection.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return the search form received by the server.
* @throws org.jivesoftware.smack.XMPPException
* thrown if a server error has occurred.
*/
public Form getSearchForm(XMPPConnection con, String searchService) throws XMPPException {
public Form getSearchForm(Connection con, String searchService) throws XMPPException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.GET);
search.setTo(searchService);
@ -89,14 +89,14 @@ public class UserSearch extends IQ {
/**
* Sends the filled out answer form to be sent and queried by the search service.
*
* @param con the current XMPPConnection.
* @param con the current Connection.
* @param searchForm the <code>Form</code> to send for querying.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return ReportedData the data found from the query.
* @throws org.jivesoftware.smack.XMPPException
* thrown if a server error has occurred.
*/
public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, String searchService) throws XMPPException {
public ReportedData sendSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.SET);
search.setTo(searchService);
@ -124,14 +124,14 @@ public class UserSearch extends IQ {
/**
* Sends the filled out answer form to be sent and queried by the search service.
*
* @param con the current XMPPConnection.
* @param con the current Connection.
* @param searchForm the <code>Form</code> to send for querying.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return ReportedData the data found from the query.
* @throws org.jivesoftware.smack.XMPPException
* thrown if a server error has occurred.
*/
public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, String searchService) throws XMPPException {
public ReportedData sendSimpleSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
SimpleUserSearch search = new SimpleUserSearch();
search.setForm(searchForm);
search.setType(IQ.Type.SET);

View File

@ -16,7 +16,7 @@
package org.jivesoftware.smackx.search;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.ReportedData;
@ -35,7 +35,7 @@ import java.util.List;
* searching (DataForms or No DataForms), but allows the user to simply use the DataForm model for both
* types of support.
* <pre>
* XMPPConnection con = new XMPPConnection("jabber.org");
* Connection con = new XMPPConnection("jabber.org");
* con.login("john", "doe");
* UserSearchManager search = new UserSearchManager(con, "users.jabber.org");
* Form searchForm = search.getSearchForm();
@ -49,15 +49,15 @@ import java.util.List;
*/
public class UserSearchManager {
private XMPPConnection con;
private Connection con;
private UserSearch userSearch;
/**
* Creates a new UserSearchManager.
*
* @param con the XMPPConnection to use.
* @param con the Connection to use.
*/
public UserSearchManager(XMPPConnection con) {
public UserSearchManager(Connection con) {
this.con = con;
userSearch = new UserSearch();
}

View File

@ -23,7 +23,7 @@ import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -36,10 +36,10 @@ import java.util.Collection;
* @author Derek DeMoro
*/
public class Agent {
private XMPPConnection connection;
private Connection connection;
private String workgroupJID;
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, XMPPConnection connection) throws XMPPException {
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
AgentWorkgroups request = new AgentWorkgroups(agentJID);
request.setTo(serviceJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
@ -62,7 +62,7 @@ public class Agent {
/**
* Constructs an Agent.
*/
Agent(XMPPConnection connection, String workgroupJID) {
Agent(Connection connection, String workgroupJID) {
this.connection = connection;
this.workgroupJID = workgroupJID;
}

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smackx.workgroup.packet.AgentStatus;
import org.jivesoftware.smackx.workgroup.packet.AgentStatusRequest;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Packet;
@ -50,7 +50,7 @@ public class AgentRoster {
private static final int EVENT_AGENT_REMOVED = 1;
private static final int EVENT_PRESENCE_CHANGED = 2;
private XMPPConnection connection;
private Connection connection;
private String workgroupJID;
private List<String> entries;
private List<AgentRosterListener> listeners;
@ -64,7 +64,7 @@ public class AgentRoster {
*
* @param connection an XMPP connection.
*/
AgentRoster(XMPPConnection connection, String workgroupJID) {
AgentRoster(Connection connection, String workgroupJID) {
this.connection = connection;
this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();

View File

@ -53,7 +53,7 @@ import java.util.*;
*/
public class AgentSession {
private XMPPConnection connection;
private Connection connection;
private String workgroupJID;
@ -83,7 +83,7 @@ public class AgentSession {
* authentication.
* @param workgroupJID the fully qualified JID of the workgroup.
*/
public AgentSession(String workgroupJID, XMPPConnection connection) {
public AgentSession(String workgroupJID, Connection connection) {
// Login must have been done before passing in connection.
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must login to server before creating workgroup.");
@ -1112,12 +1112,12 @@ public class AgentSession {
/**
* Returns the generic metadata of the workgroup the agent belongs to.
*
* @param con the XMPPConnection to use.
* @param con the Connection to use.
* @param query an optional query object used to tell the server what metadata to retrieve. This can be null.
* @throws XMPPException if an error occurs while sending the request to the server.
* @return the settings for the workgroup.
*/
public GenericSettings getGenericSettings(XMPPConnection con, String query) throws XMPPException {
public GenericSettings getGenericSettings(Connection con, String query) throws XMPPException {
GenericSettings setting = new GenericSettings();
setting.setType(IQ.Type.GET);
setting.setTo(workgroupJID);
@ -1138,7 +1138,7 @@ public class AgentSession {
return response;
}
public boolean hasMonitorPrivileges(XMPPConnection con) throws XMPPException {
public boolean hasMonitorPrivileges(Connection con) throws XMPPException {
MonitorPacket request = new MonitorPacket();
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
@ -1160,7 +1160,7 @@ public class AgentSession {
}
public void makeRoomOwner(XMPPConnection con, String sessionID) throws XMPPException {
public void makeRoomOwner(Connection con, String sessionID) throws XMPPException {
MonitorPacket request = new MonitorPacket();
request.setType(IQ.Type.SET);
request.setTo(workgroupJID);

View File

@ -19,7 +19,7 @@
package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
@ -36,7 +36,7 @@ import java.util.Map;
*/
public class Offer {
private XMPPConnection connection;
private Connection connection;
private AgentSession session;
private String sessionID;
@ -64,7 +64,7 @@ public class Offer {
* @param content content of the offer. The content explains the reason for the offer
* (e.g. user request, transfer)
*/
Offer(XMPPConnection conn, AgentSession agentSession, String userID,
Offer(Connection conn, AgentSession agentSession, String userID,
String userJID, String workgroupName, Date expiresDate,
String sessionID, Map metaData, OfferContent content)
{

View File

@ -19,7 +19,7 @@
package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
@ -46,7 +46,7 @@ public class OfferConfirmation extends IQ {
}
public void notifyService(XMPPConnection con, String workgroup, String createdRoomName) {
public void notifyService(Connection con, String workgroup, String createdRoomName) {
NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName);
con.sendPacket(packet);
}

View File

@ -23,7 +23,7 @@ import org.jivesoftware.smackx.workgroup.packet.Transcript;
import org.jivesoftware.smackx.workgroup.packet.Transcripts;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
@ -35,9 +35,9 @@ import org.jivesoftware.smack.filter.PacketIDFilter;
* @author Gaston Dombiak
*/
public class TranscriptManager {
private XMPPConnection connection;
private Connection connection;
public TranscriptManager(XMPPConnection connection) {
public TranscriptManager(Connection connection) {
this.connection = connection;
}

View File

@ -22,7 +22,7 @@ package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@ -37,9 +37,9 @@ import org.jivesoftware.smackx.ReportedData;
* @author Gaston Dombiak
*/
public class TranscriptSearchManager {
private XMPPConnection connection;
private Connection connection;
public TranscriptSearchManager(XMPPConnection connection) {
public TranscriptSearchManager(Connection connection) {
this.connection = connection;
}

View File

@ -56,7 +56,7 @@ import java.util.Map;
public class Workgroup {
private String workgroupJID;
private XMPPConnection connection;
private Connection connection;
private boolean inQueue;
private List invitationListeners;
private List queueListeners;
@ -75,7 +75,7 @@ public class Workgroup {
* @param connection an XMPP connection which must have already undergone a
* successful login.
*/
public Workgroup(String workgroupJID, XMPPConnection connection) {
public Workgroup(String workgroupJID, Connection connection) {
// Login must have been done before passing in connection.
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must login to server before creating workgroup.");
@ -114,7 +114,7 @@ public class Workgroup {
*/
MultiUserChat.addInvitationListener(connection,
new org.jivesoftware.smackx.muc.InvitationListener() {
public void invitationReceived(XMPPConnection conn, String room, String inviter,
public void invitationReceived(Connection conn, String room, String inviter,
String reason, String password, Message message) {
inQueue = false;
queuePosition = -1;
@ -854,7 +854,7 @@ public class Workgroup {
/*
public static void main(String args[]) throws Exception {
XMPPConnection con = new XMPPConnection("anteros");
Connection con = new XMPPConnection("anteros");
con.connect();
con.loginAnonymously();

View File

@ -140,12 +140,12 @@ public class PacketReaderTest extends SmackTestCase {
}
};
// Keep number of current listeners
int listenersSize = getConnection(0).packetReader.listeners.size();
int listenersSize = getConnection(0).getPacketListeners().size();
// Add a new listener
getConnection(0).addPacketListener(listener, new MockPacketFilter(true));
// Check that the listener was added
assertEquals("Listener was not added", listenersSize + 1,
getConnection(0).packetReader.listeners.size());
getConnection(0).getPacketListeners().size());
Message msg = new Message(getConnection(0).getUser(), Message.Type.normal);
@ -155,7 +155,7 @@ public class PacketReaderTest extends SmackTestCase {
getConnection(0).removePacketListener(listener);
// Check that the number of listeners is correct (i.e. the listener was removed)
assertEquals("Listener was not removed", listenersSize,
getConnection(0).packetReader.listeners.size());
getConnection(0).getPacketListeners().size());
}
/**

Some files were not shown because too many files have changed in this diff Show More