This commit is contained in:
wentch
2016-01-18 12:19:17 +08:00
parent dc15a75f0e
commit 4463cc92a8
17 changed files with 108 additions and 78 deletions

View File

@@ -107,12 +107,8 @@ public final class NodeHttpServer extends NodeServer {
if (ws == null || ws.value().length == 0) continue; if (ws == null || ws.value().length == 0) continue;
final HttpServlet servlet = clazz.newInstance(); final HttpServlet servlet = clazz.newInstance();
factory.inject(servlet, this); factory.inject(servlet, this);
String[] mappings = ws.value(); final String[] mappings = ws.value();
if (ws.repair() && !prefix.isEmpty()) { String pref = ws.repair() ? prefix : "";
for (int i = 0; i < mappings.length; i++) {
mappings[i] = prefix + mappings[i];
}
}
DefaultAnyValue servletConf = (DefaultAnyValue) en.getProperty(); DefaultAnyValue servletConf = (DefaultAnyValue) en.getProperty();
WebInitParam[] webparams = ws.initParams(); WebInitParam[] webparams = ws.initParams();
if (webparams.length > 0) { if (webparams.length > 0) {
@@ -121,8 +117,13 @@ public final class NodeHttpServer extends NodeServer {
servletConf.addValue(webparam.name(), webparam.value()); servletConf.addValue(webparam.name(), webparam.value());
} }
} }
this.httpServer.addHttpServlet(servlet, servletConf, mappings); this.httpServer.addHttpServlet(servlet, pref, servletConf, mappings);
if (ss != null) ss.add(new AbstractMap.SimpleEntry<>(clazz.getName(), mappings)); if (ss != null) {
for (int i = 0; i < mappings.length; i++) {
mappings[i] = pref + mappings[i];
}
ss.add(new AbstractMap.SimpleEntry<>(clazz.getName(), mappings));
}
} }
if (ss != null) { if (ss != null) {
Collections.sort(ss, (AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey())); Collections.sort(ss, (AbstractMap.SimpleEntry<String, String[]> o1, AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));

View File

@@ -13,12 +13,15 @@ import java.util.logging.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
* @param <C> Context的子类型
* @param <R> Request的子类型 * @param <R> Request的子类型
* @param <P> Response的子类型 * @param <P> Response的子类型
*/ */
public abstract class PrepareServlet<R extends Request, P extends Response<R>> extends Servlet<R, P> { public abstract class PrepareServlet<C extends Context, R extends Request<C>, P extends Response<R>> extends Servlet<C, R, P> {
protected final AtomicLong executeCounter = new AtomicLong(); //执行请求次数 protected final AtomicLong executeCounter = new AtomicLong(); //执行请求次数

View File

@@ -17,9 +17,9 @@ import org.redkale.convert.json.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public abstract class Request { public abstract class Request<C extends Context> {
protected final Context context; protected final C context;
protected final BsonConvert bsonConvert; protected final BsonConvert bsonConvert;
@@ -39,7 +39,7 @@ public abstract class Request {
protected final Map<String, Object> attributes = new HashMap<>(); protected final Map<String, Object> attributes = new HashMap<>();
protected Request(Context context) { protected Request(C context) {
this.context = context; this.context = context;
this.bsonConvert = context.getBsonConvert(); this.bsonConvert = context.getBsonConvert();
this.jsonConvert = context.getJsonConvert(); this.jsonConvert = context.getJsonConvert();
@@ -104,7 +104,7 @@ public abstract class Request {
return attributes; return attributes;
} }
public Context getContext() { public C getContext() {
return this.context; return this.context;
} }

View File

@@ -14,17 +14,18 @@ import java.io.IOException;
* 详情见: http://www.redkale.org * 详情见: http://www.redkale.org
* *
* @author zhangjx * @author zhangjx
* @param <C> Context的子类型
* @param <R> Request的子类型 * @param <R> Request的子类型
* @param <P> Response的子类型 * @param <P> Response的子类型
*/ */
public abstract class Servlet<R extends Request, P extends Response<R>> { public abstract class Servlet<C extends Context, R extends Request<? extends C>, P extends Response<R>> {
public void init(Context context, AnyValue config) { public void init(C context, AnyValue config) {
} }
public abstract void execute(R request, P response) throws IOException; public abstract void execute(R request, P response) throws IOException;
public void destroy(Context context, AnyValue config) { public void destroy(C context, AnyValue config) {
} }
} }

View File

@@ -7,7 +7,6 @@ package org.redkale.net.http;
import org.redkale.net.Response; import org.redkale.net.Response;
import org.redkale.net.Request; import org.redkale.net.Request;
import org.redkale.net.Context;
import org.redkale.util.AnyValue; import org.redkale.util.AnyValue;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.*; import java.lang.annotation.*;
@@ -120,8 +119,8 @@ public abstract class BasedHttpServlet extends HttpServlet {
} }
@Override @Override
public void init(Context context, AnyValue config) { public void init(HttpContext context, AnyValue config) {
String path = ((HttpContext) context).getContextPath(); String path = _prefix == null ? "" : _prefix;
WebServlet ws = this.getClass().getAnnotation(WebServlet.class); WebServlet ws = this.getClass().getAnnotation(WebServlet.class);
if (ws != null && !ws.repair()) path = ""; if (ws != null && !ws.repair()) path = "";
HashMap<String, Entry> map = load(); HashMap<String, Entry> map = load();
@@ -194,7 +193,7 @@ public abstract class BasedHttpServlet extends HttpServlet {
FieldVisitor fv; FieldVisitor fv;
MethodVisitor mv; MethodVisitor mv;
AnnotationVisitor av0; AnnotationVisitor av0;
final String factfield = "factServlet"; final String factfield = "_factServlet";
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null); cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
{ {
fv = cw.visitField(ACC_PUBLIC, factfield, interDesc, null, null); fv = cw.visitField(ACC_PUBLIC, factfield, interDesc, null, null);

View File

@@ -17,26 +17,22 @@ import org.redkale.watch.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public class HttpContext extends Context { public class HttpContext extends Context {
protected final String contextPath;
protected final SecureRandom random = new SecureRandom(); protected final SecureRandom random = new SecureRandom();
public HttpContext(long serverStartTime, Logger logger, ExecutorService executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool, public HttpContext(long serverStartTime, Logger logger, ExecutorService executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool,
ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, PrepareServlet prepare, ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, PrepareServlet prepare,
WatchFactory watch, int readTimeoutSecond, int writeTimeoutSecond, String contextPath) { WatchFactory watch, int readTimeoutSecond, int writeTimeoutSecond) {
super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset, super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset,
address, prepare, watch, readTimeoutSecond, writeTimeoutSecond); address, prepare, watch, readTimeoutSecond, writeTimeoutSecond);
this.contextPath = contextPath;
random.setSeed(Math.abs(System.nanoTime()));
}
public String getContextPath() { random.setSeed(Math.abs(System.nanoTime()));
return this.contextPath;
} }
protected String createSessionid() { protected String createSessionid() {

View File

@@ -23,7 +23,7 @@ import org.redkale.watch.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class HttpPrepareServlet extends PrepareServlet<HttpRequest, HttpResponse<HttpRequest>> { public final class HttpPrepareServlet extends PrepareServlet<HttpContext, HttpRequest, HttpResponse<HttpRequest>> {
private final List<HttpServlet> servlets = new ArrayList<>(); private final List<HttpServlet> servlets = new ArrayList<>();
@@ -34,11 +34,11 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpRequest, HttpRe
private HttpServlet resourceHttpServlet = new HttpResourceServlet(); private HttpServlet resourceHttpServlet = new HttpResourceServlet();
@Override @Override
public void init(Context context, AnyValue config) { public void init(HttpContext context, AnyValue config) {
this.servlets.stream().forEach(s -> { this.servlets.stream().forEach(s -> {
s.init(context, s._conf); s.init(context, s._conf);
}); });
final WatchFactory watch = ((HttpContext) context).getWatchFactory(); final WatchFactory watch = context.getWatchFactory();
if (watch != null) { if (watch != null) {
this.servlets.stream().forEach(s -> { this.servlets.stream().forEach(s -> {
watch.inject(s); watch.inject(s);
@@ -83,14 +83,15 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpRequest, HttpRe
} }
} }
public void addHttpServlet(HttpServlet servlet, AnyValue conf, String... mappings) { public void addHttpServlet(HttpServlet servlet, String prefix, AnyValue conf, String... mappings) {
if (prefix == null) prefix = "";
for (String mapping : mappings) { for (String mapping : mappings) {
if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式)) if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式))
if (mapping.charAt(0) != '^') mapping = '^' + mapping; if (mapping.charAt(0) != '^') mapping = '^' + mapping;
if (mapping.endsWith("/*")) { if (mapping.endsWith("/*")) {
mapping = mapping.substring(0, mapping.length() - 1) + ".*"; mapping = prefix + mapping.substring(0, mapping.length() - 1) + ".*";
} else { } else {
mapping += "$"; mapping = prefix + mapping + "$";
} }
if (regArray == null) { if (regArray == null) {
regArray = new SimpleEntry[1]; regArray = new SimpleEntry[1];
@@ -100,10 +101,11 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpRequest, HttpRe
regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet); regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet);
} }
} else if (mapping != null && !mapping.isEmpty()) { } else if (mapping != null && !mapping.isEmpty()) {
strmaps.put(mapping, servlet); strmaps.put(prefix + mapping, servlet);
} }
} }
servlet._conf = conf; servlet._conf = conf;
servlet._prefix = prefix == null ? "" : prefix;
this.servlets.add(servlet); this.servlets.add(servlet);
} }
@@ -124,7 +126,7 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpRequest, HttpRe
} }
@Override @Override
public void destroy(Context context, AnyValue config) { public void destroy(HttpContext context, AnyValue config) {
this.resourceHttpServlet.destroy(context, config); this.resourceHttpServlet.destroy(context, config);
this.servlets.stream().forEach(s -> { this.servlets.stream().forEach(s -> {
s.destroy(context, s._conf); s.destroy(context, s._conf);

View File

@@ -23,19 +23,17 @@ import org.redkale.net.*;
* 获取页号: int page = request.getRequstURIPath("page:", 1); * 获取页号: int page = request.getRequstURIPath("page:", 1);
* 获取行数: int size = request.getRequstURIPath("size:", 10); * 获取行数: int size = request.getRequstURIPath("size:", 10);
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public class HttpRequest extends Request { public class HttpRequest extends Request<HttpContext> {
protected static final Charset UTF8 = Charset.forName("UTF-8"); protected static final Charset UTF8 = Charset.forName("UTF-8");
protected static final String SESSIONID_NAME = "JSESSIONID"; protected static final String SESSIONID_NAME = "JSESSIONID";
private static final byte[] flashRequestContent1 = "<policy-file-request/>\0".getBytes();
private static final byte[] flashRequestContent2 = "<policy-file-request/>".getBytes();
private String method; private String method;
private String protocol; private String protocol;
@@ -68,7 +66,7 @@ public class HttpRequest extends Request {
private final String remoteAddrHeader; private final String remoteAddrHeader;
public HttpRequest(Context context, String remoteAddrHeader) { public HttpRequest(HttpContext context, String remoteAddrHeader) {
super(context); super(context);
this.remoteAddrHeader = remoteAddrHeader; this.remoteAddrHeader = remoteAddrHeader;
} }
@@ -226,11 +224,6 @@ public class HttpRequest extends Request {
super.removeProperty(name); super.removeProperty(name);
} }
@Override
public HttpContext getContext() {
return (HttpContext) this.context;
}
public String getRemoteAddr() { public String getRemoteAddr() {
if (remoteAddrHeader != null) { if (remoteAddrHeader != null) {
String val = getHeader(remoteAddrHeader); String val = getHeader(remoteAddrHeader);

View File

@@ -16,12 +16,13 @@ import java.util.concurrent.atomic.*;
import java.util.function.*; import java.util.function.*;
import java.util.logging.*; import java.util.logging.*;
import java.util.regex.*; import java.util.regex.*;
import org.redkale.net.*;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public final class HttpResourceServlet extends HttpServlet { public final class HttpResourceServlet extends HttpServlet {
@@ -98,7 +99,7 @@ public final class HttpResourceServlet extends HttpServlet {
protected Predicate<String> ranges; protected Predicate<String> ranges;
@Override @Override
public void init(Context context, AnyValue config) { public void init(HttpContext context, AnyValue config) {
if (config != null) { if (config != null) {
String rootstr = config.getValue("webroot", "root"); String rootstr = config.getValue("webroot", "root");
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) { if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
@@ -140,7 +141,7 @@ public final class HttpResourceServlet extends HttpServlet {
} }
@Override @Override
public void destroy(Context context, AnyValue config) { public void destroy(HttpContext context, AnyValue config) {
if (this.watchThread != null) { if (this.watchThread != null) {
try { try {
this.watchThread.watcher.close(); this.watchThread.watcher.close();

View File

@@ -15,13 +15,13 @@ import org.redkale.watch.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public final class HttpServer extends Server { public final class HttpServer extends Server {
private String contextPath;
public HttpServer() { public HttpServer() {
this(System.currentTimeMillis(), null); this(System.currentTimeMillis(), null);
} }
@@ -34,11 +34,10 @@ public final class HttpServer extends Server {
public void init(AnyValue config) throws Exception { public void init(AnyValue config) throws Exception {
super.init(config); super.init(config);
AnyValue conf = config == null ? null : config.getAnyValue("servlets"); AnyValue conf = config == null ? null : config.getAnyValue("servlets");
this.contextPath = conf == null ? "" : conf.getValue("path", "");
} }
public void addHttpServlet(HttpServlet servlet, AnyValue conf, String... mappings) { public void addHttpServlet(HttpServlet servlet, final String prefix, AnyValue conf, String... mappings) {
((HttpPrepareServlet) this.prepare).addHttpServlet(servlet, conf, mappings); ((HttpPrepareServlet) this.prepare).addHttpServlet(servlet, prefix, conf, mappings);
} }
@Override @Override
@@ -120,7 +119,7 @@ public final class HttpServer extends Server {
AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("HTTP_" + port + ".Response.cycleCounter"); AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("HTTP_" + port + ".Response.cycleCounter");
ObjectPool<Response> responsePool = HttpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null); ObjectPool<Response> responsePool = HttpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
HttpContext httpcontext = new HttpContext(this.serverStartTime, this.logger, executor, rcapacity, bufferPool, responsePool, HttpContext httpcontext = new HttpContext(this.serverStartTime, this.logger, executor, rcapacity, bufferPool, responsePool,
this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond, contextPath); this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond);
responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, addrHeader), addHeaders, setHeaders, defCookie)); responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, addrHeader), addHeaders, setHeaders, defCookie));
return httpcontext; return httpcontext;
} }

View File

@@ -10,13 +10,17 @@ import org.redkale.util.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public abstract class HttpServlet extends Servlet<HttpRequest, HttpResponse<HttpRequest>> { public abstract class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse<HttpRequest>> {
AnyValue _conf; //当前HttpServlet的配置 AnyValue _conf; //当前HttpServlet的配置
String _prefix = ""; //当前HttpServlet的path前缀
@Override @Override
public final boolean equals(Object obj) { public final boolean equals(Object obj) {
return obj != null && obj.getClass() == this.getClass(); return obj != null && obj.getClass() == this.getClass();

View File

@@ -13,7 +13,6 @@ import java.security.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import javax.annotation.*; import javax.annotation.*;
import org.redkale.net.*;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
@@ -64,7 +63,7 @@ public abstract class WebSocketServlet extends HttpServlet {
protected WebSocketEngine engine; protected WebSocketEngine engine;
@Override @Override
public void init(Context context, AnyValue conf) { public void init(HttpContext context, AnyValue conf) {
InetSocketAddress addr = context.getServerAddress(); InetSocketAddress addr = context.getServerAddress();
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + name() + "]", this.node, logger); this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + name() + "]", this.node, logger);
this.node.putWebSocketEngine(engine); this.node.putWebSocketEngine(engine);
@@ -73,7 +72,7 @@ public abstract class WebSocketServlet extends HttpServlet {
} }
@Override @Override
public void destroy(Context context, AnyValue conf) { public void destroy(HttpContext context, AnyValue conf) {
this.node.destroy(conf); this.node.destroy(conf);
super.destroy(context, conf); super.destroy(context, conf);
engine.close(); engine.close();

View File

@@ -0,0 +1,29 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.net.sncp;
import java.net.*;
import java.nio.*;
import java.nio.charset.*;
import java.util.concurrent.*;
import java.util.logging.*;
import org.redkale.net.*;
import org.redkale.util.*;
import org.redkale.watch.*;
/**
*
* @author zhangjx
*/
public class SncpContext extends Context {
public SncpContext(long serverStartTime, Logger logger, ExecutorService executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool,
ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, PrepareServlet prepare,
WatchFactory watch, int readTimeoutSecond, int writeTimeoutSecond) {
super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset,
address, prepare, watch, readTimeoutSecond, writeTimeoutSecond);
}
}

View File

@@ -6,7 +6,6 @@
package org.redkale.net.sncp; package org.redkale.net.sncp;
import org.redkale.net.PrepareServlet; import org.redkale.net.PrepareServlet;
import org.redkale.net.Context;
import org.redkale.util.AnyValue; import org.redkale.util.AnyValue;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@@ -15,10 +14,12 @@ import org.redkale.util.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public class SncpPrepareServlet extends PrepareServlet<SncpRequest, SncpResponse> { public class SncpPrepareServlet extends PrepareServlet<SncpContext, SncpRequest, SncpResponse> {
private static final ByteBuffer pongBuffer = ByteBuffer.wrap("PONG".getBytes()).asReadOnlyBuffer(); private static final ByteBuffer pongBuffer = ByteBuffer.wrap("PONG".getBytes()).asReadOnlyBuffer();
@@ -50,7 +51,7 @@ public class SncpPrepareServlet extends PrepareServlet<SncpRequest, SncpResponse
} }
@Override @Override
public void init(Context context, AnyValue config) { public void init(SncpContext context, AnyValue config) {
Collection<Map<DLong, SncpServlet>> values = this.maps.values(); Collection<Map<DLong, SncpServlet>> values = this.maps.values();
values.stream().forEach((en) -> { values.stream().forEach((en) -> {
en.values().stream().forEach(s -> s.init(context, s.conf)); en.values().stream().forEach(s -> s.init(context, s.conf));
@@ -58,7 +59,7 @@ public class SncpPrepareServlet extends PrepareServlet<SncpRequest, SncpResponse
} }
@Override @Override
public void destroy(Context context, AnyValue config) { public void destroy(SncpContext context, AnyValue config) {
Collection<Map<DLong, SncpServlet>> values = this.maps.values(); Collection<Map<DLong, SncpServlet>> values = this.maps.values();
values.stream().forEach((en) -> { values.stream().forEach((en) -> {
en.values().stream().forEach(s -> s.destroy(context, s.conf)); en.values().stream().forEach(s -> s.destroy(context, s.conf));

View File

@@ -16,7 +16,7 @@ import org.redkale.util.*;
* <p> 详情见: http://www.redkale.org * <p> 详情见: http://www.redkale.org
* @author zhangjx * @author zhangjx
*/ */
public final class SncpRequest extends Request { public final class SncpRequest extends Request<SncpContext> {
public static final int HEADER_SIZE = 72; public static final int HEADER_SIZE = 72;
@@ -42,7 +42,7 @@ public final class SncpRequest extends Request {
private byte[] bufferbytes = new byte[6]; private byte[] bufferbytes = new byte[6];
protected SncpRequest(Context context) { protected SncpRequest(SncpContext context) {
super(context); super(context);
this.convert = context.getBsonConvert(); this.convert = context.getBsonConvert();
} }

View File

@@ -62,7 +62,7 @@ public final class SncpServer extends Server {
AtomicLong createResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SNCP_" + port + ".Response.creatCounter"); AtomicLong createResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SNCP_" + port + ".Response.creatCounter");
AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SNCP_" + port + ".Response.cycleCounter"); AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SNCP_" + port + ".Response.cycleCounter");
ObjectPool<Response> responsePool = SncpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null); ObjectPool<Response> responsePool = SncpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
Context sncpcontext = new Context(this.serverStartTime, this.logger, executor, rcapacity, bufferPool, responsePool, SncpContext sncpcontext = new SncpContext(this.serverStartTime, this.logger, executor, rcapacity, bufferPool, responsePool,
this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond); this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond);
responsePool.setCreator((Object... params) -> new SncpResponse(sncpcontext, new SncpRequest(sncpcontext))); responsePool.setCreator((Object... params) -> new SncpResponse(sncpcontext, new SncpRequest(sncpcontext)));
return sncpcontext; return sncpcontext;

View File

@@ -5,15 +5,17 @@
*/ */
package org.redkale.net.sncp; package org.redkale.net.sncp;
import org.redkale.net.Servlet; import org.redkale.net.*;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public abstract class SncpServlet extends Servlet<SncpRequest, SncpResponse> implements Comparable<SncpServlet> { public abstract class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse> implements Comparable<SncpServlet> {
AnyValue conf; AnyValue conf;
@@ -30,7 +32,7 @@ public abstract class SncpServlet extends Servlet<SncpRequest, SncpResponse> imp
public final int hashCode() { public final int hashCode() {
return this.getClass().hashCode(); return this.getClass().hashCode();
} }
@Override @Override
public int compareTo(SncpServlet o) { public int compareTo(SncpServlet o) {
return 0; return 0;