当前位置:首页>java>Java中保持扩展性的几种套路和实现

Java中保持扩展性的几种套路和实现

  • 2026-01-21 22:58:47
Java中保持扩展性的几种套路和实现

阿里妹导读

在日常的开发中,作者总结了平常用到的一些低成本、保持扩展性的套路,分享出来,欢迎大家讨论。

前言

SOLID(单一、开闭、里式替换、接口隔离、依赖倒置)五大原则和23种设计模式(常见的单例、构建者、装饰、适配、代理、组合、模板等等),小伙伴们对这些肯定都很熟悉。这些原则和设计模式能够辅助我们,让我们在设计的时候有所抉择,从而达到高内聚、低耦合的目的。
那说到设计,肯定会提到架构两个字,常见的架构名词:分层架构、六边形架构、SOA架构、CQRS架构、EDA架构等等。我个人对架构的理解是边界的确认以及边界内部元素的组合,其实只要是程序员,他就一定是架构师,只不过是好的架构师还是不那么好的架构师;人人都是架构师,我认为这句话是没有问题的,区别在于他的认知决定了他所能确认的边界、如何更高效的组合内部元素;技术的架构师肯定侧重于技术,业务的架构师肯定侧重于业务,商品的架构师所能看到的边界大概率还是局限在商品域,ICBU架构组的架构师更多考虑是横向的业务支撑。以上是我个人对架构两个字的理解,今天我们不讨论具体架构,我们讨论一些套路,在日常的开发中,我总结了些我平常用到的一些低成本、保持扩展性的套路,分享出来,欢迎大家讨论。

基于管道(pipeline)的套路

关键点

  • 管道(Pipeline)----用于串联阀门的管道通路

  • 阀门(PipelineValue)----用于每一个节点处理实际业务诉求

  • 管道上下文(PipelineContext)----用于管道上下文中数据的扭转

适用场景

  • 当你的数据流需要经过很多同等逻辑处理时,可以考虑使用此套路,便于后续扩展

实现代码

  • Pipeline/StandardPipeline
package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:46 */public interface Pipeline {    /**     * 执行     *     * @return     */    boolean invoke(PipelineContext pipelineContext);    /**     * 添加值     *     * @param pipelineValue     * @return     */    boolean addValue(PipelineValue pipelineValue);    /**     * 移除值     *     * @param pipelineValue     * @return     */    boolean removeValue(PipelineValue pipelineValue);}package com.example.ownertest.dm.pipelline;import java.util.List;import com.google.common.collect.Lists;import lombok.Data;import lombok.extern.slf4j.Slf4j;/** * @Author: linear.zw * @Date: 2023/10/25 19:46 */@Data@Slf4jpublic class StandardPipeline implements Pipeline {    private List<PipelineValue> pipelineValueList = Lists.newArrayList();    @Override    public boolean invoke(PipelineContext pipelineContext) {        boolean isResult = true;        for (PipelineValue pipelineValue :            pipelineValueList) {            try {                isResult = pipelineValue.execute(pipelineContext);                if (!isResult) {                    log.error("{},exec is wrong", pipelineValue.getClass().getSimpleName());                }            } catch (Exception e) {                log.error(e.getMessage(), e);            }        }        return isResult;    }    @Override    public boolean addValue(PipelineValue pipelineValue) {        if (pipelineValueList.contains(pipelineValue)) {            return true;        }        return pipelineValueList.add(pipelineValue);    }    @Override    public boolean removeValue(PipelineValue pipelineValue) {        return pipelineValueList.remove(pipelineValue);    }}
  • PipelineContext/StandardPipelineContext

package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:47 */public interface PipelineContext {    String FOR_TEST = "forTest";    /**     * 设置     *     * @param contextKey     * @param contextValue     */    void set(String contextKey, Object contextValue);    /**     * 获取值     *     * @param contextKey     * @return     */    Object get(String contextKey);}package com.example.ownertest.dm.pipelline;import java.util.Map;import com.google.common.collect.Maps;/** * @Author: linear.zw * @Date: 2023/10/25 19:47 */public class StandardPipelineContext implements PipelineContext {    private Map<String, Object> contentMap = Maps.newConcurrentMap();    @Override    public void set(String contextKey, Object contextValue) {        contentMap.put(contextKey, contextValue);    }    @Override    public Object get(String contextKey) {        return contentMap.get(contextKey);    }}
  • PipelineValue/AbstractPipelineValue/GraySwitchValue/ForTestValue
