Context增加SSLContext属性
This commit is contained in:
@@ -13,6 +13,7 @@ import java.nio.charset.*;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
import org.redkale.convert.bson.*;
|
import org.redkale.convert.bson.*;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
@@ -35,6 +36,9 @@ public class Context {
|
|||||||
//Server的线程池
|
//Server的线程池
|
||||||
protected final ThreadPoolExecutor executor;
|
protected final ThreadPoolExecutor executor;
|
||||||
|
|
||||||
|
//SSL
|
||||||
|
protected final SSLContext sslContext;
|
||||||
|
|
||||||
//ByteBuffer的容量,默认8K
|
//ByteBuffer的容量,默认8K
|
||||||
protected final int bufferCapacity;
|
protected final int bufferCapacity;
|
||||||
|
|
||||||
@@ -74,11 +78,14 @@ public class Context {
|
|||||||
//依赖注入工厂类
|
//依赖注入工厂类
|
||||||
protected final ResourceFactory resourceFactory;
|
protected final ResourceFactory resourceFactory;
|
||||||
|
|
||||||
public Context(long serverStartTime, Logger logger, ThreadPoolExecutor executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool, ObjectPool<Response> responsePool,
|
public Context(long serverStartTime, Logger logger, ThreadPoolExecutor executor, SSLContext sslContext,
|
||||||
final int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory, final PrepareServlet prepare, final int readTimeoutSecond, final int writeTimeoutSecond) {
|
int bufferCapacity, ObjectPool<ByteBuffer> bufferPool, ObjectPool<Response> responsePool,
|
||||||
|
final int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory,
|
||||||
|
final PrepareServlet prepare, final int readTimeoutSecond, final int writeTimeoutSecond) {
|
||||||
this.serverStartTime = serverStartTime;
|
this.serverStartTime = serverStartTime;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
|
this.sslContext = sslContext;
|
||||||
this.bufferCapacity = bufferCapacity;
|
this.bufferCapacity = bufferCapacity;
|
||||||
this.bufferPool = bufferPool;
|
this.bufferPool = bufferPool;
|
||||||
this.responsePool = responsePool;
|
this.responsePool = responsePool;
|
||||||
@@ -97,6 +104,10 @@ public class Context {
|
|||||||
return resourceFactory;
|
return resourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SSLContext getSSLContext() {
|
||||||
|
return sslContext;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMaxbody() {
|
public int getMaxbody() {
|
||||||
return maxbody;
|
return maxbody;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +52,9 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
//服务的根Servlet
|
//服务的根Servlet
|
||||||
protected final PrepareServlet<K, C, R, P, S> prepare;
|
protected final PrepareServlet<K, C, R, P, S> prepare;
|
||||||
|
|
||||||
|
//SSL
|
||||||
|
protected SSLContext sslContext;
|
||||||
|
|
||||||
//服务的上下文对象
|
//服务的上下文对象
|
||||||
protected C context;
|
protected C context;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.nio.charset.*;
|
|||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
import org.redkale.asm.*;
|
import org.redkale.asm.*;
|
||||||
import static org.redkale.asm.Opcodes.*;
|
import static org.redkale.asm.Opcodes.*;
|
||||||
import org.redkale.net.*;
|
import org.redkale.net.*;
|
||||||
@@ -31,11 +32,12 @@ public class HttpContext extends Context {
|
|||||||
|
|
||||||
protected final ConcurrentHashMap<Class, Creator> asyncHandlerCreators = new ConcurrentHashMap<>();
|
protected final ConcurrentHashMap<Class, Creator> asyncHandlerCreators = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public HttpContext(long serverStartTime, Logger logger, ThreadPoolExecutor executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool,
|
public HttpContext(long serverStartTime, Logger logger, ThreadPoolExecutor executor, SSLContext sslContext,
|
||||||
ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory, PrepareServlet prepare,
|
final int bufferCapacity, final ObjectPool<ByteBuffer> bufferPool, ObjectPool<Response> responsePool,
|
||||||
int readTimeoutSecond, int writeTimeoutSecond) {
|
int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory,
|
||||||
super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset,
|
PrepareServlet prepare, int readTimeoutSecond, int writeTimeoutSecond) {
|
||||||
address, resourceFactory, prepare, readTimeoutSecond, writeTimeoutSecond);
|
super(serverStartTime, logger, executor, sslContext, bufferCapacity, bufferPool, responsePool,
|
||||||
|
maxbody, charset, address, resourceFactory, prepare, readTimeoutSecond, writeTimeoutSecond);
|
||||||
|
|
||||||
random.setSeed(Math.abs(System.nanoTime()));
|
random.setSeed(Math.abs(System.nanoTime()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
AtomicLong createResponseCounter = new AtomicLong();
|
AtomicLong createResponseCounter = new AtomicLong();
|
||||||
AtomicLong cycleResponseCounter = new AtomicLong();
|
AtomicLong cycleResponseCounter = new AtomicLong();
|
||||||
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, this.sslContext, rcapacity, bufferPool, responsePool,
|
||||||
this.maxbody, this.charset, this.address, this.resourceFactory, this.prepare, this.readTimeoutSecond, this.writeTimeoutSecond);
|
this.maxbody, this.charset, this.address, this.resourceFactory, this.prepare, this.readTimeoutSecond, this.writeTimeoutSecond);
|
||||||
responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, addrHeader), addHeaders, setHeaders, defCookie, options, ((HttpPrepareServlet) prepare).renders));
|
responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, addrHeader), addHeaders, setHeaders, defCookie, options, ((HttpPrepareServlet) prepare).renders));
|
||||||
return httpcontext;
|
return httpcontext;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
import org.redkale.net.*;
|
import org.redkale.net.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
@@ -21,10 +22,11 @@ import org.redkale.util.*;
|
|||||||
*/
|
*/
|
||||||
public class SncpContext extends Context {
|
public class SncpContext extends Context {
|
||||||
|
|
||||||
public SncpContext(long serverStartTime, Logger logger, ThreadPoolExecutor executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool,
|
public SncpContext(long serverStartTime, Logger logger, ThreadPoolExecutor executor, SSLContext sslContext,
|
||||||
ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory, PrepareServlet prepare,
|
int bufferCapacity, ObjectPool<ByteBuffer> bufferPool, ObjectPool<Response> responsePool,
|
||||||
int readTimeoutSecond, int writeTimeoutSecond) {
|
int maxbody, Charset charset, InetSocketAddress address, ResourceFactory resourceFactory,
|
||||||
super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset,
|
PrepareServlet prepare, int readTimeoutSecond, int writeTimeoutSecond) {
|
||||||
address, resourceFactory, prepare, readTimeoutSecond, writeTimeoutSecond);
|
super(serverStartTime, logger, executor, sslContext, bufferCapacity, bufferPool, responsePool,
|
||||||
|
maxbody, charset, address, resourceFactory, prepare, readTimeoutSecond, writeTimeoutSecond);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResp
|
|||||||
AtomicLong createResponseCounter = new AtomicLong();
|
AtomicLong createResponseCounter = new AtomicLong();
|
||||||
AtomicLong cycleResponseCounter = new AtomicLong();
|
AtomicLong cycleResponseCounter = new AtomicLong();
|
||||||
ObjectPool<Response> responsePool = SncpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
ObjectPool<Response> responsePool = SncpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
||||||
SncpContext sncpcontext = new SncpContext(this.serverStartTime, this.logger, executor, rcapacity, bufferPool, responsePool,
|
SncpContext sncpcontext = new SncpContext(this.serverStartTime, this.logger, executor, this.sslContext, rcapacity, bufferPool, responsePool,
|
||||||
this.maxbody, this.charset, this.address, this.resourceFactory, this.prepare, this.readTimeoutSecond, this.writeTimeoutSecond);
|
this.maxbody, this.charset, this.address, this.resourceFactory, this.prepare, 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user