This commit is contained in:
RedKale
2016-02-22 10:46:49 +08:00
parent 736f6b54e3
commit e632280d44
12 changed files with 42 additions and 113 deletions

View File

@@ -23,17 +23,17 @@ import org.redkale.util.*;
* @param <R> Request的子类型 * @param <R> Request的子类型
* @param <P> Response的子类型 * @param <P> Response的子类型
*/ */
public abstract class PrepareServlet<K extends Serializable, C extends Context, R extends Request<C>, P extends Response<C, R>> extends Servlet<C, R, P> { public abstract class PrepareServlet<K extends Serializable, C extends Context, R extends Request<C>, P extends Response<C, R>, S extends Servlet<C, R, P>> extends Servlet<C, R, P> {
protected final AtomicLong executeCounter = new AtomicLong(); //执行请求次数 protected final AtomicLong executeCounter = new AtomicLong(); //执行请求次数
protected final AtomicLong illRequestCounter = new AtomicLong(); //错误请求次数 protected final AtomicLong illRequestCounter = new AtomicLong(); //错误请求次数
protected final List<Servlet<C, R, P>> servlets = new ArrayList<>(); protected final Set<S> servlets = new HashSet<>();
protected final Map<K, Servlet<C, R, P>> mappings = new HashMap<>(); protected final Map<K, S> mappings = new HashMap<>();
public abstract <S extends Servlet<C, R, P>> void addServlet(S servlet, Object attachment, AnyValue conf, K... mappings); public abstract void addServlet(S servlet, Object attachment, AnyValue conf, K... mappings);
public final void prepare(final ByteBuffer buffer, final R request, final P response) throws IOException { public final void prepare(final ByteBuffer buffer, final R request, final P response) throws IOException {
executeCounter.incrementAndGet(); executeCounter.incrementAndGet();

View File

@@ -24,7 +24,7 @@ import org.redkale.watch.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public abstract class Server<K extends Serializable, C extends Context, R extends Request<C>, P extends Response<C, R>> { public abstract class Server<K extends Serializable, C extends Context, R extends Request<C>, P extends Response<C, R>, S extends Servlet<C, R, P>> {
public static final String RESNAME_SERVER_ROOT = "SERVER_ROOT"; public static final String RESNAME_SERVER_ROOT = "SERVER_ROOT";
@@ -37,7 +37,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
protected final String protocol; protected final String protocol;
protected final PrepareServlet<K, C, R, P> prepare; protected final PrepareServlet<K, C, R, P, S> prepare;
protected C context; protected C context;
@@ -69,7 +69,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
private ScheduledThreadPoolExecutor scheduler; private ScheduledThreadPoolExecutor scheduler;
protected Server(long serverStartTime, String protocol, PrepareServlet<K, C, R, P> servlet, final WatchFactory watch) { protected Server(long serverStartTime, String protocol, PrepareServlet<K, C, R, P, S> servlet, final WatchFactory watch) {
this.serverStartTime = serverStartTime; this.serverStartTime = serverStartTime;
this.protocol = protocol; this.protocol = protocol;
this.prepare = servlet; this.prepare = servlet;
@@ -116,7 +116,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
return this.logger; return this.logger;
} }
public <S extends Servlet<C, R, P>> void addServlet(S servlet, final Object attachment, AnyValue conf, K... mappings) { public void addServlet(S servlet, final Object attachment, AnyValue conf, K... mappings) {
this.prepare.addServlet(servlet, attachment, conf, mappings); this.prepare.addServlet(servlet, attachment, conf, mappings);
} }

View File

@@ -23,7 +23,7 @@ import org.redkale.watch.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext, HttpRequest, HttpResponse> { public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext, HttpRequest, HttpResponse, HttpServlet> {
private SimpleEntry<Predicate<String>, HttpServlet>[] regArray = new SimpleEntry[0]; private SimpleEntry<Predicate<String>, HttpServlet>[] regArray = new SimpleEntry[0];
@@ -31,7 +31,7 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
@Override @Override
public void init(HttpContext context, AnyValue config) { public void init(HttpContext context, AnyValue config) {
this.servlets.stream().forEach(s -> { this.servlets.forEach(s -> {
if (s instanceof WebSocketServlet) { if (s instanceof WebSocketServlet) {
((WebSocketServlet) s).preInit(context, getServletConf(s)); ((WebSocketServlet) s).preInit(context, getServletConf(s));
} else if (s instanceof BasedHttpServlet) { } else if (s instanceof BasedHttpServlet) {
@@ -41,7 +41,7 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
}); });
final WatchFactory watch = context.getWatchFactory(); final WatchFactory watch = context.getWatchFactory();
if (watch != null) { if (watch != null) {
this.servlets.stream().forEach(s -> { this.servlets.forEach(s -> {
watch.inject(s); watch.inject(s);
}); });
} }
@@ -85,9 +85,8 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
} }
@Override @Override
public <S extends Servlet<HttpContext, HttpRequest, HttpResponse>> void addServlet(S servlet0, Object prefix, AnyValue conf, String... mappings) { public void addServlet(HttpServlet servlet, Object prefix, AnyValue conf, String... mappings) {
if (prefix == null) prefix = ""; if (prefix == null) prefix = "";
HttpServlet servlet = (HttpServlet) servlet0;
for (String mapping : mappings) { for (String mapping : mappings) {
if (!prefix.toString().isEmpty()) mapping = prefix + mapping; if (!prefix.toString().isEmpty()) mapping = prefix + mapping;
if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式)) if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式))
@@ -132,7 +131,7 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
@Override @Override
public void destroy(HttpContext 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.forEach(s -> {
s.destroy(context, getServletConf(s)); s.destroy(context, getServletConf(s));
if (s instanceof WebSocketServlet) { if (s instanceof WebSocketServlet) {
((WebSocketServlet) s).postDestroy(context, getServletConf(s)); ((WebSocketServlet) s).postDestroy(context, getServletConf(s));

View File

@@ -20,7 +20,7 @@ import org.redkale.watch.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class HttpServer extends Server<String, HttpContext, HttpRequest, HttpResponse> { public final class HttpServer extends Server<String, HttpContext, HttpRequest, HttpResponse, HttpServlet> {
public HttpServer() { public HttpServer() {
this(System.currentTimeMillis(), null); this(System.currentTimeMillis(), null);

View File

@@ -33,12 +33,6 @@ import org.redkale.service.DynRemote;
*/ */
public abstract class Sncp { public abstract class Sncp {
private static final java.lang.reflect.Type GROUPS_TYPE1 = new TypeToken<Set<String>>() {
}.getType();
private static final java.lang.reflect.Type GROUPS_TYPE2 = new TypeToken<String[]>() {
}.getType();
static final String LOCALPREFIX = "_DynLocal"; static final String LOCALPREFIX = "_DynLocal";
static final String REMOTEPREFIX = "_DynRemote"; static final String REMOTEPREFIX = "_DynRemote";
@@ -725,7 +719,7 @@ public abstract class Sncp {
try { try {
Field e = newClazz.getDeclaredField("_client"); Field e = newClazz.getDeclaredField("_client");
e.setAccessible(true); e.setAccessible(true);
client = new SncpClient(name, executor, hash(serviceClass), false, newClazz, clientAddress); client = new SncpClient(name, serviceClass, executor, false, newClazz, clientAddress);
e.set(rs, client); e.set(rs, client);
} catch (NoSuchFieldException ne) { } catch (NoSuchFieldException ne) {
} }
@@ -734,7 +728,7 @@ public abstract class Sncp {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(newClazz.getName()).append("{name = '").append(name).append("'"); sb.append(newClazz.getName()).append("{name = '").append(name).append("'");
if (client != null) { if (client != null) {
sb.append(", nameid = ").append(client.getNameid()).append(", serviceid = ").append(client.getServiceid()); sb.append(", serviceid = ").append(client.getServiceid());
sb.append(", action.size = ").append(client.getActionCount()); sb.append(", action.size = ").append(client.getActionCount());
List<String> groups = new ArrayList<>(); List<String> groups = new ArrayList<>();
if (sameGroupTransport != null) groups.add(sameGroupTransport.getName()); if (sameGroupTransport != null) groups.add(sameGroupTransport.getName());
@@ -857,7 +851,7 @@ public abstract class Sncp {
final String anyValueDesc = Type.getDescriptor(AnyValue.class); final String anyValueDesc = Type.getDescriptor(AnyValue.class);
ClassLoader loader = Sncp.class.getClassLoader(); ClassLoader loader = Sncp.class.getClassLoader();
String newDynName = supDynName.substring(0, supDynName.lastIndexOf('/') + 1) + REMOTEPREFIX + serviceClass.getSimpleName(); String newDynName = supDynName.substring(0, supDynName.lastIndexOf('/') + 1) + REMOTEPREFIX + serviceClass.getSimpleName();
final SncpClient client = new SncpClient(name, executor, hash(serviceClass), true, realed ? createLocalServiceClass(name, serviceClass) : serviceClass, clientAddress); final SncpClient client = new SncpClient(name, serviceClass, executor, true, realed ? createLocalServiceClass(name, serviceClass) : serviceClass, clientAddress);
try { try {
Class newClazz = Class.forName(newDynName.replace('/', '.')); Class newClazz = Class.forName(newDynName.replace('/', '.'));
T rs = (T) newClazz.newInstance(); T rs = (T) newClazz.newInstance();
@@ -870,7 +864,7 @@ public abstract class Sncp {
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(newClazz.getName()).append("{name = '").append(name); sb.append(newClazz.getName()).append("{name = '").append(name);
sb.append("', nameid = ").append(client.getNameid()).append(", serviceid = ").append(client.getServiceid()); sb.append("', serviceid = ").append(client.getServiceid());
sb.append(", action.size = ").append(client.getActionCount()); sb.append(", action.size = ").append(client.getActionCount());
sb.append(", address = ").append(clientAddress).append(", groups = ").append(transport == null ? null : transport.getName()); sb.append(", address = ").append(clientAddress).append(", groups = ").append(transport == null ? null : transport.getName());
sb.append(", remoteaddrs = ").append(transport == null ? null : Arrays.asList(transport.getRemoteAddresses())); sb.append(", remoteaddrs = ").append(transport == null ? null : Arrays.asList(transport.getRemoteAddresses()));
@@ -1089,7 +1083,7 @@ public abstract class Sncp {
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(newClazz.getName()).append("{name = '").append(name); sb.append(newClazz.getName()).append("{name = '").append(name);
sb.append("', nameid = ").append(client.getNameid()).append(", serviceid = ").append(client.getServiceid()); sb.append("', serviceid = ").append(client.getServiceid());
sb.append(", action.size = ").append(client.getActionCount()); sb.append(", action.size = ").append(client.getActionCount());
sb.append(", address = ").append(clientAddress).append(", groups = ").append(transport == null ? null : transport.getName()); sb.append(", address = ").append(clientAddress).append(", groups = ").append(transport == null ? null : transport.getName());
sb.append(", remotes = ").append(transport == null ? null : Arrays.asList(transport.getRemoteAddresses())); sb.append(", remotes = ").append(transport == null ? null : Arrays.asList(transport.getRemoteAddresses()));

View File

@@ -135,21 +135,18 @@ public final class SncpClient {
protected final DLong serviceid; protected final DLong serviceid;
protected final DLong nameid;
protected final SncpAction[] actions; protected final SncpAction[] actions;
protected final Consumer<Runnable> executor; protected final Consumer<Runnable> executor;
public SncpClient(final String serviceName, final Consumer<Runnable> executor, final DLong serviceid, boolean remote, public <T extends Service> SncpClient(final String serviceName, final Class<T> serviceType, final Consumer<Runnable> executor, boolean remote,
final Class serviceClass, final InetSocketAddress clientAddress) { final Class serviceClass, final InetSocketAddress clientAddress) {
this.remote = remote; this.remote = remote;
this.executor = executor; this.executor = executor;
this.serviceClass = serviceClass; this.serviceClass = serviceClass;
this.clientAddress = clientAddress; this.clientAddress = clientAddress;
this.name = serviceName; this.name = serviceName;
this.nameid = Sncp.hash(serviceName); this.serviceid = Sncp.hash(serviceType.getName() + ':' + serviceName);
this.serviceid = serviceid;
final List<SncpAction> methodens = new ArrayList<>(); final List<SncpAction> methodens = new ArrayList<>();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
for (java.lang.reflect.Method method : parseMethod(serviceClass)) { for (java.lang.reflect.Method method : parseMethod(serviceClass)) {
@@ -165,10 +162,6 @@ public final class SncpClient {
return clientAddress; return clientAddress;
} }
public DLong getNameid() {
return nameid;
}
public DLong getServiceid() { public DLong getServiceid() {
return serviceid; return serviceid;
} }
@@ -181,8 +174,8 @@ public final class SncpClient {
public String toString() { public String toString() {
String service = serviceClass.getName(); String service = serviceClass.getName();
if (remote) service = service.replace(Sncp.LOCALPREFIX, Sncp.REMOTEPREFIX); if (remote) service = service.replace(Sncp.LOCALPREFIX, Sncp.REMOTEPREFIX);
return this.getClass().getSimpleName() + "(service = " + service + ", serviceid = " + serviceid + ", nameid = " + nameid return this.getClass().getSimpleName() + "(service = " + service + ", serviceid = " + serviceid + ", name = '" + name
+ ", name = '" + name + "', address = " + (clientAddress == null ? "" : (clientAddress.getHostString() + ":" + clientAddress.getPort())) + "', address = " + (clientAddress == null ? "" : (clientAddress.getHostString() + ":" + clientAddress.getPort()))
+ ", actions.size = " + actions.length + ")"; + ", actions.size = " + actions.length + ")";
} }
@@ -449,8 +442,6 @@ public final class SncpClient {
if (buffer.getChar() != HEADER_SIZE) throw new RuntimeException("sncp(" + action.method + ") buffer receive header.length not " + HEADER_SIZE); if (buffer.getChar() != HEADER_SIZE) throw new RuntimeException("sncp(" + action.method + ") buffer receive header.length not " + HEADER_SIZE);
DLong rserviceid = DLong.read(buffer); DLong rserviceid = DLong.read(buffer);
if (!rserviceid.equals(serviceid)) throw new RuntimeException("sncp(" + action.method + ") response.serviceid = " + serviceid + ", but request.serviceid =" + rserviceid); if (!rserviceid.equals(serviceid)) throw new RuntimeException("sncp(" + action.method + ") response.serviceid = " + serviceid + ", but request.serviceid =" + rserviceid);
DLong rnameid = DLong.read(buffer);
if (!rnameid.equals(nameid)) throw new RuntimeException("sncp(" + action.method + ") response.nameid = " + nameid + ", but receive nameid =" + rnameid);
DLong raction = DLong.read(buffer); DLong raction = DLong.read(buffer);
if (!action.actionid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")"); if (!action.actionid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")");
buffer.getInt(); //地址 buffer.getInt(); //地址
@@ -464,7 +455,6 @@ public final class SncpClient {
buffer.putLong(seqid); //序列号 buffer.putLong(seqid); //序列号
buffer.putChar((char) HEADER_SIZE); //header长度 buffer.putChar((char) HEADER_SIZE); //header长度
DLong.write(buffer, this.serviceid); DLong.write(buffer, this.serviceid);
DLong.write(buffer, this.nameid);
DLong.write(buffer, actionid); DLong.write(buffer, actionid);
buffer.put(addrBytes); buffer.put(addrBytes);
buffer.putChar((char) this.addrPort); buffer.putChar((char) this.addrPort);

View File

@@ -45,8 +45,6 @@ public final class SncpDynServlet extends SncpServlet {
private final DLong serviceid; private final DLong serviceid;
private final DLong nameid;
private final HashMap<DLong, SncpServletAction> actions = new HashMap<>(); private final HashMap<DLong, SncpServletAction> actions = new HashMap<>();
private Supplier<ByteBuffer> bufferSupplier; private Supplier<ByteBuffer> bufferSupplier;
@@ -54,8 +52,7 @@ public final class SncpDynServlet extends SncpServlet {
public SncpDynServlet(final BsonConvert convert, final String serviceName, final Class<? extends Service> type, final Service service) { public SncpDynServlet(final BsonConvert convert, final String serviceName, final Class<? extends Service> type, final Service service) {
this.serviceName = serviceName; this.serviceName = serviceName;
this.type = type; this.type = type;
this.nameid = Sncp.hash(serviceName); this.serviceid = Sncp.hash(type.getName() + ':' + serviceName);
this.serviceid = Sncp.hash(type);
Set<DLong> actionids = new HashSet<>(); Set<DLong> actionids = new HashSet<>();
for (java.lang.reflect.Method method : service.getClass().getMethods()) { for (java.lang.reflect.Method method : service.getClass().getMethods()) {
if (method.isSynthetic()) continue; if (method.isSynthetic()) continue;
@@ -90,14 +87,10 @@ public final class SncpDynServlet extends SncpServlet {
for (int i = 0; i < maxNameLength - serviceName.length(); i++) { for (int i = 0; i < maxNameLength - serviceName.length(); i++) {
sb.append(' '); sb.append(' ');
} }
sb.append(", nameid=").append(nameid).append(", actions.size=").append(actions.size() > 9 ? "" : " ").append(actions.size()).append(")"); sb.append(", actions.size=").append(actions.size() > 9 ? "" : " ").append(actions.size()).append(")");
return sb.toString(); return sb.toString();
} }
@Override
public DLong getNameid() {
return nameid;
}
@Override @Override
public DLong getServiceid() { public DLong getServiceid() {

View File

@@ -10,7 +10,6 @@ import org.redkale.util.AnyValue;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.*; import java.util.*;
import org.redkale.net.*;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
@@ -20,57 +19,37 @@ import org.redkale.util.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public class SncpPrepareServlet extends PrepareServlet<DLong, SncpContext, SncpRequest, SncpResponse> { public class SncpPrepareServlet extends PrepareServlet<DLong, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
private static final ByteBuffer pongBuffer = ByteBuffer.wrap("PONG".getBytes()).asReadOnlyBuffer(); private static final ByteBuffer pongBuffer = ByteBuffer.wrap("PONG".getBytes()).asReadOnlyBuffer();
private final Map<DLong, Map<DLong, SncpServlet>> maps = new HashMap<>();
private final Map<DLong, SncpServlet> singlemaps = new HashMap<>();
@Override @Override
public <S extends Servlet<SncpContext, SncpRequest, SncpResponse>> void addServlet(S servlet, Object attachment, AnyValue conf, DLong... mappings) { public void addServlet(SncpServlet servlet, Object attachment, AnyValue conf, DLong... mappings) {
addServlet((SncpServlet) servlet, conf); addServlet((SncpServlet) servlet, conf);
} }
public void addServlet(SncpServlet servlet, AnyValue conf) { public void addServlet(SncpServlet servlet, AnyValue conf) {
setServletConf(servlet, conf); setServletConf(servlet, conf);
if (servlet.getNameid() == DLong.ZERO) { synchronized (mappings) {
synchronized (singlemaps) { mappings.put(servlet.getServiceid(), servlet);
singlemaps.put(servlet.getServiceid(), servlet); servlets.add(servlet);
}
} else {
synchronized (maps) {
Map<DLong, SncpServlet> m = maps.get(servlet.getServiceid());
if (m == null) {
m = new HashMap<>();
maps.put(servlet.getServiceid(), m);
}
m.put(servlet.getNameid(), servlet);
}
} }
} }
public List<SncpServlet> getSncpServlets() { public List<SncpServlet> getSncpServlets() {
ArrayList<SncpServlet> list = new ArrayList<>(singlemaps.values()); ArrayList<SncpServlet> list = new ArrayList<>(servlets.size());
maps.values().forEach(x -> list.addAll(x.values())); servlets.forEach(x -> list.add((SncpServlet) x));
return list; return list;
} }
@Override @Override
public void init(SncpContext context, AnyValue config) { public void init(SncpContext context, AnyValue config) {
Collection<Map<DLong, SncpServlet>> values = this.maps.values(); servlets.forEach(s -> s.init(context, getServletConf(s)));
values.stream().forEach((en) -> {
en.values().stream().forEach(s -> s.init(context, getServletConf(s)));
});
} }
@Override @Override
public void destroy(SncpContext context, AnyValue config) { public void destroy(SncpContext context, AnyValue config) {
Collection<Map<DLong, SncpServlet>> values = this.maps.values(); servlets.forEach(s -> s.destroy(context, getServletConf(s)));
values.stream().forEach((en) -> {
en.values().stream().forEach(s -> s.destroy(context, getServletConf(s)));
});
} }
@Override @Override
@@ -79,23 +58,9 @@ public class SncpPrepareServlet extends PrepareServlet<DLong, SncpContext, SncpR
response.finish(pongBuffer.duplicate()); response.finish(pongBuffer.duplicate());
return; return;
} }
SncpServlet servlet; SncpServlet servlet = (SncpServlet) mappings.get(request.getServiceid());
if (request.getNameid() == DLong.ZERO) {
servlet = singlemaps.get(request.getServiceid());
if (servlet == null) {
response.finish(SncpResponse.RETCODE_ILLSERVICEID, null); //无效serviceid
return;
}
} else {
Map<DLong, SncpServlet> m = maps.get(request.getServiceid());
if (m == null) {
response.finish(SncpResponse.RETCODE_ILLSERVICEID, null); //无效serviceid
return;
}
servlet = m.get(request.getNameid());
}
if (servlet == null) { if (servlet == null) {
response.finish(SncpResponse.RETCODE_ILLNAMEID, null); //无效nameid response.finish(SncpResponse.RETCODE_ILLSERVICEID, null); //无效serviceid
} else { } else {
servlet.execute(request, response); servlet.execute(request, response);
} }

View File

@@ -13,12 +13,14 @@ import org.redkale.util.*;
/** /**
* *
* <p> 详情见: http://www.redkale.org * <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx * @author zhangjx
*/ */
public final class SncpRequest extends Request<SncpContext> { public final class SncpRequest extends Request<SncpContext> {
public static final int HEADER_SIZE = 72; public static final int HEADER_SIZE = 56;
public static final byte[] DEFAULT_HEADER = new byte[HEADER_SIZE]; public static final byte[] DEFAULT_HEADER = new byte[HEADER_SIZE];
@@ -28,8 +30,6 @@ public final class SncpRequest extends Request<SncpContext> {
private DLong serviceid; private DLong serviceid;
private DLong nameid;
private DLong actionid; private DLong actionid;
private int bodylength; private int bodylength;
@@ -60,7 +60,6 @@ public final class SncpRequest extends Request<SncpContext> {
return -1; return -1;
} }
this.serviceid = DLong.read(buffer); this.serviceid = DLong.read(buffer);
this.nameid = DLong.read(buffer);
this.actionid = DLong.read(buffer); this.actionid = DLong.read(buffer);
buffer.get(bufferbytes); buffer.get(bufferbytes);
this.bodylength = buffer.getInt(); this.bodylength = buffer.getInt();
@@ -102,7 +101,6 @@ public final class SncpRequest extends Request<SncpContext> {
protected void recycle() { protected void recycle() {
this.seqid = 0; this.seqid = 0;
this.serviceid = null; this.serviceid = null;
this.nameid = null;
this.actionid = null; this.actionid = null;
this.bodylength = 0; this.bodylength = 0;
this.bodyoffset = 0; this.bodyoffset = 0;
@@ -128,10 +126,6 @@ public final class SncpRequest extends Request<SncpContext> {
return serviceid; return serviceid;
} }
public DLong getNameid() {
return nameid;
}
public DLong getActionid() { public DLong getActionid() {
return actionid; return actionid;
} }

View File

@@ -23,9 +23,7 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
public static final int RETCODE_ILLSERVICEID = (1 << 10); //无效serviceid public static final int RETCODE_ILLSERVICEID = (1 << 10); //无效serviceid
public static final int RETCODE_ILLNAMEID = (1 << 11); //无效nameid public static final int RETCODE_ILLACTIONID = (1 << 11); //无效actionid
public static final int RETCODE_ILLACTIONID = (1 << 12); //无效actionid
public static final int RETCODE_THROWEXCEPTION = (1 << 30); //内部异常 public static final int RETCODE_THROWEXCEPTION = (1 << 30); //内部异常
@@ -39,7 +37,6 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
public static String getRetCodeInfo(int retcode) { public static String getRetCodeInfo(int retcode) {
if (retcode == RETCODE_ILLSERVICEID) return "serviceid is invalid"; if (retcode == RETCODE_ILLSERVICEID) return "serviceid is invalid";
if (retcode == RETCODE_ILLNAMEID) return "nameid is invalid";
if (retcode == RETCODE_ILLACTIONID) return "actionid is invalid"; if (retcode == RETCODE_ILLACTIONID) return "actionid is invalid";
if (retcode == RETCODE_THROWEXCEPTION) return "Inner exception"; if (retcode == RETCODE_THROWEXCEPTION) return "Inner exception";
return null; return null;
@@ -71,7 +68,6 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
buffer.putLong(request.getSeqid()); buffer.putLong(request.getSeqid());
buffer.putChar((char) SncpRequest.HEADER_SIZE); buffer.putChar((char) SncpRequest.HEADER_SIZE);
DLong.write(buffer, request.getServiceid()); DLong.write(buffer, request.getServiceid());
DLong.write(buffer, request.getNameid());
DLong.write(buffer, request.getActionid()); DLong.write(buffer, request.getActionid());
buffer.put(addrBytes); buffer.put(addrBytes);
buffer.putChar((char) this.addrPort); buffer.putChar((char) this.addrPort);

View File

@@ -21,7 +21,7 @@ import org.redkale.watch.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResponse> { public final class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
public SncpServer() { public SncpServer() {
this(System.currentTimeMillis(), null); this(System.currentTimeMillis(), null);

View File

@@ -17,8 +17,6 @@ import org.redkale.util.*;
*/ */
public abstract class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse> implements Comparable<SncpServlet> { public abstract class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse> implements Comparable<SncpServlet> {
public abstract DLong getNameid();
public abstract DLong getServiceid(); public abstract DLong getServiceid();
@Override @Override