You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Colic <al...@pop-ware.com> on 2001/09/24 22:14:07 UTC

Can you comment on this design idea?

Hi,

hopefully someone can comment on an idea I have.

I have a VB backend that I talk to via a socket to handle db access. When a
connection is made to the back end I put a Boolean value of TRUE under the
"active" key in the application session. If for whatever reason the VB
backend goes down I get the key "active" and set it to FALSE. I created a
tag that as the user goes from page to page it checks this key and if it is
active it continues displaying the page and if it is not it takes the user
to a generic, back end down page.

A problem I found is that a user could be on a page and submit data to a
servlet. If the backend has gone down while the user has been on a page, the
servlet will not know about it and attempt to do some work. I do not want
this to happen. I want a similar set-up that I have for the pages for the
servlet.

I was thinking of overriding the doGet and Post methods of the ActionServlet
to check if the "active" key is true. If it is continue passing the request
to the servlets if it is not then send them to a generic, back end not
available page.

Something like this:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
  {
String errorPage="/serverNotAvailable.jsp";
if(key)
	{
		//do usual work
	}
else
	{
		RequestDispatcher disp=new request.getRequestDispatcher(errorPage);
		disp.forward(request,response);
	}

super.doGet(request, response);

any comments are appreciated.

Alex


RE: Can you comment on this design idea?

Posted by Hans Gilde <hg...@environments.com>.
Alex,

You probably want a connection pool. Your code in an Action class (or
wherever) would be something like:

MyConnection MyConnectionObject;

try {
	//get the connection from the pool
	MyConnectionObject = MyConnection.getInstance();
	//do your stuff
} catch (MyConnectionInvalidException e) {
	//error
} catch (MyConnectonInterruptedException e) {
	//another error
} finally {
	//release the connection back to the pool
	MyConnection.releaseInstance(MyConnectionObject);
}

Where MyConnection.getInstance() and releaseInstance are public static
methods of MyConnection; they check the connection before returning it.
There are a couple of open source connection pools that help here. This
technique would be directly portable between a servlet and a GUI
application. It requires a ping before each connection attempt but is
probably worth the overhead.

If you're open to changing the architecture... Why not use SOAP calls to COM
objects running in MTS? There's a more overhead in each invocation but you
get to use neat new technology.


-----Original Message-----
From: Alex Colic [mailto:alex.colic@pop-ware.com]
Sent: Monday, September 24, 2001 4:14 PM
To: Struts
Subject: Can you comment on this design idea?


Hi,

hopefully someone can comment on an idea I have.

I have a VB backend that I talk to via a socket to handle db access. When a
connection is made to the back end I put a Boolean value of TRUE under the
"active" key in the application session. If for whatever reason the VB
backend goes down I get the key "active" and set it to FALSE. I created a
tag that as the user goes from page to page it checks this key and if it is
active it continues displaying the page and if it is not it takes the user
to a generic, back end down page.

A problem I found is that a user could be on a page and submit data to a
servlet. If the backend has gone down while the user has been on a page, the
servlet will not know about it and attempt to do some work. I do not want
this to happen. I want a similar set-up that I have for the pages for the
servlet.

I was thinking of overriding the doGet and Post methods of the ActionServlet
to check if the "active" key is true. If it is continue passing the request
to the servlets if it is not then send them to a generic, back end not
available page.

Something like this:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
  {
String errorPage="/serverNotAvailable.jsp";
if(key)
	{
		//do usual work
	}
else
	{
		RequestDispatcher disp=new request.getRequestDispatcher(errorPage);
		disp.forward(request,response);
	}

super.doGet(request, response);

any comments are appreciated.

Alex