package com.eactive.eai.common.web;

import javax.servlet.*;
import java.io.IOException;

public class FrontFilter implements Filter {
	private static int count;

	private FilterConfig config;

	public void destroy() {

	}

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {
		try {
			increase();
			chain.doFilter(req, res);
		} catch (Exception e) {
			throw new ServletException(e.getMessage());
		} finally {
			descrease();
		}
	}

	public void init(FilterConfig config) throws ServletException {
		this.config = config;
		if (this.config != null) {
			this.config.getFilterName();
		}
	}

	private synchronized void increase() {
		count++;
	}

	private synchronized void descrease() {
		count--;
	}

	public static int count() {
		return count;
	}
}
