package com.example.struts2;

import com.opensymphony.xwork2.ActionSupport;
import com.example.struts2.interceptor.MonitorInterceptor;
import org.apache.struts2.interceptor.RequestAware;
import java.util.Map;

/**
 * 拦截器演示 Action
 * 
 * 学习点：
 * - 拦截器与 Action 的协作
 * - RequestAware 接口获取 request
 */
public class InterceptorDemoAction extends ActionSupport implements RequestAware {
    
    private Map<String, Object> request;
    private Map<String, Long> interceptorStats;
    private Long executionTime;
    
    public String execute() {
        interceptorStats = MonitorInterceptor.getStats();
        if (request != null) {
            executionTime = (Long) request.get("executionTimeNs");
        }
        return SUCCESS;
    }
    
    @Override
    public void setRequest(Map<String, Object> request) {
        this.request = request;
    }
    
    public Map<String, Long> getInterceptorStats() { return interceptorStats; }
    public Long getExecutionTime() { return executionTime; }
}