?? x3795.htm
字號:
<HTML
><HEAD
><TITLE
>Resources and Priority</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Jabber Technology Basics"
HREF="c3612.htm"><LINK
REL="PREVIOUS"
TITLE="Jabber Identifiers"
HREF="x3625.htm"><LINK
REL="NEXT"
TITLE="XML Streams"
HREF="x3837.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x3625.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Jabber Technology Basics</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x3837.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-5-SECT-5.2"
>Resources and Priority</A
></H1
><P
>In the previous section, we saw how the <TT
CLASS="LITERAL"
>resource</TT
> is used to “qualify” certain queries to a servername, to hold information
such as version numbers, and to represent users in a conference room.
However, the resource is traditionally seen as a way of making a distinction
between simultaneous connections by a user to the same Jabber server.
For example, if you connect to a Jabber server using the same username and password on three different machines (or "resources"), the Jabber server will look at the resource part of the JID to determine which client to route messages to.</P
><P
>For the purpose of this example, let's say that the three resources are a workstation, laptop, and a PDA. Each client is connected to the same Jabber server, so the <TT
CLASS="LITERAL"
>resource</TT
> part of the JID can be used to distinguish between the three connections. They could also be used to differentiate between the three connections coming from the same client host.</P
><P
>The classic explanation serves us well here: In a work situation, I might
be connected to my Jabber server using a client on my workstation. I
might also be connected, with the same
<TT
CLASS="LITERAL"
>username</TT
>, to my Jabber server on my
laptop that's sitting next to my workstation. Furthermore, I might have
a handheld device that runs a small Jabber client, that I'm connected
with too.</P
><P
>On each client machine, I'm connecting using the same credentials (username
and password) to the same Jabber server. So the
<TT
CLASS="LITERAL"
>resource</TT
> part of a JID can
be used to distinguish between my three connections. The three 'resources'
are my workstation, laptop and handheld, in this example. In another example,
they might be used to differentiate between three different connections
coming from the same client host (say, my desktop).</P
><P
>The <TT
CLASS="LITERAL"
>resource</TT
> part of a JID allows a
user to be connected to Jabber (specifically the JSM, which manages
users and sees user sessions as separate entities) multiple times.</P
><P
>"But", I hear you say, "what happens when someone sends you a message?
To which client is the message sent?"</P
><P
>This is where the concept of connection <I
CLASS="EMPHASIS"
>priority</I
>
comes to our aid.
Each Jabber client connection can be given a priority.
When a user has more than one concurrent connection to a Jabber server,
the priority is used to determine to which connection any messages intended
for that user should be sent.
<A
NAME="MESSAGES"
HREF="#FTN.MESSAGES"
>[1]</A
>
The connection with the highest priority value is the connection to which
the messages are sent.
<A
NAME="AEN3813"
HREF="#FTN.AEN3813"
>[2]</A
></P
><P
><A
HREF="x3795.htm#JABTDG-CH-5-FIG-1"
>Figure 5-1</A
>
shows priority in action. In this example, Sabine's message is sent to the Jabber
client on the Desktop, as it has a higher priority. Note that with Jabber priority,
1 has a lower priority than, say, 5. The higher the number, the higher the priority.</P
><DIV
CLASS="FIGURE"
><A
NAME="JABTDG-CH-5-FIG-1"
></A
><P
><B
>Figure 5-1. Resources, Priority, and Message Delivery</B
></P
><PRE
CLASS="SCREEN"
> Sender Recipient
------ ---------
sabine@yak dj@yak
+---------------+
+--------+ | | +------------------+
| | | Jabber | | Client 1 |
| Client |---------| Server |---------| Resource: Laptop |
| | | | | Priority: 1 |
+--------+ | yak | +------------------+
| | dj@jak/Laptop
| |
Message ------------------+ | +------------------+
to dj@yak | | | | Client 2 |
| | |---------| Resource: Desktop|
| +---------------> | Priority: 2 |
| | +------------------+
+---------------+ dj@yak/Desktop </PRE
></DIV
><P
>If there is a priority tie, for example if I have connected to my Jabber
server with a client on my laptop (where I specified the resource “Laptop”)
and also with a client on my desktop (where I specified the resource
“Desktop”), and the settings in <I
CLASS="EMPHASIS"
>both</I
> clients have
their priorities set to the value
1, the <I
CLASS="EMPHASIS"
>most recent</I
> connection
to be made wins and receives the messages.</P
><P
>It is also possible to direct messages to a particular client. Taking
the example from
<A
HREF="x3795.htm#JABTDG-CH-5-FIG-1"
>Figure 5-1</A
>,
if <TT
CLASS="LITERAL"
>sabine@yak</TT
>
were to specify <TT
CLASS="LITERAL"
>dj@yak/Laptop</TT
> instead of <TT
CLASS="LITERAL"
>dj@yak</TT
> as the
recipient for a message, her message would
go to Client 1 (<TT
CLASS="LITERAL"
>Laptop</TT
>), not Client 2 (<TT
CLASS="LITERAL"
>Desktop</TT
>), despite Client 1's lower priority value.</P
><P
>Priorities are
specified when a user sends presence information. We will see this later in
<A
HREF="x4089.htm"
>the section called <I
>The Jabber Building Blocks</I
></A
>.
It
makes sense for the priority to be associated with a user's presence,
rather than a user's client connection. For example, if the priority was specified
at connection time, the user would have to disconnect and reconnect if
she wanted to change priority. As it stands, she just has to send presence
information containing a new priority value to change it.
<A
HREF="x3795.htm#JABTDG-CH-5-FIG-PRIORITY"
>Figure 5-2</A
> shows a WinJab client
popup window used to change presence information. The value of the
current priority can be changed.</P
><DIV
CLASS="FIGURE"
><A
NAME="JABTDG-CH-5-FIG-PRIORITY"
></A
><P
><B
>Figure 5-2. Changing presence and priority in the WinJab client</B
></P
><P
><IMG
SRC="CH-5-FIG-PRIORITY.jpg"></P
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.MESSAGES"
HREF="x3795.htm#MESSAGES"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>“Messages” is used in the generic sense; actually any packet destined to
the user is implied. See <A
HREF="x4089.htm"
>the section called <I
>The Jabber Building Blocks</I
></A
> in this
Chapter for information on the types of packets that are send and received.</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN3813"
HREF="x3795.htm#AEN3813"
>[2]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>Priority values must be a positive integer, and cannot be zero or less.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x3625.htm"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x3837.htm"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Jabber Identifiers</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c3612.htm"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>XML Streams</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -