Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock/unlock a site

Status
Not open for further replies.

yanis97

Programmer
Jan 26, 2004
22
0
0
FR
Hi;

At 20 pm , each day a data replication on a SQL server 2000 is started. My J2ee application use this SQL server and I would like to synchronise with the replication.
Just before to launch the data replication, I start a filter servlet to lock the site (acces denied for the maintenance) and when the replication is finish, I unlock the site.

Q : how to call the servlet from SQL server or how J2ee application call the SQL server ? For example in using a flag into the database ?

regards;
 
why do you need to call the servlet? to see if the job is running? why not just have the job set a flag in the database, and have the servlet check that flag - so if any user tries to access the site, the servlet will do the checking. the SQL server job doesn't have to know about the servlet.


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Hi Jeff;

Its OK but I need to execute a thread which supervises all the time (each minute) the changement of the flag !
But I do not want to do this => performance problem.

Regards;
 
no you don't... it would be as simple as

Code:
package mypackage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class myServlet extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		
		checkDisabled(res);
		
		...
		
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		
		checkDisabled(res);
		
		...
		
	}
	
	private void checkDisabled(HttpServletResponse res)
			throws IOException {
				
		boolean disabled = getDisabledFlagFromDb();
		
		if (disabled) {
			res.sendRedirect("path/to/siteUnavailable.jsp");
		}
	}
	
}

this way every attempt to access the site is first validated to see if the site is available.

it can also be done other ways, e.g.
- some base servlet class that does this check, and all your servlets extend it

- a servlet filter that does the check

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top