All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.yoojia.halo.actions.HaloAction Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.github.yoojia.halo.actions;

import com.github.yoojia.halo.HaloChain;
import com.github.yoojia.halo.HaloRequest;
import com.github.yoojia.halo.HaloResponse;
import com.github.yoojia.halo.supports.*;
import com.github.yoojia.halo.utils.SystemTime;

/**
 * @author YOOJIA.CHEN ([email protected])
 */
public final class HaloAction extends HaloModule {

    private final ActionManager mManager = new ActionManager();

    @Override
    public void init(Context context, Config pluginConfig) {
        mLogger.debug("Init...");
        final long start = System.nanoTime();
        context.getClassScanner().walkClasses(new FilterScanner<>(Action.class, Handle.class, mManager));
        SystemTime.log(start, "HaloAction.init");
    }

    @Override
    public void onService(HaloRequest request, HaloResponse response, KernelChain bridgeChain) throws Exception {
        final long start = System.nanoTime();
        try{
            final ActionProcessor processor = mManager.findMatched(request.method, request.resources);
            if(processor != null){
                final HttpChain chain = new HttpChain();
                request.userParams.putAll(processor.parseParams(request.resources));
                processor.perform(request, response, chain);
                if(chain.isNextDisabled()) {
                    return;
                }
            }
        } finally {
            SystemTime.log(start, String.format("HaloAction.process(:%s)", request.uri));
        }
        bridgeChain.onService(request, response, bridgeChain);
    }

    @Override
    public void onStartup(Context context) {
        mManager.rebuild();
    }

    @Override
    public void onShutdown(Context context) {
        mManager.clear();
    }

    private class HttpChain extends HaloChain {
        @Override
        public boolean isNextDisabled() {
            return super.isNextDisabled();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy