This commit is contained in:
@@ -103,7 +103,7 @@ public final class Application {
|
|||||||
final List<NodeServer> servers = new CopyOnWriteArrayList<>();
|
final List<NodeServer> servers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
//传输端的TransportFactory
|
//传输端的TransportFactory
|
||||||
final TransportFactory transportFactory;
|
final SncpTransportFactory transportFactory;
|
||||||
|
|
||||||
//全局根ResourceFactory
|
//全局根ResourceFactory
|
||||||
final ResourceFactory resourceFactory = ResourceFactory.root();
|
final ResourceFactory resourceFactory = ResourceFactory.root();
|
||||||
@@ -260,21 +260,20 @@ public final class Application {
|
|||||||
logger.log(Level.INFO, Transport.class.getSimpleName() + " configure bufferCapacity = " + bufferCapacity + "; bufferPoolSize = " + bufferPoolSize + "; threads = " + threads + ";");
|
logger.log(Level.INFO, Transport.class.getSimpleName() + " configure bufferCapacity = " + bufferCapacity + "; bufferPoolSize = " + bufferPoolSize + "; threads = " + threads + ";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup);
|
this.transportFactory = new SncpTransportFactory(transportExec, transportPool, transportGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceFactory getResourceFactory() {
|
public ResourceFactory getResourceFactory() {
|
||||||
return resourceFactory;
|
return resourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportFactory getTransportFactory() {
|
public SncpTransportFactory getTransportFactory() {
|
||||||
return transportFactory;
|
return transportFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public WatchFactory getWatchFactory() {
|
// public WatchFactory getWatchFactory() {
|
||||||
// return watchFactory;
|
// return watchFactory;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public List<NodeServer> getNodeServers() {
|
public List<NodeServer> getNodeServers() {
|
||||||
return new ArrayList<>(servers);
|
return new ArrayList<>(servers);
|
||||||
}
|
}
|
||||||
@@ -359,6 +358,8 @@ public final class Application {
|
|||||||
Class type = field.getType();
|
Class type = field.getType();
|
||||||
if (type == Application.class) {
|
if (type == Application.class) {
|
||||||
field.set(src, application);
|
field.set(src, application);
|
||||||
|
} else if (type == SncpTransportFactory.class) {
|
||||||
|
field.set(src, application.transportFactory);
|
||||||
} else if (type == NodeSncpServer.class) {
|
} else if (type == NodeSncpServer.class) {
|
||||||
NodeServer server = null;
|
NodeServer server = null;
|
||||||
for (NodeServer ns : application.getNodeServers()) {
|
for (NodeServer ns : application.getNodeServers()) {
|
||||||
@@ -403,7 +404,7 @@ public final class Application {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}, Application.class, NodeSncpServer.class, NodeHttpServer.class, NodeWatchServer.class);
|
}, Application.class, SncpTransportFactory.class, NodeSncpServer.class, NodeHttpServer.class, NodeWatchServer.class);
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
initResources();
|
initResources();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public abstract class NodeServer {
|
|||||||
final NodeServer self = this;
|
final NodeServer self = this;
|
||||||
//---------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------
|
||||||
final ResourceFactory appResFactory = application.getResourceFactory();
|
final ResourceFactory appResFactory = application.getResourceFactory();
|
||||||
final TransportFactory appTranFactory = application.getTransportFactory();
|
final SncpTransportFactory appTranFactory = application.getTransportFactory();
|
||||||
final AnyValue resources = application.config.getAnyValue("resources");
|
final AnyValue resources = application.config.getAnyValue("resources");
|
||||||
final Map<String, AnyValue> cacheResource = new HashMap<>();
|
final Map<String, AnyValue> cacheResource = new HashMap<>();
|
||||||
//final Map<String, AnyValue> dataResources = new HashMap<>();
|
//final Map<String, AnyValue> dataResources = new HashMap<>();
|
||||||
@@ -321,7 +321,7 @@ public abstract class NodeServer {
|
|||||||
final Set<FilterEntry<? extends Service>> entrys = (Set) serviceFilter.getAllFilterEntrys();
|
final Set<FilterEntry<? extends Service>> entrys = (Set) serviceFilter.getAllFilterEntrys();
|
||||||
ResourceFactory regFactory = isSNCP() ? application.getResourceFactory() : resourceFactory;
|
ResourceFactory regFactory = isSNCP() ? application.getResourceFactory() : resourceFactory;
|
||||||
final ResourceFactory appResourceFactory = application.getResourceFactory();
|
final ResourceFactory appResourceFactory = application.getResourceFactory();
|
||||||
final TransportFactory appTransportFactory = application.getTransportFactory();
|
final SncpTransportFactory appTransportFactory = application.getTransportFactory();
|
||||||
for (FilterEntry<? extends Service> entry : entrys) { //service实现类
|
for (FilterEntry<? extends Service> entry : entrys) { //service实现类
|
||||||
final Class<? extends Service> serviceImplClass = entry.getType();
|
final Class<? extends Service> serviceImplClass = entry.getType();
|
||||||
if (Modifier.isFinal(serviceImplClass.getModifiers())) continue; //修饰final的类跳过
|
if (Modifier.isFinal(serviceImplClass.getModifiers())) continue; //修饰final的类跳过
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ public class TransportFactory {
|
|||||||
return groupInfos.get(group);
|
return groupInfos.get(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TransportFactory addGroupInfo(String name, InetSocketAddress... addrs) {
|
||||||
|
addGroupInfo(new TransportGroupInfo(name, addrs));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransportFactory addGroupInfo(String name, Set<InetSocketAddress> addrs) {
|
||||||
|
addGroupInfo(new TransportGroupInfo(name, addrs));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addGroupInfo(TransportGroupInfo info) {
|
public boolean addGroupInfo(TransportGroupInfo info) {
|
||||||
if (info == null) throw new RuntimeException("TransportGroupInfo can not null");
|
if (info == null) throw new RuntimeException("TransportGroupInfo can not null");
|
||||||
if (info.addresses == null) throw new RuntimeException("TransportGroupInfo.addresses can not null");
|
if (info.addresses == null) throw new RuntimeException("TransportGroupInfo.addresses can not null");
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.redkale.net;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议地址组合对象, 对应application.xml 中 resources->group 节点信息
|
* 协议地址组合对象, 对应application.xml 中 resources->group 节点信息
|
||||||
@@ -30,13 +31,23 @@ public class TransportGroupInfo {
|
|||||||
public TransportGroupInfo() {
|
public TransportGroupInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TransportGroupInfo(String name, InetSocketAddress... addrs) {
|
||||||
|
this(name, "TCP", "", Utility.ofSet(addrs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransportGroupInfo(String name, Set<InetSocketAddress> addrs) {
|
||||||
|
this(name, "TCP", "", addrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransportGroupInfo(String name, String protocol, String subprotocol, InetSocketAddress... addrs) {
|
||||||
|
this(name, protocol, subprotocol, Utility.ofSet(addrs));
|
||||||
|
}
|
||||||
|
|
||||||
public TransportGroupInfo(String name, String protocol, String subprotocol, Set<InetSocketAddress> addrs) {
|
public TransportGroupInfo(String name, String protocol, String subprotocol, Set<InetSocketAddress> addrs) {
|
||||||
Objects.requireNonNull(name, "Transport.group.name can not null");
|
Objects.requireNonNull(name, "Transport.group.name can not null");
|
||||||
Objects.requireNonNull(protocol, "Transport.group.protocol can not null");
|
|
||||||
Objects.requireNonNull(subprotocol, "Transport.group.subprotocol can not null");
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.protocol = protocol;
|
this.protocol = protocol == null ? "TCP" : protocol;
|
||||||
this.subprotocol = subprotocol;
|
this.subprotocol = subprotocol == null ? "" : subprotocol;
|
||||||
this.addresses = addrs;
|
this.addresses = addrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +65,7 @@ public class TransportGroupInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocol(String protocol) {
|
public void setProtocol(String protocol) {
|
||||||
Objects.requireNonNull(protocol, "Transport.group.protocol can not null");
|
this.protocol = protocol == null ? "TCP" : protocol;
|
||||||
this.protocol = protocol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubprotocol() {
|
public String getSubprotocol() {
|
||||||
@@ -63,7 +73,7 @@ public class TransportGroupInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSubprotocol(String subprotocol) {
|
public void setSubprotocol(String subprotocol) {
|
||||||
Objects.requireNonNull(subprotocol, "Transport.group.subprotocol can not null");
|
this.subprotocol = subprotocol == null ? "" : subprotocol;
|
||||||
this.subprotocol = subprotocol;
|
this.subprotocol = subprotocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
|
|||||||
import jdk.internal.org.objectweb.asm.*;
|
import jdk.internal.org.objectweb.asm.*;
|
||||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
import jdk.internal.org.objectweb.asm.Type;
|
import jdk.internal.org.objectweb.asm.Type;
|
||||||
import org.redkale.net.*;
|
|
||||||
import org.redkale.net.sncp.SncpClient.SncpAction;
|
import org.redkale.net.sncp.SncpClient.SncpAction;
|
||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
@@ -750,6 +749,11 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends Service> T createSimpleLocalService(final Class<T> serviceImplClass,
|
||||||
|
final SncpTransportFactory transportFactory, final InetSocketAddress clientSncpAddress, final String... groups) {
|
||||||
|
return createLocalService("", serviceImplClass, ResourceFactory.root(), transportFactory, clientSncpAddress, Utility.ofSet(groups), null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 创建本地模式Service实例
|
* 创建本地模式Service实例
|
||||||
@@ -758,7 +762,7 @@ public abstract class Sncp {
|
|||||||
* @param name 资源名
|
* @param name 资源名
|
||||||
* @param serviceImplClass Service类
|
* @param serviceImplClass Service类
|
||||||
* @param resourceFactory ResourceFactory
|
* @param resourceFactory ResourceFactory
|
||||||
* @param transportFactory TransportFactory
|
* @param transportFactory SncpTransportFactory
|
||||||
* @param clientSncpAddress 本地IP地址
|
* @param clientSncpAddress 本地IP地址
|
||||||
* @param groups 所有的组节点,包含自身
|
* @param groups 所有的组节点,包含自身
|
||||||
* @param conf 启动配置项
|
* @param conf 启动配置项
|
||||||
@@ -770,7 +774,7 @@ public abstract class Sncp {
|
|||||||
final String name,
|
final String name,
|
||||||
final Class<T> serviceImplClass,
|
final Class<T> serviceImplClass,
|
||||||
final ResourceFactory resourceFactory,
|
final ResourceFactory resourceFactory,
|
||||||
final TransportFactory transportFactory,
|
final SncpTransportFactory transportFactory,
|
||||||
final InetSocketAddress clientSncpAddress,
|
final InetSocketAddress clientSncpAddress,
|
||||||
final Set<String> groups,
|
final Set<String> groups,
|
||||||
final AnyValue conf) {
|
final AnyValue conf) {
|
||||||
@@ -825,6 +829,11 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends Service> T createSimpleRemoteService(final Class<T> serviceImplClass,
|
||||||
|
final SncpTransportFactory transportFactory, final InetSocketAddress clientSncpAddress, final String... groups) {
|
||||||
|
return createRemoteService("", serviceImplClass, transportFactory, clientSncpAddress, Utility.ofSet(groups), null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* @Resource(name = "")
|
* @Resource(name = "")
|
||||||
@@ -889,7 +898,7 @@ public abstract class Sncp {
|
|||||||
* @param <T> Service泛型
|
* @param <T> Service泛型
|
||||||
* @param name 资源名
|
* @param name 资源名
|
||||||
* @param serviceTypeOrImplClass Service类
|
* @param serviceTypeOrImplClass Service类
|
||||||
* @param transportFactory TransportFactory
|
* @param transportFactory SncpTransportFactory
|
||||||
* @param clientAddress 本地IP地址
|
* @param clientAddress 本地IP地址
|
||||||
* @param groups 所有的组节点,包含自身
|
* @param groups 所有的组节点,包含自身
|
||||||
* @param conf 启动配置项
|
* @param conf 启动配置项
|
||||||
@@ -897,10 +906,11 @@ public abstract class Sncp {
|
|||||||
* @return Service的远程模式实例
|
* @return Service的远程模式实例
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
||||||
public static <T extends Service> T createRemoteService(
|
public static <T extends Service> T createRemoteService(
|
||||||
final String name,
|
final String name,
|
||||||
final Class<T> serviceTypeOrImplClass,
|
final Class<T> serviceTypeOrImplClass,
|
||||||
final TransportFactory transportFactory,
|
final SncpTransportFactory transportFactory,
|
||||||
final InetSocketAddress clientAddress,
|
final InetSocketAddress clientAddress,
|
||||||
final Set<String> groups,
|
final Set<String> groups,
|
||||||
final AnyValue conf) {
|
final AnyValue conf) {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public final class SncpClient {
|
|||||||
//本地模式
|
//本地模式
|
||||||
protected Transport[] diffGroupTransports;
|
protected Transport[] diffGroupTransports;
|
||||||
|
|
||||||
public <T extends Service> SncpClient(final String serviceName, final Class<T> serviceTypeOrImplClass, final T service, final TransportFactory factory,
|
public <T extends Service> SncpClient(final String serviceName, final Class<T> serviceTypeOrImplClass, final T service, final SncpTransportFactory factory,
|
||||||
final boolean remote, final Class serviceClass, final InetSocketAddress clientAddress) {
|
final boolean remote, final Class serviceClass, final InetSocketAddress clientAddress) {
|
||||||
this.remote = remote;
|
this.remote = remote;
|
||||||
this.executor = factory.getExecutor();
|
this.executor = factory.getExecutor();
|
||||||
@@ -101,6 +101,7 @@ public final class SncpClient {
|
|||||||
this.actions = methodens.toArray(new SncpAction[methodens.size()]);
|
this.actions = methodens.toArray(new SncpAction[methodens.size()]);
|
||||||
this.addrBytes = clientAddress == null ? new byte[4] : clientAddress.getAddress().getAddress();
|
this.addrBytes = clientAddress == null ? new byte[4] : clientAddress.getAddress().getAddress();
|
||||||
this.addrPort = clientAddress == null ? 0 : clientAddress.getPort();
|
this.addrPort = clientAddress == null ? 0 : clientAddress.getPort();
|
||||||
|
factory.addSncpClient(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<SncpAction> getSncpActions(final Class serviceClass) {
|
static List<SncpAction> getSncpActions(final Class serviceClass) {
|
||||||
@@ -337,18 +338,6 @@ public final class SncpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<byte[]> remote0(final AsyncHandler handler, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
private CompletableFuture<byte[]> remote0(final AsyncHandler handler, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||||
if ("rest".equalsIgnoreCase(transport.getSubprotocol())) {
|
|
||||||
return remoteRest0(handler, transport, addr0, action, params);
|
|
||||||
}
|
|
||||||
return remoteSncp0(handler, transport, addr0, action, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
//尚未实现
|
|
||||||
private CompletableFuture<byte[]> remoteRest0(final AsyncHandler handler, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompletableFuture<byte[]> remoteSncp0(final AsyncHandler handler, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
|
||||||
final Type[] myparamtypes = action.paramTypes;
|
final Type[] myparamtypes = action.paramTypes;
|
||||||
final Class[] myparamclass = action.paramClass;
|
final Class[] myparamclass = action.paramClass;
|
||||||
if (action.addressSourceParamIndex >= 0) params[action.addressSourceParamIndex] = this.clientAddress;
|
if (action.addressSourceParamIndex >= 0) params[action.addressSourceParamIndex] = this.clientAddress;
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import java.io.IOException;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.AsynchronousChannelGroup;
|
import java.nio.channels.AsynchronousChannelGroup;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.redkale.convert.bson.BsonConvert;
|
import org.redkale.convert.bson.BsonConvert;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.net.*;
|
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.sncp.*;
|
import org.redkale.net.sncp.*;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
@@ -36,11 +34,18 @@ public class ABMainService implements Service {
|
|||||||
public static void remotemain(String[] args) throws Throwable {
|
public static void remotemain(String[] args) throws Throwable {
|
||||||
System.out.println("------------------- 远程模式调用 -----------------------------------");
|
System.out.println("------------------- 远程模式调用 -----------------------------------");
|
||||||
final int abport = 8888;
|
final int abport = 8888;
|
||||||
ResourceFactory factory = ResourceFactory.root();
|
ResourceFactory resFactory = ResourceFactory.root();
|
||||||
factory.register(JsonConvert.root());
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
factory.register(BsonConvert.root());
|
final SncpTransportFactory transFactory = new SncpTransportFactory(executor, newBufferPool(), newChannelGroup());
|
||||||
|
transFactory.addGroupInfo("g77", new InetSocketAddress("127.0.0.1", 5577));
|
||||||
|
transFactory.addGroupInfo("g88", new InetSocketAddress("127.0.0.1", 5588));
|
||||||
|
transFactory.addGroupInfo("g99", new InetSocketAddress("127.0.0.1", 5599));
|
||||||
|
|
||||||
|
resFactory.register(JsonConvert.root());
|
||||||
|
resFactory.register(BsonConvert.root());
|
||||||
|
|
||||||
//------------------------ 初始化 CService ------------------------------------
|
//------------------------ 初始化 CService ------------------------------------
|
||||||
CService cservice = Sncp.createLocalService("", null, ResourceFactory.root(), CService.class, new InetSocketAddress("127.0.0.1", 5577), "", new HashSet<>(), (AnyValue) null, null, null);
|
CService cservice = Sncp.createSimpleLocalService(CService.class, transFactory, new InetSocketAddress("127.0.0.1", 5577), "g77");
|
||||||
SncpServer cserver = new SncpServer();
|
SncpServer cserver = new SncpServer();
|
||||||
cserver.getLogger().setLevel(Level.WARNING);
|
cserver.getLogger().setLevel(Level.WARNING);
|
||||||
cserver.addSncpServlet(cservice);
|
cserver.addSncpServlet(cservice);
|
||||||
@@ -48,11 +53,10 @@ public class ABMainService implements Service {
|
|||||||
cserver.start();
|
cserver.start();
|
||||||
|
|
||||||
//------------------------ 初始化 BCService ------------------------------------
|
//------------------------ 初始化 BCService ------------------------------------
|
||||||
final Transport bctransport = new Transport("", "", newBufferPool(), newChannelGroup(), null, Utility.ofSet(new InetSocketAddress("127.0.0.1", 5577)));
|
BCService bcservice = Sncp.createSimpleLocalService(BCService.class, transFactory, new InetSocketAddress("127.0.0.1", 5588), "g88");
|
||||||
BCService bcservice = Sncp.createLocalService("", null, ResourceFactory.root(), BCService.class, new InetSocketAddress("127.0.0.1", 5588), "", new HashSet<>(), (AnyValue) null, bctransport, null);
|
CService remoteCService = Sncp.createSimpleRemoteService(CService.class, transFactory, new InetSocketAddress("127.0.0.1", 5588), "g77");
|
||||||
CService remoteCService = Sncp.createRemoteService("", null, CService.class, new InetSocketAddress("127.0.0.1", 5588), "", new HashSet<>(), (AnyValue) null, bctransport);
|
resFactory.inject(remoteCService);
|
||||||
factory.inject(remoteCService);
|
resFactory.register("", remoteCService);
|
||||||
factory.register("", remoteCService);
|
|
||||||
SncpServer bcserver = new SncpServer();
|
SncpServer bcserver = new SncpServer();
|
||||||
bcserver.getLogger().setLevel(Level.WARNING);
|
bcserver.getLogger().setLevel(Level.WARNING);
|
||||||
bcserver.addSncpServlet(bcservice);
|
bcserver.addSncpServlet(bcservice);
|
||||||
@@ -60,20 +64,19 @@ public class ABMainService implements Service {
|
|||||||
bcserver.start();
|
bcserver.start();
|
||||||
|
|
||||||
//------------------------ 初始化 ABMainService ------------------------------------
|
//------------------------ 初始化 ABMainService ------------------------------------
|
||||||
final Transport abtransport = new Transport("", "", newBufferPool(), newChannelGroup(), null, Utility.ofSet(new InetSocketAddress("127.0.0.1", 5588)));
|
ABMainService service = Sncp.createSimpleLocalService(ABMainService.class, transFactory, new InetSocketAddress("127.0.0.1", 5599), "g99");
|
||||||
ABMainService service = Sncp.createLocalService("", null, ResourceFactory.root(), ABMainService.class, new InetSocketAddress("127.0.0.1", 5599), "", new HashSet<>(), (AnyValue) null, bctransport, null);
|
BCService remoteBCService = Sncp.createSimpleRemoteService(BCService.class, transFactory, new InetSocketAddress("127.0.0.1", 5599), "g88");
|
||||||
BCService remoteBCService = Sncp.createRemoteService("", null, BCService.class, new InetSocketAddress("127.0.0.1", 5599), "", new HashSet<>(), (AnyValue) null, abtransport);
|
resFactory.inject(remoteBCService);
|
||||||
factory.inject(remoteBCService);
|
resFactory.register("", remoteBCService);
|
||||||
factory.register("", remoteBCService);
|
|
||||||
|
|
||||||
HttpServer server = new HttpServer();
|
HttpServer server = new HttpServer();
|
||||||
server.getLogger().setLevel(Level.WARNING);
|
server.getLogger().setLevel(Level.WARNING);
|
||||||
|
|
||||||
server.addRestServlet("", ABMainService.class, service, HttpServlet.class, "/pipes");
|
server.addRestServlet("", ABMainService.class, service, HttpServlet.class, "/pipes");
|
||||||
|
|
||||||
factory.inject(cservice);
|
resFactory.inject(cservice);
|
||||||
factory.inject(bcservice);
|
resFactory.inject(bcservice);
|
||||||
factory.inject(service);
|
resFactory.inject(service);
|
||||||
|
|
||||||
server.init(DefaultAnyValue.create("port", abport));
|
server.init(DefaultAnyValue.create("port", abport));
|
||||||
server.start();
|
server.start();
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import java.util.concurrent.*;
|
|||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
import org.redkale.convert.bson.*;
|
import org.redkale.convert.bson.*;
|
||||||
import org.redkale.net.Transport;
|
|
||||||
import org.redkale.net.sncp.*;
|
import org.redkale.net.sncp.*;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
@@ -79,9 +78,9 @@ public class SncpTest {
|
|||||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||||
set.add(addr);
|
set.add(addr);
|
||||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||||
//String name, WatchFactory, ObjectPool<ByteBuffer>, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection<InetSocketAddress>
|
final SncpTransportFactory transFactory = new SncpTransportFactory(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||||
final Transport transport = new Transport("", "", newBufferPool(), newChannelGroup(), null, set);
|
transFactory.addGroupInfo("client", set);
|
||||||
final SncpTestIService service = Sncp.createSimpleRemoteService(serviceName, SncpTestIService.class, addr, transport);
|
final SncpTestIService service = Sncp.createSimpleRemoteService(SncpTestIService.class, transFactory, addr, "client");
|
||||||
ResourceFactory.root().inject(service);
|
ResourceFactory.root().inject(service);
|
||||||
|
|
||||||
// SncpTestBean bean = new SncpTestBean();
|
// SncpTestBean bean = new SncpTestBean();
|
||||||
@@ -156,9 +155,9 @@ public class SncpTest {
|
|||||||
SncpServer server = new SncpServer();
|
SncpServer server = new SncpServer();
|
||||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||||
//String name, WatchFactory, ObjectPool<ByteBuffer>, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection<InetSocketAddress>
|
final SncpTransportFactory transFactory = new SncpTransportFactory(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||||
final Transport transport = new Transport("", "", newBufferPool(), newChannelGroup(), null, set);
|
transFactory.addGroupInfo("server", set);
|
||||||
SncpTestIService service = Sncp.createSimpleLocalService("", SncpTestServiceImpl.class, addr, transport);
|
SncpTestIService service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, transFactory, addr, "server");
|
||||||
ResourceFactory.root().inject(service);
|
ResourceFactory.root().inject(service);
|
||||||
server.addSncpServlet(service);
|
server.addSncpServlet(service);
|
||||||
System.out.println(service);
|
System.out.println(service);
|
||||||
@@ -190,9 +189,10 @@ public class SncpTest {
|
|||||||
SncpServer server = new SncpServer();
|
SncpServer server = new SncpServer();
|
||||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||||
set.add(new InetSocketAddress(myhost, port));
|
set.add(new InetSocketAddress(myhost, port));
|
||||||
//String name, WatchFactory, ObjectPool<ByteBuffer>, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection<InetSocketAddress>
|
|
||||||
final Transport transport = new Transport("", "", newBufferPool(), newChannelGroup(), null, set);
|
final SncpTransportFactory transFactory = new SncpTransportFactory(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||||
Service service = Sncp.createSimpleLocalService("", SncpTestServiceImpl.class, addr, transport);
|
transFactory.addGroupInfo("server", set);
|
||||||
|
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, transFactory, addr, "server");
|
||||||
server.addSncpServlet(service);
|
server.addSncpServlet(service);
|
||||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||||
conf.addValue("host", "0.0.0.0");
|
conf.addValue("host", "0.0.0.0");
|
||||||
@@ -207,4 +207,5 @@ public class SncpTest {
|
|||||||
}.start();
|
}.start();
|
||||||
cdl.await();
|
cdl.await();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ package org.redkale.test.sncp;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.HashSet;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import org.redkale.net.sncp.*;
|
import org.redkale.net.sncp.*;
|
||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.source.DataCallArrayAttribute;
|
import org.redkale.source.DataCallArrayAttribute;
|
||||||
|
import static org.redkale.test.sncp.SncpTest.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +98,11 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Service service = Sncp.createLocalService("", null, ResourceFactory.root(), SncpTestServiceImpl.class, new InetSocketAddress("127.0.0.1", 7070), "", new HashSet<>(), (AnyValue) null, null, null);
|
|
||||||
|
final SncpTransportFactory transFactory = new SncpTransportFactory(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||||
|
|
||||||
|
transFactory.addGroupInfo("g70", new InetSocketAddress("127.0.0.1", 7070));
|
||||||
|
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, transFactory, new InetSocketAddress("127.0.0.1", 7070), "g70");
|
||||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||||
System.out.println(method);
|
System.out.println(method);
|
||||||
}
|
}
|
||||||
@@ -107,7 +111,7 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
|||||||
System.out.println(method);
|
System.out.println(method);
|
||||||
}
|
}
|
||||||
System.out.println("-----------------------------------");
|
System.out.println("-----------------------------------");
|
||||||
service = Sncp.createSimpleRemoteService("", SncpTestServiceImpl.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
service = Sncp.createSimpleRemoteService(SncpTestServiceImpl.class, transFactory, new InetSocketAddress("127.0.0.1", 7070), "g70");
|
||||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||||
System.out.println(method);
|
System.out.println(method);
|
||||||
}
|
}
|
||||||
@@ -116,7 +120,7 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
|||||||
System.out.println(method);
|
System.out.println(method);
|
||||||
}
|
}
|
||||||
System.out.println("-----------------------------------");
|
System.out.println("-----------------------------------");
|
||||||
service = Sncp.createSimpleRemoteService("", SncpTestIService.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
service = Sncp.createSimpleRemoteService(SncpTestIService.class, transFactory, new InetSocketAddress("127.0.0.1", 7070), "g70");
|
||||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||||
System.out.println(method);
|
System.out.println(method);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user