my dog learned polymorphism*
The moose likes BEA/Weblogic and the fly likes how to use two execute queues for one servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "how to use two execute queues for one servlet" Watch "how to use two execute queues for one servlet" New topic
Author

how to use two execute queues for one servlet

sudhakar papireddy
Greenhorn

Joined: Jan 10, 2008
Posts: 9
Hi,

is it possible to use two execute queues for the same servlet.

for eg: i have only one servlet A , which can process two types of requests. i would like to pass first kind of request to one execute queue(probably default execute queue weblogic.kernel.Default) and second type of request to second excute queue.

Please help me !

Thanks
Sudhakar
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
What does it mean "two kinds of requests"?
If, for example, the difference is in the url pattern you can declare two different servlets with the same class as below :

<servlet>
<servlet-name>A</servlet-name>
<servlet-class>com.blablabla.XServlet</servlet-class>
<init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>firstExecuteQueue<param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>B</servlet-name>
<servlet-class>com.blablabla.XServlet</servlet-class>
<init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>secondExecuteQueue<param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>A</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>B</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

Hope it helps...

Best regards


Regards,<br />Andrea<br /> <br /><a href="http://www.linkedin.com/in/andreagazzarini" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID : a.gazzarini@gmail.com<br /><a href="http://www.andreagazzarini.blogspot.com" target="_blank" rel="nofollow">My Blog</a>
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
Excuse me for the format...



Hope it helps...

Best regards
sudhakar papireddy
Greenhorn

Joined: Jan 10, 2008
Posts: 9
Andrea Thank you for your reply.

let me explain the scenario.

when ever there is request to servlet, in the request object we have parameter called BEAN. servlet reads this parameter from the request object and create a object for with that parameter
eg: //Here WBean is a generic Bean
WBean wb = null;
String targetName = (String)request.getAttribute("Bean");
wb = (WBean)beanFactory.createObject(targetName);

Than it is going to call the following function to process the request.
wb.processRequest(request, response ,beanFactory).

Currently we divided these beans into to two categories. One set of beans is for saving data and another set of beans is to retrieve the data.
by default all these requests are going through the default web logic queue.


so we are planning to send the request to default queue if it is for saving the data (first category).
Otherwise send the request to another queue(new execute queue)( second category).

can you please help us , whether we can setup two execute queues in this scenario.

Thanks
sudhakar
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
Hi Sudhakar, simply : you can't do that with your actual design!

The container is not able to make a distinction between two requests with the same url pattern.
This is your scenario : you are calling the same servlet using a different value for a request parameter :

http//host ort/app/servlet?BEAN=A
http//host ort/app/servlet?BEAN=B

what is written after the name of the servlet is called the query string and is not part of
the identifier used in the url-pattern declaration.

now, since your bean are (I suppose) normal POJO, there's no container interposition so
after a thread is executing your servlet you can't ask to the container another thread for executing a POJO.

Here's one suggestion:

1) Take the value of the BEAN parameter and create a jms TextMessage with it;
2) Create a temporaryQueue (ex: incomingResponseQueue)and send the message to a previously declared jms queue (ex: incomingRequestsQueue) with the setJMSReplyTo property set to the temporary queue;
3) An MDB detaches the message from the incomingRequestQueue, takes the name of the bean and create a valid instance using the ObjectFactory.
4) The MDB executes the bean and send the response as a ObjectMessage to incomingResponseQueue.
5) The servlet consume the message from the incomingResponseQueue.

Something like this:

***** Servlet code ******



**** MDB CODE ****



now, you have solved the first part of the problem : you can execute your beans in a separated executing thread.
How you can distinguish the bean for updating and for retrieving data?

1) You can deploy twice the MDB (with two different names) on two different jms queues and assign to each of them a different execute queue.
This could be done with some kind of configuration in the web.xml. (for example a mapping between bean name --> destination Queue)
In this way the servlet must act as a router / dispatcher between the two queues / MDB.

2) If the names of the beans follow some kind of naming convention and starting from the name you can understand the category of it
you can deploy twice the MDB (with two different names) on THE SAME jsm queues and assign to them a corrispondent message selector.
In this way the servlet must put the bean name also in a string property of the jms message.


Best regards
sudhakar papireddy
Greenhorn

Joined: Jan 10, 2008
Posts: 9
hi thanks for your reply.

here i am confused about the last part
-------------------------------------------------
How you can distinguish the bean for updating and for retrieving data?

1) You can deploy twice the MDB (with two different names) on two different jms queues and assign to each of them a different execute queue.
This could be done with some kind of configuration in the web.xml. (for example a mapping between bean name --> destination Queue)
In this way the servlet must act as a router / dispatcher between the two queues / MDB.

2) If the names of the beans follow some kind of naming convention and starting from the name you can understand the category of it
you can deploy twice the MDB (with two different names) on THE SAME jms queues and assign to them a correspondent message selector.
In this way the servlet must put the bean name also in a string property of the jms message.
----------------------------------------------------------------

can you explain little bit more about this (specially point 1 )
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
Hi,
suppose you have four beans. A,B,C,D. A and B are for retrieving data, while B and C for updating. Well, as I wrote you have two choices :

1) Using servlet deployment descriptor. Using init params you must declare inside the Deployment descriptor all the beans divided by category. Something like this:


Now, you servlet looks like this:



2) Using message selector.
In this scenario you have only one queue and two MDB. The first MDB (for updating) has a message selector like this :

beanName IN ('A','B')

while the second one (for retrieving data) has the following message selector:

beanName IN ('C','D')

Now your servlet doesn't need to know the kind of request so in your service / doGet / doPost method :



That's all...the container will route the message to the appropriate MDB (using the message selector).

Regards
sudhakar papireddy
Greenhorn

Joined: Jan 10, 2008
Posts: 9
Andrea
Thank a lot for your info.


---------------
Thanks
Sudhakar P.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use two execute queues for one servlet