com.github.yoojia.halo.actions.HaloAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of halo-core Show documentation
Show all versions of halo-core Show documentation
A FAST && THIN && HIGH SCALABLE Java web framework
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();
}
}
}