AsmMethodBoost优化
This commit is contained in:
@@ -42,18 +42,21 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
|
|
||||||
protected final AtomicInteger fieldIndex = new AtomicInteger();
|
protected final AtomicInteger fieldIndex = new AtomicInteger();
|
||||||
|
|
||||||
|
protected final boolean remote;
|
||||||
|
|
||||||
protected final Class serviceType;
|
protected final Class serviceType;
|
||||||
|
|
||||||
protected AsmMethodBoost(Class serviceType) {
|
protected AsmMethodBoost(boolean remote, Class serviceType) {
|
||||||
|
this.remote = remote;
|
||||||
this.serviceType = serviceType;
|
this.serviceType = serviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AsmMethodBoost create(Collection<AsmMethodBoost> list) {
|
public static AsmMethodBoost create(boolean remote, Collection<AsmMethodBoost> list) {
|
||||||
return new AsmMethodBoosts(list);
|
return new AsmMethodBoosts(remote, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AsmMethodBoost create(AsmMethodBoost... items) {
|
public static AsmMethodBoost create(boolean remote, AsmMethodBoost... items) {
|
||||||
return new AsmMethodBoosts(items);
|
return new AsmMethodBoosts(remote, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,13 +246,13 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
|
|
||||||
private final AsmMethodBoost[] items;
|
private final AsmMethodBoost[] items;
|
||||||
|
|
||||||
public AsmMethodBoosts(Collection<AsmMethodBoost> list) {
|
public AsmMethodBoosts(boolean remote, Collection<AsmMethodBoost> list) {
|
||||||
super(null);
|
super(remote, null);
|
||||||
this.items = list.toArray(new AsmMethodBoost[list.size()]);
|
this.items = list.toArray(new AsmMethodBoost[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsmMethodBoosts(AsmMethodBoost... items) {
|
public AsmMethodBoosts(boolean remote, AsmMethodBoost... items) {
|
||||||
super(null);
|
super(remote, null);
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.boot;
|
package org.redkale.boot;
|
||||||
|
|
||||||
import org.redkale.mq.spi.MessageModuleEngine;
|
|
||||||
import org.redkale.mq.spi.MessageAgent;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@@ -35,7 +33,8 @@ import org.redkale.inject.ResourceEvent;
|
|||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.inject.ResourceTypeLoader;
|
import org.redkale.inject.ResourceTypeLoader;
|
||||||
import org.redkale.lock.spi.LockModuleEngine;
|
import org.redkale.lock.spi.LockModuleEngine;
|
||||||
import org.redkale.mq.*;
|
import org.redkale.mq.spi.MessageAgent;
|
||||||
|
import org.redkale.mq.spi.MessageModuleEngine;
|
||||||
import org.redkale.net.*;
|
import org.redkale.net.*;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.sncp.*;
|
import org.redkale.net.sncp.*;
|
||||||
@@ -846,10 +845,10 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AsmMethodBoost createAsmMethodBoost(Class serviceClass) {
|
AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||||
List<AsmMethodBoost> list = null;
|
List<AsmMethodBoost> list = null;
|
||||||
for (ModuleEngine item : moduleEngines) {
|
for (ModuleEngine item : moduleEngines) {
|
||||||
AsmMethodBoost boost = item.createAsmMethodBoost(serviceClass);
|
AsmMethodBoost boost = item.createAsmMethodBoost(remote, serviceClass);
|
||||||
if (boost != null) {
|
if (boost != null) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
@@ -860,7 +859,7 @@ public final class Application {
|
|||||||
if (list == null) {
|
if (list == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return list.size() == 1 ? list.get(0) : AsmMethodBoost.create(list);
|
return list.size() == 1 ? list.get(0) : AsmMethodBoost.create(remote, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -58,11 +58,12 @@ public abstract class ModuleEngine {
|
|||||||
/**
|
/**
|
||||||
* 动态扩展类的方法
|
* 动态扩展类的方法
|
||||||
*
|
*
|
||||||
|
* @param remote 是否远程模式
|
||||||
* @param serviceClass 类
|
* @param serviceClass 类
|
||||||
*
|
*
|
||||||
* @return 方法动态扩展器
|
* @return 方法动态扩展器
|
||||||
*/
|
*/
|
||||||
public AsmMethodBoost createAsmMethodBoost(Class serviceClass) {
|
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class NodeHttpServer extends NodeServer {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.WARNING, "WebSocketServlet getMessageAgent error", ex);
|
logger.log(Level.WARNING, "WebSocketServlet getMessageAgent error", ex);
|
||||||
}
|
}
|
||||||
AsmMethodBoost methodBoost = application.createAsmMethodBoost(WebSocketNodeService.class);
|
AsmMethodBoost methodBoost = application.createAsmMethodBoost(false, WebSocketNodeService.class);
|
||||||
nodeService = Sncp.createLocalService(serverClassLoader, resourceName, WebSocketNodeService.class, methodBoost,
|
nodeService = Sncp.createLocalService(serverClassLoader, resourceName, WebSocketNodeService.class, methodBoost,
|
||||||
application.getResourceFactory(), application.getSncpRpcGroups(), sncpClient, messageAgent, (String) null, (AnyValue) null);
|
application.getResourceFactory(), application.getSncpRpcGroups(), sncpClient, messageAgent, (String) null, (AnyValue) null);
|
||||||
regFactory.register(resourceName, WebSocketNode.class, nodeService);
|
regFactory.register(resourceName, WebSocketNode.class, nodeService);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.boot;
|
package org.redkale.boot;
|
||||||
|
|
||||||
import org.redkale.mq.spi.MessageAgent;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
@@ -25,7 +24,7 @@ import org.redkale.boot.ClassFilter.FilterEntry;
|
|||||||
import org.redkale.cluster.ClusterAgent;
|
import org.redkale.cluster.ClusterAgent;
|
||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.inject.ResourceTypeLoader;
|
import org.redkale.inject.ResourceTypeLoader;
|
||||||
import org.redkale.mq.*;
|
import org.redkale.mq.spi.MessageAgent;
|
||||||
import org.redkale.net.*;
|
import org.redkale.net.*;
|
||||||
import org.redkale.net.Filter;
|
import org.redkale.net.Filter;
|
||||||
import org.redkale.net.client.ClientAddress;
|
import org.redkale.net.client.ClientAddress;
|
||||||
@@ -265,7 +264,7 @@ public abstract class NodeServer {
|
|||||||
if (groups.isEmpty() && isSNCP() && NodeServer.this.sncpGroup != null) {
|
if (groups.isEmpty() && isSNCP() && NodeServer.this.sncpGroup != null) {
|
||||||
groups.add(NodeServer.this.sncpGroup);
|
groups.add(NodeServer.this.sncpGroup);
|
||||||
}
|
}
|
||||||
AsmMethodBoost methodBoost = application.createAsmMethodBoost(WebSocketNodeService.class);
|
AsmMethodBoost methodBoost = application.createAsmMethodBoost(false, WebSocketNodeService.class);
|
||||||
nodeService = Sncp.createLocalService(serverClassLoader, resourceName, WebSocketNodeService.class, methodBoost,
|
nodeService = Sncp.createLocalService(serverClassLoader, resourceName, WebSocketNodeService.class, methodBoost,
|
||||||
application.getResourceFactory(), application.getSncpRpcGroups(), sncpClient, null, (String) null, (AnyValue) null);
|
application.getResourceFactory(), application.getSncpRpcGroups(), sncpClient, null, (String) null, (AnyValue) null);
|
||||||
(isSNCP() ? appResFactory : resourceFactory).register(resourceName, WebSocketNode.class, nodeService);
|
(isSNCP() ? appResFactory : resourceFactory).register(resourceName, WebSocketNode.class, nodeService);
|
||||||
@@ -332,7 +331,7 @@ public abstract class NodeServer {
|
|||||||
if (Modifier.isFinal(resServiceType.getModifiers()) || Sncp.isComponent(resServiceType)) {
|
if (Modifier.isFinal(resServiceType.getModifiers()) || Sncp.isComponent(resServiceType)) {
|
||||||
service = (Service) resServiceType.getConstructor().newInstance();
|
service = (Service) resServiceType.getConstructor().newInstance();
|
||||||
} else {
|
} else {
|
||||||
AsmMethodBoost methodBoost = application.createAsmMethodBoost(resServiceType);
|
AsmMethodBoost methodBoost = application.createAsmMethodBoost(false, resServiceType);
|
||||||
service = Sncp.createLocalService(serverClassLoader, resourceName, resServiceType,
|
service = Sncp.createLocalService(serverClassLoader, resourceName, resServiceType,
|
||||||
methodBoost, appResFactory, application.getSncpRpcGroups(), sncpClient, null, null, null);
|
methodBoost, appResFactory, application.getSncpRpcGroups(), sncpClient, null, null, null);
|
||||||
}
|
}
|
||||||
@@ -385,7 +384,7 @@ public abstract class NodeServer {
|
|||||||
if (entry.getName().contains(Resource.PARENT_NAME)) {
|
if (entry.getName().contains(Resource.PARENT_NAME)) {
|
||||||
throw new RedkaleException("<name> value cannot contains '" + Resource.PARENT_NAME + "' in " + entry.getProperty());
|
throw new RedkaleException("<name> value cannot contains '" + Resource.PARENT_NAME + "' in " + entry.getProperty());
|
||||||
}
|
}
|
||||||
if (!entry.isEmptyGroup() && !entry.isRemote() && rpcGroups.containsGroup(entry.getGroup())) {
|
if (!entry.isEmptyGroup() && !entry.isRemote() && !rpcGroups.containsGroup(entry.getGroup())) {
|
||||||
throw new RedkaleException("Not found group(" + entry.getGroup() + ")");
|
throw new RedkaleException("Not found group(" + entry.getGroup() + ")");
|
||||||
}
|
}
|
||||||
Service oldOther = resourceFactory.find(entry.getName(), serviceImplClass);
|
Service oldOther = resourceFactory.find(entry.getName(), serviceImplClass);
|
||||||
@@ -424,11 +423,11 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
service = serviceImplClass.getDeclaredConstructor().newInstance();
|
service = serviceImplClass.getDeclaredConstructor().newInstance();
|
||||||
} else if (ws || localMode) { //本地模式
|
} else if (ws || localMode) { //本地模式
|
||||||
AsmMethodBoost methodBoost = application.createAsmMethodBoost(serviceImplClass);
|
AsmMethodBoost methodBoost = application.createAsmMethodBoost(false, serviceImplClass);
|
||||||
service = Sncp.createLocalService(serverClassLoader, resourceName, serviceImplClass,
|
service = Sncp.createLocalService(serverClassLoader, resourceName, serviceImplClass,
|
||||||
methodBoost, appResourceFactory, rpcGroups, this.sncpClient, agent, group, entry.getProperty());
|
methodBoost, appResourceFactory, rpcGroups, this.sncpClient, agent, group, entry.getProperty());
|
||||||
} else {
|
} else {
|
||||||
AsmMethodBoost methodBoost = application.createAsmMethodBoost(serviceImplClass);
|
AsmMethodBoost methodBoost = application.createAsmMethodBoost(true, serviceImplClass);
|
||||||
service = Sncp.createRemoteService(serverClassLoader, resourceName, serviceImplClass,
|
service = Sncp.createRemoteService(serverClassLoader, resourceName, serviceImplClass,
|
||||||
methodBoost, appResourceFactory, rpcGroups, this.sncpClient, agent, group, entry.getProperty());
|
methodBoost, appResourceFactory, rpcGroups, this.sncpClient, agent, group, entry.getProperty());
|
||||||
}
|
}
|
||||||
@@ -482,10 +481,11 @@ public abstract class NodeServer {
|
|||||||
new ArrayList<>(localServices).forEach(y -> {
|
new ArrayList<>(localServices).forEach(y -> {
|
||||||
resourceFactory.inject(Sncp.getResourceName(y), y, NodeServer.this);
|
resourceFactory.inject(Sncp.getResourceName(y), y, NodeServer.this);
|
||||||
});
|
});
|
||||||
new ArrayList<>(remoteServices).forEach(y -> {
|
//远程模式不可inject, 里面存在@Resource.required=true依赖
|
||||||
resourceFactory.inject(Sncp.getResourceName(y), y, NodeServer.this);
|
// new ArrayList<>(remoteServices).forEach(y -> {
|
||||||
calcMaxLength(y);
|
// resourceFactory.inject(Sncp.getResourceName(y), y, NodeServer.this);
|
||||||
});
|
// calcMaxLength(y);
|
||||||
|
// });
|
||||||
|
|
||||||
if (sb != null) {
|
if (sb != null) {
|
||||||
remoteServices.forEach(y -> {
|
remoteServices.forEach(y -> {
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
private Map<String, CacheAction> actionMap;
|
private Map<String, CacheAction> actionMap;
|
||||||
|
|
||||||
public CacheAsmMethodBoost(Class serviceType) {
|
public CacheAsmMethodBoost(boolean remote, Class serviceType) {
|
||||||
super(serviceType);
|
super(remote, serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -52,12 +52,14 @@ public class CacheModuleEngine extends ModuleEngine {
|
|||||||
/**
|
/**
|
||||||
* 动态扩展类的方法
|
* 动态扩展类的方法
|
||||||
*
|
*
|
||||||
|
* @param remote 是否远程模式
|
||||||
* @param serviceClass 类
|
* @param serviceClass 类
|
||||||
*
|
*
|
||||||
* @return 方法动态扩展器
|
* @return 方法动态扩展器
|
||||||
*/
|
*/
|
||||||
public AsmMethodBoost createAsmMethodBoost(Class serviceClass) {
|
@Override
|
||||||
return new CacheAsmMethodBoost(serviceClass);
|
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||||
|
return new CacheAsmMethodBoost(remote, serviceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ public class LockAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class, DynForLock.class);
|
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class, DynForLock.class);
|
||||||
|
|
||||||
public LockAsmMethodBoost(Class serviceType) {
|
public LockAsmMethodBoost(boolean remote, Class serviceType) {
|
||||||
super(serviceType);
|
super(remote, serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -52,12 +52,13 @@ public class LockModuleEngine extends ModuleEngine {
|
|||||||
/**
|
/**
|
||||||
* 动态扩展类的方法
|
* 动态扩展类的方法
|
||||||
*
|
*
|
||||||
|
* @param remote 是否远程模式
|
||||||
* @param serviceClass 类
|
* @param serviceClass 类
|
||||||
*
|
*
|
||||||
* @return 方法动态扩展器
|
* @return 方法动态扩展器
|
||||||
*/
|
*/
|
||||||
public AsmMethodBoost createAsmMethodBoost(Class serviceClass) {
|
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||||
return new LockAsmMethodBoost(serviceClass);
|
return new LockAsmMethodBoost(remote, serviceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Messaged.class);
|
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Messaged.class);
|
||||||
|
|
||||||
public MessageAsmMethodBoost(Class serviceType) {
|
public MessageAsmMethodBoost(boolean remote, Class serviceType) {
|
||||||
super(serviceType);
|
super(remote, serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class CacheInstanceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void run1() throws Exception {
|
public void run1() throws Exception {
|
||||||
Class<CacheInstance> serviceClass = CacheInstance.class;
|
Class<CacheInstance> serviceClass = CacheInstance.class;
|
||||||
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(serviceClass);
|
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass);
|
||||||
SncpRpcGroups grous = new SncpRpcGroups();
|
SncpRpcGroups grous = new SncpRpcGroups();
|
||||||
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
||||||
SncpClient client = new SncpClient("", iGroup, 0, new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
SncpClient client = new SncpClient("", iGroup, 0, new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||||
|
|||||||
Reference in New Issue
Block a user