This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
package com.wentch.redkale.net;
|
||||
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import com.wentch.redkale.watch.*;
|
||||
import java.net.*;
|
||||
@@ -46,6 +48,10 @@ public class Context {
|
||||
|
||||
protected final Logger logger;
|
||||
|
||||
protected final BsonFactory bsonFactory;
|
||||
|
||||
protected final JsonFactory jsonFactory;
|
||||
|
||||
protected final WatchFactory watch;
|
||||
|
||||
public Context(long serverStartTime, Logger logger, ExecutorService executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool, ObjectPool<Response> responsePool,
|
||||
@@ -64,6 +70,8 @@ public class Context {
|
||||
this.watch = watch;
|
||||
this.readTimeoutSecond = readTimeoutSecond;
|
||||
this.writeTimeoutSecond = writeTimeoutSecond;
|
||||
this.jsonFactory = JsonFactory.root();
|
||||
this.bsonFactory = BsonFactory.root();
|
||||
}
|
||||
|
||||
public int getMaxbody() {
|
||||
@@ -114,4 +122,11 @@ public class Context {
|
||||
return writeTimeoutSecond;
|
||||
}
|
||||
|
||||
public JsonConvert getJsonConvert() {
|
||||
return jsonFactory.getConvert();
|
||||
}
|
||||
|
||||
public BsonConvert getBsonConvert() {
|
||||
return bsonFactory.getConvert();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.wentch.redkale.net.http;
|
||||
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.net.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
@@ -24,8 +25,6 @@ public final class HttpContext extends Context {
|
||||
|
||||
protected final String contextPath;
|
||||
|
||||
protected final JsonFactory jsonFactory;
|
||||
|
||||
protected final SecureRandom random = new SecureRandom();
|
||||
|
||||
public HttpContext(long serverStartTime, Logger logger, ExecutorService executor, int bufferCapacity, ObjectPool<ByteBuffer> bufferPool,
|
||||
@@ -34,7 +33,6 @@ public final class HttpContext extends Context {
|
||||
super(serverStartTime, logger, executor, bufferCapacity, bufferPool, responsePool, maxbody, charset,
|
||||
address, prepare, watch, readTimeoutSecond, writeTimeoutSecond);
|
||||
this.contextPath = contextPath;
|
||||
this.jsonFactory = JsonFactory.root();
|
||||
random.setSeed(Math.abs(System.nanoTime()));
|
||||
}
|
||||
|
||||
@@ -60,7 +58,11 @@ public final class HttpContext extends Context {
|
||||
return responsePool;
|
||||
}
|
||||
|
||||
public JsonConvert getJsonConvert() {
|
||||
return jsonFactory.getConvert();
|
||||
protected JsonFactory getJsonFactory() {
|
||||
return jsonFactory;
|
||||
}
|
||||
|
||||
protected BsonFactory getBsonFactory() {
|
||||
return bsonFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public final class HttpServer extends Server {
|
||||
ObjectPool<Response> responsePool = HttpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
||||
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);
|
||||
responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, httpcontext.jsonFactory, addrHeader), addHeaders, setHeaders, defCookie));
|
||||
responsePool.setCreator((Object... params) -> new HttpResponse(httpcontext, new HttpRequest(httpcontext, httpcontext.getJsonFactory(), addrHeader), addHeaders, setHeaders, defCookie));
|
||||
return httpcontext;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class WebSocketNode {
|
||||
return dataNodes;
|
||||
}
|
||||
|
||||
protected abstract int sendMessage(@SncpParameter InetSocketAddress addr, Serializable groupid, boolean recent, Serializable message, boolean last);
|
||||
protected abstract int sendMessage(@SncpTargetAddress InetSocketAddress addr, Serializable groupid, boolean recent, Serializable message, boolean last);
|
||||
|
||||
protected abstract void connect(Serializable groupid, InetSocketAddress addr);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.wentch.redkale.util.AnyValue;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Service对象的封装类
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T>
|
||||
|
||||
@@ -21,6 +21,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
import jdk.internal.org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* 生成Service的本地模式或远程模式Service-Class的工具类
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class SncpClient {
|
||||
for (int i = 0; i < anns.length; i++) {
|
||||
if (anns[i].length > 0) {
|
||||
for (Annotation ann : anns[i]) {
|
||||
if (ann.annotationType() == SncpParameter.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
if (ann.annotationType() == SncpTargetAddress.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
addrIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package com.wentch.redkale.net.sncp;
|
||||
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.net.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import com.wentch.redkale.watch.*;
|
||||
@@ -21,14 +22,12 @@ import java.util.logging.*;
|
||||
*/
|
||||
public final class SncpContext extends Context {
|
||||
|
||||
protected final BsonFactory bsonFactory;
|
||||
|
||||
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);
|
||||
this.bsonFactory = BsonFactory.root();
|
||||
|
||||
}
|
||||
|
||||
protected WatchFactory getWatchFactory() {
|
||||
@@ -43,7 +42,11 @@ public final class SncpContext extends Context {
|
||||
return responsePool;
|
||||
}
|
||||
|
||||
public BsonConvert getBsonConvert() {
|
||||
return bsonFactory.getConvert();
|
||||
protected JsonFactory getJsonFactory() {
|
||||
return jsonFactory;
|
||||
}
|
||||
|
||||
protected BsonFactory getBsonFactory() {
|
||||
return bsonFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class SncpServer extends Server {
|
||||
ObjectPool<Response> responsePool = SncpResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
||||
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);
|
||||
responsePool.setCreator((Object... params) -> new SncpResponse(sncpcontext, new SncpRequest(sncpcontext, sncpcontext.bsonFactory)));
|
||||
responsePool.setCreator((Object... params) -> new SncpResponse(sncpcontext, new SncpRequest(sncpcontext, sncpcontext.getBsonFactory())));
|
||||
return sncpcontext;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
*
|
||||
* SNCP协议中标记为目标地址参数, 该注解只能标记在类型为SocketAddress或其之类的参数上。
|
||||
*
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@@ -18,6 +19,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Documented
|
||||
@Target({PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
public @interface SncpParameter {
|
||||
public @interface SncpTargetAddress {
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sendMessage(@SncpParameter InetSocketAddress addr, Serializable groupid, boolean recent, Serializable message, boolean last) {
|
||||
public int sendMessage(@SncpTargetAddress InetSocketAddress addr, Serializable groupid, boolean recent, Serializable message, boolean last) {
|
||||
final Set<String> engineids = localNodes.get(groupid);
|
||||
if (engineids == null || engineids.isEmpty()) return RETCODE_GROUP_EMPTY;
|
||||
int code = RETCODE_GROUP_EMPTY;
|
||||
|
||||
Reference in New Issue
Block a user