KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > http > servlet > internal > Registration


1 /*******************************************************************************
2  * Copyright (c) 2005-2007 Cognos Incorporated, IBM Corporation and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Cognos Incorporated - initial API and implementation
10  * IBM Corporation - bug fixes and enhancements
11  *******************************************************************************/

12 package org.eclipse.equinox.http.servlet.internal;
13
14 import java.io.IOException JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18
19 public abstract class Registration {
20
21     protected int referenceCount;
22
23     public synchronized void addReference() {
24         ++referenceCount;
25     }
26
27     public synchronized void removeReference() {
28         --referenceCount;
29         if (referenceCount == 0) {
30             notifyAll();
31         }
32     }
33
34     public synchronized void destroy() {
35         boolean interrupted = false;
36         try {
37             while (referenceCount != 0) {
38                 try {
39                     wait();
40                 } catch (InterruptedException JavaDoc e) {
41                     // wait until the servlet is inactive but save the interrupted status
42
interrupted = true;
43                 }
44             }
45         } finally {
46             if (interrupted)
47                 Thread.currentThread().interrupt(); //restore the interrupted state
48
}
49     }
50
51     public abstract boolean handleRequest(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp, String JavaDoc alias) throws IOException JavaDoc, ServletException JavaDoc;
52
53     public void close() {
54         // do nothing
55
}
56
57 }
58
Popular Tags