package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:47 */public interface PipelineValue {    /**     * 节点执行     *     * @param pipelineContext     * @return     */    boolean execute(PipelineContext pipelineContext);}package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:48 */public abstract class AbstractPipelineValue implements PipelineValue {    @Override    public boolean execute(PipelineContext pipelineContext) {        System.out.println(this.getClass().getSimpleName() + " start ");        boolean result = doExec(pipelineContext);        System.out.println(this.getClass().getSimpleName() + " end ");        return result;    }    protected abstract boolean doExec(PipelineContext pipelineContext);}package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:48 */public class GraySwitchValue extends AbstractPipelineValue {    @Override    public boolean doExec(PipelineContext pipelineContext) {        pipelineContext.set(PipelineContext.FOR_TEST, true);        return true;    }}package com.example.ownertest.dm.pipelline;/** * @Author: linear.zw * @Date: 2023/10/25 19:48 */public class ForTestValue extends AbstractPipelineValue {    @Override    public boolean doExec(PipelineContext pipelineContext) {        return true;    }}
  • PipelineClient
package com.example.ownertest.dm.pipelline;/** * 入口类 * * @Author: linear.zw * @Date: 2023/10/25 19:48 */public class PipelineClient {    public static void main(String[] args) {        // 管道初始化        Pipeline pipeline = new StandardPipeline();        // value扩展        PipelineValue pipelineValue = new GraySwitchValue();        PipelineValue pipelineValue2 = new ForTestValue();        // 上下文        PipelineContext pipelineContext = new StandardPipelineContext();        pipeline.addValue(pipelineValue);        pipeline.addValue(pipelineValue2);        // 调用管道        pipeline.invoke(pipelineContext);    }}

常见框架中的应用

  • 网络层的扛把子netty框架中,例如ChannelPipeline、ChannelHandler、ChannelHandlerContext,分别用于处理tcp拆包、加解码等等之类。

基于责任链(filterchain)的套路

关键点



来源--https://www.oracle.com/java/technologies/intercepting-filter.html
  • 过滤器(Filter)----实际处理业务的节点

  • 过滤链(FilterChain)----串联过滤器的链条

适用场景

  • 例如常见的web请求场景

实现代码

  • Filter/ForTest1Filter/ForTest2Filter

package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:22 */public interface Filter {    void doFilter(HttpRequest httpRequest,FilterChain filterChain);}package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:22 */public class ForTest1Filter implements Filter {    @Override    public void doFilter(HttpRequest httpRequest, FilterChain filterChain) {        // do        System.out.println(this.getClass().getSimpleName() + " before " + System.currentTimeMillis());        filterChain.doFilter(httpRequest);        // after        System.out.println(this.getClass().getSimpleName() + " end " + System.currentTimeMillis());    }}package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:22 */public class ForTest2Filter implements Filter {    @Override    public void doFilter(HttpRequest httpRequest, FilterChain filterChain) {        // do        System.out.println(this.getClass().getSimpleName() + " before " + System.currentTimeMillis());        filterChain.doFilter(httpRequest);        // after        System.out.println(this.getClass().getSimpleName() + " end " + System.currentTimeMillis());    }}
  • FilterChain/StandardFilterChain
package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:23 */public interface FilterChain {    void doFilter(HttpRequest httpRequest);    void addFilter(Filter filter);}package com.example.ownertest.dm.filter;import java.util.List;import com.google.common.collect.Lists;/** * @Author: linear.zw * @Date: 2023/10/26 19:24 */public class StandardFilterChain implements FilterChain {    private List<Filter> filterList = Lists.newArrayList();    private int currentIndex = 0;    @Override    public void doFilter(HttpRequest httpRequest) {        if (currentIndex == filterList.size()) { return; }        Filter filter = filterList.get(currentIndex);        currentIndex = currentIndex + 1;        filter.doFilter(httpRequest, this);    }    @Override    public void addFilter(Filter filter) {        if (filterList.contains(filter)) {            return;        }        filterList.add(filter);    }}
  • HttpRequest/StandardHttpRequest
package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:24 */public interface HttpRequest {}package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:24 */public class StandardHttpRequest implements HttpRequest {}
  • FilterClient----入口测试
package com.example.ownertest.dm.filter;/** * @Author: linear.zw * @Date: 2023/10/26 19:25 */public class FilterClient {    public static void main(String[] args) {        FilterChain filterChain = new StandardFilterChain();        filterChain.addFilter(new ForTest1Filter());        filterChain.addFilter(new ForTest2Filter());        filterChain.doFilter(new StandardHttpRequest());    }}

常见框架中的应用

  • hsf的filter机制,服务端扩展的ServerFilter和客户端扩展的ClientFilter

  • 开发过java web的小伙伴都知道的servlet,servlet的入口即是FilterChain、Filter;

基于组合/模板的套路

关键点

  • 理器注册器----用于存储处理器的集合

  • 处理器工厂----用于创建处理器

  • 处理器----实际的处理器以及扩展的实现

  • 处理器上下文----处理器上下文,用于参数的传递

适用场景

  • 适合于有共性、后续持续扩展的场景

实现代码

  • PiiHandlerRegistry----处理器注册器

package com.example.ownertest.dm.comp;import java.lang.reflect.Field;import java.util.List;import java.util.Map;import com.google.common.collect.Maps;import lombok.extern.slf4j.Slf4j;import org.apache.commons.collections4.CollectionUtils;import org.apache.commons.lang3.StringUtils;/** * @Author: linear.zw * @Date: 2023/10/31 20:45 */@Slf4jpublic class PiiHandlerRegistry {    private static Map<String, PiiDomainFieldHandler> piiDomainFieldHandlerMap = Maps.newHashMap();    public static void putHandler(String piiDomainFieldName, PiiDomainFieldHandler piiDomainFieldHandler) {        if (StringUtils.isEmpty(piiDomainFieldName)) {            log.warn(" piiDomainFieldName is null,continue");            return;        }        if (piiDomainFieldHandler == null) {            log.warn(piiDomainFieldName + " piiDomainFieldHandler is null,continue");            return;        }        if (!piiDomainFieldHandlerMap.containsKey(piiDomainFieldName)) {            piiDomainFieldHandlerMap.put(piiDomainFieldName, piiDomainFieldHandler);        }    }    public static <T extends Object> int handlerRead(T domain, Field domainField, PiiContent piiContent) {        int num = 0;        for (Map.Entry<String, PiiDomainFieldHandler> piiDomainFieldHandlerEntry :            piiDomainFieldHandlerMap.entrySet()) {            if (piiDomainFieldHandlerEntry.getValue().isSupport(domain, domainField)) {                piiDomainFieldHandlerEntry.getValue().handlerRead(domain, domainField, piiContent);            }        }        return num;    }    public static <T extends Object> int handlerWrite(T domain, Field domainField, PiiContent piiContent) {        int num = 0;        for (Map.Entry<String, PiiDomainFieldHandler> piiDomainFieldHandlerEntry :            piiDomainFieldHandlerMap.entrySet()) {            if (piiDomainFieldHandlerEntry.getValue().isSupport(domain, domainField)) {                piiDomainFieldHandlerEntry.getValue().handlerWrite(domain, domainField, piiContent);            }        }        return num;    }    public static Map<String, PiiDomainFieldHandler> getPiiDomainFieldHandlerMap() {        return piiDomainFieldHandlerMap;    }    public static void init() {        List<PiiDomainFieldHandler> piiDomainFieldHandlerList = PiiDomainFieldHandlerFactory            .createPiiDomainFieldHandler();        if (CollectionUtils.isNotEmpty(piiDomainFieldHandlerList)) {            for (PiiDomainFieldHandler piiDomainFieldHandler :                piiDomainFieldHandlerList) {                putHandler(piiDomainFieldHandler.getPiiDomainMeta(), piiDomainFieldHandler);            }        }    }}
  • PiiDomainFieldHandlerFactory----处理器工厂
package com.example.ownertest.dm.comp;import java.util.List;import com.google.common.collect.Lists;/** * @Author: linear.zw * @Date: 2023/10/31 20:46 */public class PiiDomainFieldHandlerFactory {    /**     * 创建领域处理器     *     * @return     */    public static List<PiiDomainFieldHandler> createPiiDomainFieldHandler() {        List<PiiDomainFieldHandler> piiDomainFieldHandlerList = Lists.newArrayList();        //        piiDomainFieldHandlerList.add(new ForTestSupportFieldHandler());        piiDomainFieldHandlerList.add(new ForTestNotSupportFieldHandler());        return piiDomainFieldHandlerList;    }}
  • PiiDomainFieldHandler/PiiDomainFieldHandlerBase/ForTestNotSupportFieldHandler/ForTestSupportFieldHandler----处理器
package com.example.ownertest.dm.comp;import java.lang.reflect.Field;/** * @Author: linear.zw * @Date: 2023/10/31 20:46 */public interface PiiDomainFieldHandler {    /**     * 处理实际操作     * 读----从PiiContent获取数据回填domain     *     * @param domain     * @param domainField     * @param piiContent     * @param <T>     * @return     */    <T extends Object> boolean handlerRead(T domain, Field domainField, PiiContent piiContent);    /**     * 处理实际操作     * 写----将domain中需要写入pii的字段数据写入PiiContent     *     * @param domain     * @param domainField     * @param piiContent     * @param <T>     * @return     */    <T extends Object> boolean handlerWrite(T domain, Field domainField, PiiContent piiContent);    /**     * 当前处理器是否支持该领域对象     *     * @param domain     * @param domainField     * @param <T>     * @return     */    <T extends Object> boolean isSupport(T domain, Field domainField);    /**     * 获取处理器对应的元信息     *     * @return     */    String getPiiDomainMeta();}package com.example.ownertest.dm.comp;import java.lang.reflect.Field;import lombok.extern.slf4j.Slf4j;/** * @Author: linear.zw * @Date: 2023/10/31 20:47 */@Slf4jpublic abstract class PiiDomainFieldHandlerBase implements PiiDomainFieldHandler {    @Override    public <T extends Object> boolean handlerRead(T domain, Field domainField, PiiContent piiContent) {        // to do business read        return true;    }    @Override    public <T extends Object> boolean handlerWrite(T domain, Field domainField, PiiContent piiContent) {        // to do business write        return true;    }}package com.example.ownertest.dm.comp;import java.lang.reflect.Field;/** * @Author: linear.zw * @Date: 2023/10/31 20:47 */public class ForTestSupportFieldHandler extends PiiDomainFieldHandlerBase {    @Override    public <T> boolean isSupport(T domain, Field domainField) {        if (this.getClass().getSimpleName().equalsIgnoreCase(domain.getClass().getSimpleName())) {            // to do business            System.out.println(this.getClass().getSimpleName() + " is support, to do some business");            return true;        }        return false;    }    @Override    public String getPiiDomainMeta() {        return this.getClass().getSimpleName();    }}package com.example.ownertest.dm.comp;import java.lang.reflect.Field;/** * @Author: linear.zw * @Date: 2023/10/31 20:48 */public class ForTestNotSupportFieldHandler extends PiiDomainFieldHandlerBase {    @Override    public <T> boolean isSupport(T domain, Field domainField) {        if (this.getClass().getSimpleName().equalsIgnoreCase(domain.getClass().getSimpleName())) {            // to do business            System.out.println(this.getClass().getSimpleName() + " is support, to do some business");            return true;        }        return false;    }    @Override    public String getPiiDomainMeta() {        return this.getClass().getSimpleName();    }}
  • PiiContent----上下文
package com.example.ownertest.dm.comp;import java.util.Map;import com.google.common.collect.Maps;import lombok.Data;/** * @Author: linear.zw * @Date: 2023/10/31 20:48 */@Datapublic class PiiContent {    public static String FORTEST="fortest";    private Map<String, Object> piiDataMap = Maps.newHashMap();    private Map<String, Object> piiContextMap = Maps.newHashMap();    public void putPiiData(String domainFieldName, Object domainFieldValue) {        piiDataMap.put(domainFieldName, domainFieldValue);    }    public Object getPiiData(String domainFieldName) {        return piiDataMap.get(domainFieldName);    }    public void putPiiContext(String contextName, Object contextNameValue) {        piiContextMap.put(contextName, contextNameValue);    }    public Object getPiiContext(String contextName) {        return piiContextMap.get(contextName);    }}
  • PiiClient----入口的测试类
package com.example.ownertest.dm.comp;import java.util.Map;/** * @Author: linear.zw * @Date: 2023/10/31 20:48 */public class PiiClient {    public static void main(String[] args) {        PiiHandlerRegistry.init();        // 遍历处理器        for (Map.Entry<String, PiiDomainFieldHandler> entryHandler :            PiiHandlerRegistry.getPiiDomainFieldHandlerMap().entrySet()) {            System.out.println(entryHandler.getKey() + "\t" + entryHandler.getValue().getPiiDomainMeta());        }        //        PiiContent piiContent = new PiiContent();        piiContent.putPiiContext(PiiContent.FORTEST, PiiContent.FORTEST);        // 请求处理        System.out.println("ForTestSupportFieldHandler start");        PiiHandlerRegistry.handlerRead(new ForTestSupportFieldHandler(), null, piiContent);        System.out.println("ForTestSupportFieldHandler end");        // 请求处理        System.out.println("ForTestNotSupportFieldHandler start");        PiiHandlerRegistry.handlerRead(new ForTestNotSupportFieldHandler(), null, piiContent);        System.out.println("ForTestNotSupportFieldHandler end");    }}

常见框架中的应用

  • 这个就太多了,例如spring最核心的BeanPostProcessor机制,通过org.springframework.beans.factory.support.AbstractBeanFactory#beanPostProcessors管理一些列的beanPostProcessors,在spring上下文org.springframework.context.support.AbstractApplicationContext#refresh的时候,进行bean的init(InitDestroyAnnotationBeanPostProcessor)、解析注解(ScheduledAnnotationBeanPostProcessor、AutowiredAnnotationBeanPostProcessor)、解析aop(AnnotationAwareAspectJAutoProxyCreator)等等。

基于注解的套路

关键点

  • 注解元定义----用来定义通用的元信息;
  • 注解解析器----解析类上是否有指定的注解,进而进行对应的扩展操作;
  • spring的BeanPostProcessor----这里是借用spring的BeanPostProcessor机制,在spring容器初始化的时候,进行回调,完成预期的扩展行为;

适用场景

  • 简化内部使用

实现代码

  • ForTestAnnotation----注解元定义
package com.example.ownertest.dm.annotation;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.springframework.stereotype.Component;/** * 用于测试的标识注解 * * @Author: linear.zw * @Date: 2023/11/1 10:21 */@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Componentpublic @interface ForTestAnnotation {}
  • ForTestAnnotationProcessor----注解解析器
package com.example.ownertest.dm.annotation;import org.springframework.aop.support.AopUtils;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.BeanPostProcessor;import org.springframework.core.annotation.AnnotationUtils;import org.springframework.stereotype.Component;/** * 注解解析器 * @Author: linear.zw * @Date: 2023/11/1 10:25 */@Componentpublic class ForTestAnnotationProcessor implements BeanPostProcessor {    @Override    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {        // 获取目标类是否有ForTestAnnotation注解        ForTestAnnotation annotation = AnnotationUtils.findAnnotation(AopUtils.getTargetClass(bean),            ForTestAnnotation.class);        if (annotation == null) {            return bean;        }        // 处理想要的扩展        System.out.println(beanName + " has ForTestAnnotation");        return bean;    }    @Override    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {        return bean;    }}
  • ForTestBean----测试bean
package com.example.ownertest.dm.annotation;/** * @Author: linear.zw * @Date: 2023/11/1 10:26 */@ForTestAnnotationpublic class ForTestBean {    public ForTestBean() {        System.out.println(ForTestBean.class.getSimpleName() + " init");    }}
  • ForTestClient---测试入口
package com.example.ownertest.dm.annotation;import org.springframework.context.annotation.AnnotationConfigApplicationContext;/** * @Author: linear.zw * @Date: 2023/11/1 10:26 */public class ForTestClient {    public static void main(String[] args) {        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(            "com.example.ownertest.dm.annotation");        System.out.println(ForTestClient.class.getSimpleName());    }}

常见框架中的应用

  • 例如集团内部的spring-boot-alibaba-diamond-autoconfigure

基于事件分发的套路

关键点

  • 事件源--事件触发者

  • 事件--标识产生的来源

  • 事件监听器--事件的关注者,即处理者

  • 事件分发器--用于将事件源的事件转发给事件监听器

实现代码

  • EventSource/EventSourceForTest/EventSourceForTest2

package com.example.ownertest.dm.event;/** * 发出事件 * @Author: linear.zw * @Date: 2023/11/1 14:12 */public interface EventSource {    /**     * 发出事件     *     * @return     */    Event fireEvent();}package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:14 */public class EventSourceForTest implements EventSource {    @Override    public Event fireEvent() {        Event event = new EventForTest();        System.out.println(getClass().getSimpleName() + " \t fireEvent " + event.getName());        return event;    }}package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:15 */public class EventSourceForTest2 implements EventSource {    @Override    public Event fireEvent() {        Event event = new EventForTest2();        System.out.println(getClass().getSimpleName() + " \t fireEvent " + event.getName());        return event;    }}
  • Event/EventForTest/EventForTest2
package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:15 */public interface Event {    /**     * 事件名称     *     * @return     */    String getName();}package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:17 */public class EventForTest implements Event {    @Override    public String getName() {        return getClass().getSimpleName();    }}package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:17 */public class EventForTest2 implements Event {    @Override    public String getName() {        return getClass().getSimpleName();    }}
  • EventListener/EventListenerForTest
package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:17 */public interface EventListener {    /**     * 是否支持此事件     *     * @param event     * @return     */    boolean supportEvent(Event event);    /**     * 处理事件     *     * @return     */    boolean handlerEvent(Event event);}package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:18 */public class EventListenerForTest implements EventListener {    @Override    public boolean supportEvent(Event event) {        return event.getName().contains("Test");    }    @Override    public boolean handlerEvent(Event event) {        System.out.println(this.getClass().getSimpleName() + "\t handler " + event.getName());        return true;    }}
  • EventDispatcher/EventListenerManager
package com.example.ownertest.dm.event;import org.apache.commons.collections4.CollectionUtils;/** * @Author: linear.zw * @Date: 2023/11/1 14:18 */public class EventDispatcher {    /**     * 单例模式     */    private static EventDispatcher eventDispatcher = new EventDispatcher();    private EventDispatcher() {    }    /**     * 分发事件     *     * @param event     * @return     */    public static boolean dispatchEvent(Event event) {        if (CollectionUtils.isNotEmpty(EventListenerManager.getEventListenerList())) {            for (EventListener eventListener :                EventListenerManager.getEventListenerList()) {                if (eventListener.supportEvent(event)) {                    eventListener.handlerEvent(event);                }            }        }        return true;    }}package com.example.ownertest.dm.event;import java.util.List;import com.google.common.collect.Lists;/** * @Author: linear.zw * @Date: 2023/11/1 14:18 */public class EventListenerManager {    private static List<EventListener> eventListenerList = Lists.newArrayList();    /**     * 添加事件监听器     *     * @param eventListener     * @return     */    public static boolean addEventListener(EventListener eventListener) {        if (!eventListenerList.contains(eventListener)) {            return eventListenerList.add(eventListener);        }        return true;    }    /**     * 移除事件监听器     *     * @param eventListener     * @return     */    public static boolean removeEventListener(EventListener eventListener) {        if (eventListenerList.contains(eventListener)) {            return eventListenerList.remove(eventListener);        }        return true;    }    public static List<EventListener> getEventListenerList() {        return eventListenerList;    }}
  • EventClient
package com.example.ownertest.dm.event;/** * @Author: linear.zw * @Date: 2023/11/1 14:19 */public class EventClient {    public static void main(String[] args) {        // 创建事件源        EventSource eventSourceForTest = new EventSourceForTest();        EventSource eventSourceForTest2 = new EventSourceForTest2();        // 创建事件监听器        EventListener eventListener = new EventListenerForTest();        EventListenerManager.addEventListener(eventListener);        // 发布事件        EventDispatcher.dispatchEvent(eventSourceForTest.fireEvent());        EventDispatcher.dispatchEvent(eventSourceForTest2.fireEvent());    }}

基于SPI机制的套路

关键点

  • 服务调用方

  • 服务实现方----以接口名称为文件名称,放在META-INF/services,值为该接口的实现

  • 标准服务接口

适用场景

实现代码

  • SpiServiceLoaderHelper

package com.example.ownertest.dm.spi;import java.util.Iterator;import java.util.Objects;import java.util.ServiceLoader;/** * @Author: linear.zw * @Date: 2023/11/1 15:32 */public class SpiServiceLoaderHelper {    public static ProductPackageRemoteServiceInterface getProductPackageRemoteServiceInterface() {        // 先从缓存中加载        Object serviceCache = DependServiceRegistryHelper.getDependObject(ProductPackageRemoteServiceInterface.class);        if (serviceCache != null) {            return (ProductPackageRemoteServiceInterface) serviceCache;        }        // spi 方式加载        ProductPackageRemoteServiceInterface serviceInterface = loadSpiImpl(ProductPackageRemoteServiceInterface.class);        // 防止注入的bean为空 提前进行判断 以免业务执行出现问题        boolean isExist = true;        if (Objects.isNull(serviceInterface)) {            isExist = false;        } else if (Objects.isNull(serviceInterface.getProductPackageRemoteService())) {            isExist = false;        }        if (!isExist) {            throw new RuntimeException("getProductPackageRemoteService load impl failed,please check spi service");        }        // 添加进统一的依赖管理        DependServiceRegistryHelper.registry(ProductPackageRemoteServiceInterface.class, serviceInterface);        return serviceInterface;    }    /**     * 以spi的方式加载实现类     *     * @param cls     * @param <P>     * @return     */    private static <P> P loadSpiImpl(Class<P> cls) {        ServiceLoader<P> spiLoader = ServiceLoader.load(cls);        Iterator<P> iaIterator = spiLoader.iterator();        if (iaIterator.hasNext()) {            return iaIterator.next();        }        return null;    }}
  • DependServiceRegistryHelper
package com.example.ownertest.dm.spi;import java.util.Map;import com.google.common.collect.Maps;/** * @Author: linear.zw * @Date: 2023/11/1 15:35 */public class DependServiceRegistryHelper {    /**     * 存储策略依赖的服务,统一管理     */    private static Map<String, Object> dependManagerMap = Maps.newHashMap();    public static boolean registryMap(Map<Class, Object> dependManagerMap) {        for (Map.Entry<Class, Object> dependEntry :            dependManagerMap.entrySet()) {            registry(dependEntry.getKey(), dependEntry.getValue());        }        return true;    }    public static boolean registry(Class cls, Object dependObject) {        dependManagerMap.put(cls.getCanonicalName(), dependObject);        return true;    }    public static Object getDependObject(Class cls) {        return dependManagerMap.get(cls.getCanonicalName());    }}
  • SpiServiceLoaderClientTest
package com.example.ownertest.dm.spi;/** * @Author: linear.zw * @Date: 2023/11/1 15:37 */public class SpiServiceLoaderClientTest {    public static void main(String[] args) {        ProductPackageRemoteServiceInterface productPackageRemoteServiceInterface            = SpiServiceLoaderHelper.getProductPackageRemoteServiceInterface();    }}

常见框架中的应用

  • 目前大多数中台的策略包,都是基于spi方式的,动态加载业务的实现,进而达到扩展的目的;

  • 例如google开源的auto-service,通过注解的方式,自动生成spi的实现目录;

最后

程序员大多数都是实干派,所以,你的套路有哪些,评论区有你的位置,Show me the code。

欢迎加入【阿里云开发者公众号】读者群

这是一个专门面向“阿里云开发者”公众号的读者交流空间
💡 在这里你可以探讨技术和实践,我们也会定期发布群福利和活动~
欢迎扫码或者添加微信:argentinaliu 加入我们👇

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-10 13:20:31 HTTP/2.0 GET : https://f.mffb.com.cn/a/458930.html
  2. 运行时间 : 0.121376s [ 吞吐率:8.24req/s ] 内存消耗:5,103.88kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=f4d8b13068ef16c2ec00422d96396ca9
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000648s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000929s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000376s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000453s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000476s ]
  6. SELECT * FROM `set` [ RunTime:0.000291s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000588s ]
  8. SELECT * FROM `article` WHERE `id` = 458930 LIMIT 1 [ RunTime:0.000708s ]
  9. UPDATE `article` SET `lasttime` = 1770700831 WHERE `id` = 458930 [ RunTime:0.005679s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 65 LIMIT 1 [ RunTime:0.000300s ]
  11. SELECT * FROM `article` WHERE `id` < 458930 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.002785s ]
  12. SELECT * FROM `article` WHERE `id` > 458930 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.001385s ]
  13. SELECT * FROM `article` WHERE `id` < 458930 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001341s ]
  14. SELECT * FROM `article` WHERE `id` < 458930 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003553s ]
  15. SELECT * FROM `article` WHERE `id` < 458930 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.006477s ]
0.123142s