AbstractProcessor泛型抽象类

该类实现了ActionHook和Processor接口,并声明了一些方法。

protected static final StringManager sm = StringManager.getManager(Constants.Package);

	protected Adapter adapter;
	protected AsyncStateMachine<S> asyncStateMachine;
	protected AbstractEndpoint<S> endpoint;
	protected Request request;
	protected Response response;
	protected SocketWrapper<S> socketWrapper = null;

	/**
	 * 当前正在被处理的request/response的错误状态
	 * Error state for the request/response currently being processed.
	 */
	private ErrorState errorState = ErrorState.NONE;

	/**
	 * Intended for use by the Upgrade sub-classes that have no need to
	 * initialise the request, response, etc.
	 */
	protected AbstractProcessor() {
		// NOOP
	}

	/**
	 * 构造方法
	 * 
	 * @param endpoint
	 */
	public AbstractProcessor(AbstractEndpoint<S> endpoint) {
		this.endpoint = endpoint;
		asyncStateMachine = new AsyncStateMachine<S>(this);
		request = new Request();
		response = new Response();
		response.setHook(this);
		request.setResponse(response);
	}

	/**
	 * 更新errorState的状态,如果新的错误状态比当前错误状态严重
	 * Update the current error state to the new error state if the new error
	 * state is more severe than the current error state.
	 */
	protected void setErrorState(ErrorState errorState, Throwable t) {
		boolean blockIo = this.errorState.isIoAllowed()
				&& !errorState.isIoAllowed();
		this.errorState = this.errorState.getMostSevere(errorState);
		if (blockIo && !ContainerThreadMarker.isContainerThread()) {
			if (response.getStatus() < 400) {
				response.setStatus(500);
			}
			/**
			 * 直接交由endpoint处理该请求[error],此时SocketStatus为CLOSE_NOW
			 */
			getEndpoint().processSocketAsync(socketWrapper, SocketStatus.CLOSE_NOW);
		}
	}
	
	/**
	 * 重置错误状态
	 */
	protected void resetErrorState() {
		errorState = ErrorState.NONE;
	}

	/**
	 * 获取错误状态
	 * @return
	 */
	protected ErrorState getErrorState() {
		return errorState;
	}

	/**
	 * endpoint接受的连接将被该processor处理
	 * The endpoint receiving connections that are handled by this processor.
	 */
	protected AbstractEndpoint<S> getEndpoint() {
		return endpoint;
	}

	/**
	 * 该处理器所关联的request
	 * The request associated with this processor.
	 */
	@Override
	public Request getRequest() {
		return request;
	}

	/**
	 * 设置所关联的adapter对象
	 * 
	 * @param adapter
	 *            the new adapter
	 */
	public void setAdapter(Adapter adapter) {
		this.adapter = adapter;
	}

	/**
	 * 获取所关联的adapter对象
	 * 
	 * @return the associated adapter
	 */
	public Adapter getAdapter() {
		return adapter;
	}

	/**
	 * 设置socketWrapper
	 */
	protected final void setSocketWrapper(SocketWrapper<S> socketWrapper) {
		this.socketWrapper = socketWrapper;
	}

	/**
	 * 获取socketWrapper
	 */
	protected final SocketWrapper<S> getSocketWrapper() {
		return socketWrapper;
	}

	/**
	 * 获取endpoint中的executor
	 */
	@Override
	public Executor getExecutor() {
		return endpoint.getExecutor();
	}

	/**
	 * 判断该处理器实体是否是异步的
	 */
	@Override
	public boolean isAsync() {
		return (asyncStateMachine != null && asyncStateMachine.isAsync());
	}

	@Override
	public SocketState asyncPostProcess() {
		return asyncStateMachine.asyncPostProcess();
	}

	/**
	 * 处理错误跳转
	 */
	@Override
	public void errorDispatch() {
		getAdapter().errorDispatch(request, response);
	}

	@Override
	public abstract boolean isComet();

	@Override
	public abstract boolean isUpgrade();

	/**
	 * 处理http请求。所有的请求都将被当作HTTP请求来处理尽管在处理过程中他们会改变
	 * Process HTTP requests. All requests are treated as HTTP requests to start
	 * with although they may change type during processing.
	 */
	@Override
	public abstract SocketState process(SocketWrapper<S> socket)
			throws IOException;

	/**
	 * Process in-progress Comet requests. These will start as HTTP requests.
	 */
	@Override
	public abstract SocketState event(SocketStatus status) throws IOException;

	/**
	 * Process in-progress Servlet 3.0 Async requests. These will start as HTTP
	 * requests.
	 */
	@Override
	public abstract SocketState asyncDispatch(SocketStatus status);

	/**
	 * Processes data received on a connection that has been through an HTTP
	 * upgrade.
	 */
	@Override
	public abstract SocketState upgradeDispatch() throws IOException;

	/**
	 * @deprecated Will be removed in Tomcat 8.0.x.
	 */
	@Deprecated
	@Override
	public abstract org.apache.coyote.http11.upgrade.UpgradeInbound getUpgradeInbound();

	protected abstract Log getLog();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值