[prev in list] [next in list] [prev in thread] [next in thread]
List: openjms-developer
Subject: RE: [openjms-developer] Priority Queing & Extending Queue to include Attributes
From: "Tim Anderson" <tma () netspace ! net ! au>
Date: 2003-12-23 13:33:27
[Download RAW message or body]
MessageTo clarify, you're trying to ensure that clients with a higher
priority receive messages
before those with a lower priority?
I suspect you could simulate this behaviour in your clients, by using
blocking receive() calls,
in conjunction with Thread.sleep().
High priority clients would specify a long receive timeout, and a short
sleep time,
while low priority clients would specify a short receive timeout and a long
sleep time -
this would ensure that high priority clients are more likely to receive
messages.
E.g:
public Message receive(QueueReceiver receiver, int clientPriority)
throws JMSException {
if (clientPriority > 10) {
clientPriority = 10;
}
long sleepTimeout = 1000 - (clientPriority * 100);
long recvTimeout = 1000 - sleepTimeout;
Message message = null;
while (message == null) {
message = receiver.receive(recvTimeout);
if (message == null) {
try {
Thread.currentThread().sleep(sleepTimeout);
} catch (InterruptedException ignore) {
}
}
return message;
}
For a high priority client (10), invoking the above with
Message message = receive(receiver, 10);
would wait at most 1 second for a message, and not sleep if no message
is received.
For a low priority client (1), invoking the above with
Message message = receive(receiver, 10);
would wait at most 100 milliseconds for a message, and sleep for 900ms if no
message
is received.
-----Original Message-----
From: openjms-developer-admin@lists.sourceforge.net
[mailto:openjms-developer-admin@lists.sourceforge.net]On Behalf Of Curtis
Paris
Sent: Tuesday, 23 December 2003 8:32 AM
To: openjms-developer@lists.sourceforge.net
Subject: [openjms-developer] Priority Queing & Extending Queue to include
Attributes
I currently have implemented priority based Queuing into the OpenJMS
system. But, I'm struggling with the best way to have a client define it's
priority. There is no obvious way in JMS, that I can see, to pass an
attribute for each Queue. I would rather not do it on a ClientID basis,
since it may be applicable that some clients need to have a higher priority
in one queue, and a lower priority in another (including in my environment).
As soon as I can get a best practice for specifying the client priority,
I'll be happy to send in my code to the OpenJMS project
To give you an idea of what the priority queuing does, here we go:
A client creates a queue connection, and specifies its priority (agian,
any ideas on best practices?). Priorities are defined as a byte.
QueueDestinationCache will look for people to handle the message by:
- Top to Bottom Priorioty
- Round Robin Servers for each priority (keeping track of the last
server # for each priority level).
Example, if I had five clients:
#1 - Priority of 200
#2 - Priority of 200
#3 - Priority of 100
#4 - Priority of 100
#5 - Priority of 50
a.. It will round robin and check to see if client #1 or #2 can select
the message and are ready for it (checking all highest priority servers
first)
b.. If not, it will round robin and check to see if Client #3 or #4 can
select the message and are ready for it.
c.. If not, it will round robin #5 and check to see if client #5 can
select the message and is ready for it.
d.. If not, queue the message for later delivery.
Clients can not change their priority unless the unregister and
reregister. (Although it would be simple enough to have registerConsumer()
handle this appropriately.
My only thought on how to do this would be to extend the selection
critereon. For example:
Currently: MyHeader > 5
Attributed: {Priority=5} MyHeader > 5
When the client is connected, it will parse out attributes in {}'s. It'll
then release the rest of it for the normal parser.
----------------------------------------------------------------------------
--
Curtis Paris
Software Engineer IV
Metro One Telecommunications, Inc.
11200 Murray Scholls Place
Beaverton, OR 97007 Phone: +1 (503) 643-9500
Fax: +1 (503) 643-9600
E-Mail: curtis.paris@metro1.com
Web: http://www.metro1.com/
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>To
clarify, you're trying </SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>to ensure that clients with a higher priority receive
messages </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>before
those with a lower priority?</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>I
suspect you could simulate this behaviour in your clients, by using
blocking receive() calls, </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>in
conjunction with </SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>Thread.sleep(). </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>High
priority clients would specify a long receive timeout, and a short sleep
time,</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>while
low priority clients would specify a short receive timeout and a long sleep time
-</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>this
would ensure that high priority clients are more likely to receive
messages.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>E.g:</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> public Message receive(QueueReceiver
receiver, int clientPriority) </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> throws
JMSException {</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> if (clientPriority
> 10) {</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>
clientPriority =
10;</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>
}</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>
long sleepTimeout = 1000 - (clientPriority * 100);</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> long recvTimeout =
1000 - sleepTimeout;</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> Message message =
null;</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> while (message == null)
{</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>
message = receiver.receive(recvTimeout);</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>
if (message == null) {</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> try \
{</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>
Thread.currentThread().sleep(sleepTimeout);</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> \
} catch (InterruptedException ignore) {</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> \
}</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003>
}</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> return
message;</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> }</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> </SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>For a
high priority client (10), invoking the above with</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> Message message =
receive(receiver, 10);</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>would
wait at most 1 second for a message, and not sleep if no
message</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>is
received.</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>For a
low priority client (1), invoking the above with
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003> Message message =
receive(receiver, 10);</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>would
wait at most 100 milliseconds for a message, and sleep for 900ms if no
message</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=570175612-23122003>is
received.</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN
class=570175612-23122003></SPAN></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; \
MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT \
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B>
openjms-developer-admin@lists.sourceforge.net
[mailto:openjms-developer-admin@lists.sourceforge.net]<B>On Behalf Of
</B>Curtis Paris<BR><B>Sent:</B> Tuesday, 23 December 2003 8:32
AM<BR><B>To:</B> openjms-developer@lists.sourceforge.net<BR><B>Subject:</B>
[openjms-developer] Priority Queing & Extending Queue to include
Attributes<BR><BR></FONT></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>I currently have
implemented priority based Queuing into the OpenJMS system. But, I'm
struggling with the best way to have a client define it's priority.
There is no obvious way in JMS, that I can see, to pass an attribute for each
Queue. I would rather not do it on a ClientID basis, since it may be
applicable that some clients need to have a higher priority in one queue, and
a lower priority in another (including in my environment).
<SPAN class=078561821-22122003><FONT face=Arial size=2>As soon as I can get a
best practice for specifying the client priority, I'll be happy to send in my
code to the OpenJMS project</FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>To give you an
idea of what the priority queuing does, here we go:</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>A client creates a
queue connection, and specifies its priority (agian, any ideas on best
practices?). </FONT></SPAN><SPAN class=078561821-22122003><FONT
face=Arial size=2>Priorities are defined as a byte.</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2>QueueDestinationCache will look for people to handle the message
by:</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003> <FONT face=Arial
size=2>- Top to Bottom Priorioty</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003>
<FONT face=Arial size=2>- Round Robin Servers for each priority (keeping track
of the last server # for each priority level).</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003></SPAN><SPAN
class=078561821-22122003><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>Example, if I had
five clients:</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003> #1 - Priority of 200</SPAN></DIV>
<DIV><SPAN class=078561821-22122003> #2 - Priority of 200</SPAN></DIV>
<DIV><SPAN class=078561821-22122003> #3 - Priority of 100</SPAN></DIV>
<DIV><SPAN class=078561821-22122003>
<DIV><SPAN class=078561821-22122003> #4 - Priority of 100</SPAN></DIV>
<DIV><SPAN class=078561821-22122003> #5 - Priority of 50</SPAN></DIV>
<UL>
<LI><SPAN class=078561821-22122003><FONT face=Arial size=2>It will round
robin and check to see if client #1 or #2 can select the message
and are ready for it (checking all highest priority servers
first)</FONT></SPAN>
<LI><SPAN class=078561821-22122003><FONT face=Arial size=2>If not, it will
round robin and check to see if Client #3 or #4 can select the message
and are ready for it.</FONT></SPAN>
<LI><SPAN class=078561821-22122003><FONT face=Arial size=2>If not, it will
round robin #5 and check to see if client #5 can select the message and is
ready for it.</FONT></SPAN>
<LI><SPAN class=078561821-22122003><FONT face=Arial size=2>If not, queue the
message for later delivery.</FONT></SPAN></LI></UL>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>Clients can not
change their priority unless the unregister and reregister. (Although it
would be simple enough to have registerConsumer() handle this
appropriately.</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003></SPAN><SPAN
class=078561821-22122003><FONT face=Arial size=2>My only thought on how to do
this would be to extend the selection critereon. For
example:</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2>Currently: MyHeader > 5</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>Attributed:
{Priority=5} MyHeader > 5</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial size=2>When the client is
connected, it will parse out attributes in {}'s. It'll then release the
rest of it for the normal parser.</FONT></SPAN></DIV>
<DIV><SPAN class=078561821-22122003><FONT face=Arial
size=2></FONT></SPAN> </DIV><FONT face=Arial size=2></FONT>
<DIV align=left><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial
color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><FONT
face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><BR></DIV>
<HR align=left width="100%" SIZE=1>
<TABLE
style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; FONT-SIZE: 10pt; \
BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: Arial" \
cellSpacing=0 cellPadding=5 width=450 border=0> <TBODY>
<TR vAlign=top bgColor=#e0e0e0>
<TD colSpan=2><FONT
style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; FONT-FAMILY: Arial">Curtis
Paris</FONT><BR>Software Engineer IV</TD>
<TD vAlign=center><IMG height=20
src="http://metrodex.metro1.com/images/metroone_logo_gray.gif"
width=148></TD></TR>
<TR vAlign=top bgColor=#f0f0f0>
<TD><NOBR>Metro One Telecommunications, Inc.<BR>11200 Murray Scholls
Place<BR>Beaverton, OR 97007</NOBR> </TD>
<TD> </TD>
<TD>
<TABLE style="FONT-SIZE: 10pt; FONT-FAMILY: Arial" cellSpacing=0
cellPadding=0 border=0>
<TBODY>
<TR>
<TD>Phone:</TD>
<TD>+1 (503) 643-9500</TD></TR>
<TR>
<TD>Fax:</TD>
<TD>+1 (503) 643-9600</TD></TR>
<TR>
<TD>E-Mail:</TD>
<TD><A
href="mailto:curtis.paris@metro1.com">curtis.paris@metro1.com</A></TD></TR>
<TR>
<TD>Web:</TD>
<TD><A href="http://www.metro1.com/"
target=_blank>http://www.metro1.com/</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<DIV><FONT face=Arial color=#0000ff
size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
openjms-developer mailing list
openjms-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openjms-developer
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic