package org.gof.chainofresponsibility;
/**
 * ×¢Òâ£ºÈç¹ûµ±Ç°´¦ÀíÆ÷ÎÞ·¨´¦ÀíÇëÇó£¬±ØÐëµ÷ÓÃºóÐø´¦ÀíÆ÷´¦ÀíÇëÇó
 * È»¶ø£¬ÎÞ·¨±£ÕÏËùHandler½Ó¿ÚµÄÊµÏÖÀà¶¼ÊµÏÖÉÏÊöÂß¼­£¬
 * Òò´Ë£¬Í¨¹ýÒ»¸ö³éÏóµÄ»ùÀàÀ´±£ÕÏÉÏÊöÂß¼­
 * 
 * Java Servlet Filter×ñÑ­ÁËGOF¶ÔÔðÈÎÁ´Éè¼ÆÄ£Ê½µÄÉÏÊöµÄÈ±ÏÝ
 * 
 * @author LSK
 *
 */
public abstract class AbstractHandler implements Handler {

	private volatile Handler next;

	@Override
	public final void setNext(Handler handler) {
		this.next = handler;
	}

	@Override
	public final void handleRequest(Request request) {
		if (this.accept(request)) {
			this.doHandle(request);
		} else {
			this.next.handleRequest(request);
		}
	}

	protected abstract boolean accept(Request request);

	protected abstract void doHandle(Request request);
}
