增加RedkaleException

This commit is contained in:
redkale
2023-02-05 17:19:03 +08:00
parent 2751e6475e
commit 0aa8e8653c
39 changed files with 190 additions and 108 deletions

View File

@@ -290,7 +290,7 @@ public final class Application {
this.confPath = confFile.toURI(); this.confPath = confFile.toURI();
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
{ //设置系统变量 { //设置系统变量
AnyValue propertiesConf = this.config.getAnyValue("properties"); AnyValue propertiesConf = this.config.getAnyValue("properties");
@@ -450,7 +450,7 @@ public final class Application {
try { try {
loadResourceProperties(); loadResourceProperties();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
//------------------------------------ 配置 <transport> 节点 ------------------------------------ //------------------------------------ 配置 <transport> 节点 ------------------------------------
TransportStrategy strategy = null; TransportStrategy strategy = null;
@@ -533,7 +533,7 @@ public final class Application {
AnyValue mqConf = mqConfs[i]; AnyValue mqConf = mqConfs[i];
String mqname = mqConf.getValue("name", ""); String mqname = mqConf.getValue("name", "");
if (mqnames.contains(mqname)) { if (mqnames.contains(mqname)) {
throw new RuntimeException("mq.name(" + mqname + ") is repeat"); throw new RedkaleException("mq.name(" + mqname + ") is repeat");
} }
mqnames.add(mqname); mqnames.add(mqname);
String namex = mqConf.getValue("names"); String namex = mqConf.getValue("names");
@@ -543,7 +543,7 @@ public final class Application {
continue; continue;
} }
if (mqnames.contains(n.trim())) { if (mqnames.contains(n.trim())) {
throw new RuntimeException("mq.name(" + n.trim() + ") is repeat"); throw new RedkaleException("mq.name(" + n.trim() + ") is repeat");
} }
mqnames.add(n.trim()); mqnames.add(n.trim());
} }
@@ -1009,7 +1009,7 @@ public final class Application {
} }
for (char ch : name.toCharArray()) { for (char ch : name.toCharArray()) {
if (!((ch >= '0' && ch <= '9') || ch == '_' || ch == '.' || ch == '-' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符 if (!((ch >= '0' && ch <= '9') || ch == '_' || ch == '.' || ch == '-' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符
throw new RuntimeException("name only 0-9 a-z A-Z _ - . cannot begin 0-9"); throw new RedkaleException("name only 0-9 a-z A-Z _ - . cannot begin 0-9");
} }
} }
return name; return name;
@@ -1335,7 +1335,7 @@ public final class Application {
final String group = conf.getValue("name", ""); final String group = conf.getValue("name", "");
final String protocol = conf.getValue("protocol", Transport.DEFAULT_NETPROTOCOL).toUpperCase(); final String protocol = conf.getValue("protocol", Transport.DEFAULT_NETPROTOCOL).toUpperCase();
if (!"TCP".equalsIgnoreCase(protocol) && !"UDP".equalsIgnoreCase(protocol)) { if (!"TCP".equalsIgnoreCase(protocol) && !"UDP".equalsIgnoreCase(protocol)) {
throw new RuntimeException("Not supported Transport Protocol " + conf.getValue("protocol")); throw new RedkaleException("Not supported Transport Protocol " + conf.getValue("protocol"));
} }
TransportGroupInfo ginfo = new TransportGroupInfo(group, protocol, new LinkedHashSet<>()); TransportGroupInfo ginfo = new TransportGroupInfo(group, protocol, new LinkedHashSet<>());
for (AnyValue node : conf.getAnyValues("node")) { for (AnyValue node : conf.getAnyValues("node")) {
@@ -1576,7 +1576,7 @@ public final class Application {
} }
} }
if (watchs.size() > 1) { if (watchs.size() > 1) {
throw new RuntimeException("Found one more WATCH Server"); throw new RedkaleException("Found one more WATCH Server");
} }
this.watching = !watchs.isEmpty(); this.watching = !watchs.isEmpty();
@@ -1706,7 +1706,7 @@ public final class Application {
} }
final Class<? extends NodeServer> old = nodeClasses.get(p); final Class<? extends NodeServer> old = nodeClasses.get(p);
if (old != null && old != type) { if (old != null && old != type) {
throw new RuntimeException("Protocol(" + p + ") had NodeServer-Class(" + old.getName() + ") but repeat NodeServer-Class(" + type.getName() + ")"); throw new RedkaleException("Protocol(" + p + ") had NodeServer-Class(" + old.getName() + ") but repeat NodeServer-Class(" + type.getName() + ")");
} }
nodeClasses.put(p, type); nodeClasses.put(p, type);
} }

View File

@@ -612,7 +612,7 @@ public final class ClassFilter<T> {
} else if (root.isDirectory()) { } else if (root.isDirectory()) {
if (exclude != null && exclude.equals(root)) return; if (exclude != null && exclude.equals(root)) return;
File[] lfs = root.listFiles(); File[] lfs = root.listFiles();
if (lfs == null) throw new RuntimeException("File(" + root + ") cannot listFiles()"); if (lfs == null) throw new RedkaleException("File(" + root + ") cannot listFiles()");
for (File f : lfs) { for (File f : lfs) {
loadClassFiles(exclude, f, files); loadClassFiles(exclude, f, files);
} }

View File

@@ -153,12 +153,12 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
String cname = getClass().getName(); String cname = getClass().getName();
this.sourceResourceName = manager.getProperty(cname + ".source"); this.sourceResourceName = manager.getProperty(cname + ".source");
if (this.sourceResourceName == null || this.sourceResourceName.isEmpty()) { if (this.sourceResourceName == null || this.sourceResourceName.isEmpty()) {
throw new RuntimeException("not found logging.property " + cname + ".source"); throw new RedkaleException("not found logging.property " + cname + ".source");
} }
String tagstr = manager.getProperty(cname + ".tag"); String tagstr = manager.getProperty(cname + ".tag");
if (tagstr != null && !tagstr.isEmpty()) { if (tagstr != null && !tagstr.isEmpty()) {
if (!checkTagName(tagstr.replaceAll("\\$\\{.+\\}", ""))) { if (!checkTagName(tagstr.replaceAll("\\$\\{.+\\}", ""))) {
throw new RuntimeException("found illegal logging.property " + cname + ".tag = " + tagstr); throw new RedkaleException("found illegal logging.property " + cname + ".tag = " + tagstr);
} }
this.tag = tagstr.replace("${" + RESNAME_APP_NAME + "}", System.getProperty(RESNAME_APP_NAME, "")); this.tag = tagstr.replace("${" + RESNAME_APP_NAME + "}", System.getProperty(RESNAME_APP_NAME, ""));
if (this.tag.contains("%")) { if (this.tag.contains("%")) {

View File

@@ -364,7 +364,7 @@ public class NodeHttpServer extends NodeServer {
if (mqname != null) { if (mqname != null) {
agent0 = application.getMessageAgent(mqname); agent0 = application.getMessageAgent(mqname);
if (agent0 == null) { if (agent0 == null) {
throw new RuntimeException("not found " + MessageAgent.class.getSimpleName() + " config for (name=" + mqname + ")"); throw new RedkaleException("not found " + MessageAgent.class.getSimpleName() + " config for (name=" + mqname + ")");
} }
} }
final MessageAgent messageAgent = agent0; final MessageAgent messageAgent = agent0;

View File

@@ -120,7 +120,7 @@ public abstract class NodeServer {
RedkaleClassLoader.putReflectionDeclaredConstructors(clazz, clazz.getName(), Application.class, AnyValue.class); RedkaleClassLoader.putReflectionDeclaredConstructors(clazz, clazz.getName(), Application.class, AnyValue.class);
return clazz.getDeclaredConstructor(Application.class, AnyValue.class).newInstance(application, serconf); return clazz.getDeclaredConstructor(Application.class, AnyValue.class).newInstance(application, serconf);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
@@ -131,7 +131,7 @@ public abstract class NodeServer {
this.sncpAddress = new InetSocketAddress(host.isEmpty() ? application.localAddress.getAddress().getHostAddress() : host, this.serverConf.getIntValue("port")); this.sncpAddress = new InetSocketAddress(host.isEmpty() ? application.localAddress.getAddress().getHostAddress() : host, this.serverConf.getIntValue("port"));
this.sncpGroup = application.getSncpTransportFactory().findGroupName(this.sncpAddress); this.sncpGroup = application.getSncpTransportFactory().findGroupName(this.sncpAddress);
//单向SNCP服务不需要对等group //单向SNCP服务不需要对等group
//if (this.sncpGroup == null) throw new RuntimeException("Server (" + String.valueOf(config).replaceAll("\\s+", " ") + ") not found <group> info"); //if (this.sncpGroup == null) throw new RedkaleException("Server (" + String.valueOf(config).replaceAll("\\s+", " ") + ") not found <group> info");
} }
//单点服务不会有 sncpAddress、sncpGroup //单点服务不会有 sncpAddress、sncpGroup
if (this.sncpAddress != null) { if (this.sncpAddress != null) {
@@ -340,7 +340,7 @@ public abstract class NodeServer {
return null; //远程模式不需要注入 CacheSource return null; //远程模式不需要注入 CacheSource
} }
if (!(srcObj instanceof Service)) { if (!(srcObj instanceof Service)) {
throw new RuntimeException("CacheSource must be inject in Service, cannot in " + srcObj); throw new RedkaleException("CacheSource must be inject in Service, cannot in " + srcObj);
} }
final Service srcService = (Service) srcObj; final Service srcService = (Service) srcObj;
SncpOldClient client = Sncp.getSncpOldClient(srcService); SncpOldClient client = Sncp.getSncpOldClient(srcService);
@@ -467,7 +467,7 @@ public abstract class NodeServer {
} }
} }
if (entry.getName().contains("$")) { if (entry.getName().contains("$")) {
throw new RuntimeException("<name> value cannot contains '$' in " + entry.getProperty()); throw new RedkaleException("<name> value cannot contains '$' in " + entry.getProperty());
} }
Service oldother = resourceFactory.find(entry.getName(), serviceImplClass); Service oldother = resourceFactory.find(entry.getName(), serviceImplClass);
if (oldother != null) { //Server加载Service时需要判断是否已经加载过了。 if (oldother != null) { //Server加载Service时需要判断是否已经加载过了。
@@ -523,7 +523,7 @@ public abstract class NodeServer {
if (rf.find(resourceName, restype) == null) { if (rf.find(resourceName, restype) == null) {
regFactory.register(resourceName, restype, service); regFactory.register(resourceName, restype, service);
} else if (isSNCP() && !entry.isAutoload()) { } else if (isSNCP() && !entry.isAutoload()) {
throw new RuntimeException(restype.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:" + resourceName + ", group:" + groups + ") is repeat."); throw new RedkaleException(restype.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:" + resourceName + ", group:" + groups + ") is repeat.");
} }
if (Sncp.isRemote(service)) { if (Sncp.isRemote(service)) {
remoteServices.add(service); remoteServices.add(service);
@@ -545,7 +545,7 @@ public abstract class NodeServer {
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
throw ex; throw ex;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
}; };
if (entry.isExpect()) { if (entry.isExpect()) {

View File

@@ -241,7 +241,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
@Override @Override
public void register(Application application) { public void register(Application application) {
if (isApplicationHealth()) { if (isApplicationHealth()) {
throw new RuntimeException("application.nodeid=" + nodeid + " exists in cluster"); throw new RedkaleException("application.nodeid=" + nodeid + " exists in cluster");
} }
deregister(application); deregister(application);

View File

@@ -4,6 +4,8 @@
*/ */
package org.redkale.convert; package org.redkale.convert;
import org.redkale.util.RedkaleException;
/** /**
* 序列化自定义异常类 * 序列化自定义异常类
* *
@@ -12,7 +14,7 @@ package org.redkale.convert;
* *
* @author zhangjx * @author zhangjx
*/ */
public class ConvertException extends RuntimeException { public class ConvertException extends RedkaleException {
public ConvertException() { public ConvertException() {
super(); super();

View File

@@ -62,7 +62,7 @@ public final class EnumSimpledCoder<R extends Reader, W extends Writer, E extend
this.enumToValues = map1; this.enumToValues = map1;
this.valueToEnums = map2; this.valueToEnums = map2;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new ConvertException(e);
} }
} }
} }

View File

@@ -48,7 +48,7 @@ public final class IntSimpledCoder<R extends Reader, W extends Writer> extends S
out.writeSmallString("0x0"); out.writeSmallString("0x0");
} else { } else {
if (value < 0) { if (value < 0) {
throw new NumberFormatException("Negative values (" + value + ") are not supported"); throw new ConvertException("Negative values (" + value + ") are not supported");
} }
out.writeSmallString("0x" + Integer.toHexString(value)); out.writeSmallString("0x" + Integer.toHexString(value));
} }

View File

@@ -48,7 +48,7 @@ public final class LongSimpledCoder<R extends Reader, W extends Writer> extends
out.writeSmallString("0x0"); out.writeSmallString("0x0");
} else { } else {
if (value < 0) { if (value < 0) {
throw new NumberFormatException("Negative values (" + value + ") are not supported"); throw new ConvertException("Negative values (" + value + ") are not supported");
} }
out.writeSmallString("0x" + Long.toHexString(value)); out.writeSmallString("0x" + Long.toHexString(value));
} }

View File

@@ -100,7 +100,7 @@ public class JsonByteBufferReader extends JsonReader {
} }
return Character.lowSurrogate(uc); return Character.lowSurrogate(uc);
} else { } else {
throw new RuntimeException(new UnmappableCharacterException(4)); throw new ConvertException(new UnmappableCharacterException(4));
} }
} }

View File

@@ -16,6 +16,7 @@ import org.redkale.boot.*;
import org.redkale.convert.Convert; import org.redkale.convert.Convert;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.net.http.*; import org.redkale.net.http.*;
import org.redkale.util.RedkaleException;
/** /**
* 没有配置MQ且也没有ClusterAgent的情况下实现的默认HttpMessageClient实例 * 没有配置MQ且也没有ClusterAgent的情况下实现的默认HttpMessageClient实例
@@ -159,7 +160,7 @@ public class HttpMessageLocalClient extends HttpMessageClient {
try { try {
servlet.execute(req, resp); servlet.execute(req, resp);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }

View File

@@ -91,7 +91,7 @@ public abstract class MessageAgent implements Resourcable {
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
throw ex; throw ex;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
// application (it doesn't execute completion handlers). // application (it doesn't execute completion handlers).
@@ -214,11 +214,11 @@ public abstract class MessageAgent implements Resourcable {
return name; return name;
} }
if (name.charAt(0) >= '0' && name.charAt(0) <= '9') { if (name.charAt(0) >= '0' && name.charAt(0) <= '9') {
throw new RuntimeException("name only 0-9 a-z A-Z _ cannot begin 0-9"); throw new RedkaleException("name only 0-9 a-z A-Z _ cannot begin 0-9");
} }
for (char ch : name.toCharArray()) { for (char ch : name.toCharArray()) {
if (!((ch >= '0' && ch <= '9') || ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符 if (!((ch >= '0' && ch <= '9') || ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符
throw new RuntimeException("name only 0-9 a-z A-Z _ cannot begin 0-9"); throw new RedkaleException("name only 0-9 a-z A-Z _ cannot begin 0-9");
} }
} }
return name; return name;
@@ -313,7 +313,7 @@ public abstract class MessageAgent implements Resourcable {
httpNodesLock.lock(); httpNodesLock.lock();
try { try {
if (messageNodes.containsKey(consumerid)) { if (messageNodes.containsKey(consumerid)) {
throw new RuntimeException("consumerid(" + consumerid + ") is repeat"); throw new RedkaleException("consumerid(" + consumerid + ") is repeat");
} }
HttpMessageProcessor processor = new HttpMessageProcessor(this.logger, httpMessageClient, getHttpProducer(), ns, service, servlet); HttpMessageProcessor processor = new HttpMessageProcessor(this.logger, httpMessageClient, getHttpProducer(), ns, service, servlet);
this.messageNodes.put(consumerid, new MessageConsumerNode(ns, service, servlet, processor, createConsumer(topics, consumerid, processor))); this.messageNodes.put(consumerid, new MessageConsumerNode(ns, service, servlet, processor, createConsumer(topics, consumerid, processor)));
@@ -336,7 +336,7 @@ public abstract class MessageAgent implements Resourcable {
sncpNodesLock.lock(); sncpNodesLock.lock();
try { try {
if (messageNodes.containsKey(consumerid)) { if (messageNodes.containsKey(consumerid)) {
throw new RuntimeException("consumerid(" + consumerid + ") is repeat"); throw new RedkaleException("consumerid(" + consumerid + ") is repeat");
} }
SncpMessageProcessor processor = new SncpMessageProcessor(this.logger, sncpMessageClient, getSncpProducer(), ns, service, servlet); SncpMessageProcessor processor = new SncpMessageProcessor(this.logger, sncpMessageClient, getSncpProducer(), ns, service, servlet);
this.messageNodes.put(consumerid, new MessageConsumerNode(ns, service, servlet, processor, createConsumer(new String[]{topic}, consumerid, processor))); this.messageNodes.put(consumerid, new MessageConsumerNode(ns, service, servlet, processor, createConsumer(new String[]{topic}, consumerid, processor)));

View File

@@ -455,7 +455,7 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
public void setReadBuffer(ByteBuffer buffer) { public void setReadBuffer(ByteBuffer buffer) {
if (this.readBuffer != null) { if (this.readBuffer != null) {
throw new RuntimeException("repeat AsyncConnection.setReadBuffer"); throw new RedkaleException("repeat AsyncConnection.setReadBuffer");
} }
this.readBuffer = buffer; this.readBuffer = buffer;
} }
@@ -684,7 +684,7 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
protected void setReadSSLBuffer(ByteBuffer buffer) { protected void setReadSSLBuffer(ByteBuffer buffer) {
if (this.readSSLHalfBuffer != null) { if (this.readSSLHalfBuffer != null) {
throw new RuntimeException("repeat AsyncConnection.setReadSSLBuffer"); throw new RedkaleException("repeat AsyncConnection.setReadSSLBuffer");
} }
this.readSSLHalfBuffer = buffer; this.readSSLHalfBuffer = buffer;
} }

View File

@@ -111,7 +111,7 @@ public class AsyncIOGroup extends AsyncGroup {
this.connectThread = null; this.connectThread = null;
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
@@ -133,7 +133,7 @@ public class AsyncIOGroup extends AsyncGroup {
return this; return this;
} }
if (closed.get()) { if (closed.get()) {
throw new RuntimeException("group is closed"); throw new RedkaleException("group is closed");
} }
for (int i = 0; i < this.ioReadThreads.length; i++) { for (int i = 0; i < this.ioReadThreads.length; i++) {
this.ioReadThreads[i].start(); this.ioReadThreads[i].start();
@@ -214,7 +214,7 @@ public class AsyncIOGroup extends AsyncGroup {
try { try {
return newTCPClientConnection(null); return newTCPClientConnection(null);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
@@ -302,7 +302,7 @@ public class AsyncIOGroup extends AsyncGroup {
try { try {
return newUDPClientConnection(null); return newUDPClientConnection(null);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }

View File

@@ -64,7 +64,7 @@ public class AsyncIOThread extends WorkThread {
return; return;
} }
if (key.selector() != selector) { if (key.selector() != selector) {
throw new RuntimeException("NioThread.selector not the same to SelectionKey.selector"); throw new RedkaleException("NioThread.selector not the same to SelectionKey.selector");
} }
if ((key.interestOps() & opt) != 0) { if ((key.interestOps() & opt) != 0) {
return; return;

View File

@@ -188,7 +188,7 @@ class AsyncNioTcpProtocolServer extends ProtocolServer {
} else if (t instanceof RuntimeException) { } else if (t instanceof RuntimeException) {
throw (RuntimeException) t; throw (RuntimeException) t;
} else { } else {
throw new RuntimeException(t); throw new RedkaleException(t);
} }
}); });
} }

View File

@@ -181,7 +181,7 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
} else if (t instanceof RuntimeException) { } else if (t instanceof RuntimeException) {
throw (RuntimeException) t; throw (RuntimeException) t;
} else { } else {
throw new RuntimeException(t); throw new RedkaleException(t);
} }
}); });
} }

View File

@@ -10,7 +10,7 @@ import java.net.*;
import java.util.Set; import java.util.Set;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import org.redkale.util.AnyValue; import org.redkale.util.*;
/** /**
* 协议底层Server * 协议底层Server
@@ -56,7 +56,7 @@ public abstract class ProtocolServer {
} else if ("UDP".equalsIgnoreCase(protocol)) { } else if ("UDP".equalsIgnoreCase(protocol)) {
return new AsyncNioUdpProtocolServer(context); return new AsyncNioUdpProtocolServer(context);
} else { } else {
throw new RuntimeException(ProtocolServer.class.getSimpleName() + " not support protocol " + protocol); throw new RedkaleException(ProtocolServer.class.getSimpleName() + " not support protocol " + protocol);
} }
} }

View File

@@ -134,7 +134,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
this.responsePoolSize = config.getIntValue("responsePoolSize", 1024); this.responsePoolSize = config.getIntValue("responsePoolSize", 1024);
this.name = config.getValue("name", "Server-" + config.getValue("protocol", netprotocol).replaceFirst("\\..+", "").toUpperCase() + "-" + this.address.getPort()); this.name = config.getValue("name", "Server-" + config.getValue("protocol", netprotocol).replaceFirst("\\..+", "").toUpperCase() + "-" + this.address.getPort());
if (!this.name.matches("^[a-zA-Z][\\w_-]{1,64}$")) { if (!this.name.matches("^[a-zA-Z][\\w_-]{1,64}$")) {
throw new RuntimeException("server.name (" + this.name + ") is illegal"); throw new RedkaleException("server.name (" + this.name + ") is illegal");
} }
AnyValue sslConf = config.getAnyValue("ssl"); AnyValue sslConf = config.getAnyValue("ssl");
if (sslConf != null) { if (sslConf != null) {
@@ -544,7 +544,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
if (root.isDirectory()) { if (root.isDirectory()) {
File[] lfs = root.listFiles(); File[] lfs = root.listFiles();
if (lfs == null) { if (lfs == null) {
throw new RuntimeException("File(" + root + ") cannot listFiles()"); throw new RedkaleException("File(" + root + ") cannot listFiles()");
} }
for (File f : lfs) { for (File f : lfs) {
set.add(f.toURI().toURL()); set.add(f.toURI().toURL());
@@ -558,7 +558,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
if (set.isEmpty()) { if (set.isEmpty()) {
return new URL[0]; return new URL[0];

View File

@@ -20,7 +20,7 @@ import javax.net.ssl.SSLContext;
import org.redkale.annotation.ConstructorParameters; import org.redkale.annotation.ConstructorParameters;
import org.redkale.convert.ConvertDisabled; import org.redkale.convert.ConvertDisabled;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.util.Utility; import org.redkale.util.*;
/** /**
* 传输客户端 * 传输客户端
@@ -268,7 +268,7 @@ public final class Transport {
final SocketAddress addr = addr0; final SocketAddress addr = addr0;
final boolean rand = addr == null; //是否随机取地址 final boolean rand = addr == null; //是否随机取地址
if (rand && nodes.length < 1) { if (rand && nodes.length < 1) {
throw new RuntimeException("Transport (" + this.name + ") have no remoteAddress list"); throw new RedkaleException("Transport (" + this.name + ") have no remoteAddress list");
} }
try { try {
if (!tcp) { // UDP if (!tcp) { // UDP
@@ -315,7 +315,7 @@ public final class Transport {
} }
return pollConnection0(nodes, null, now); return pollConnection0(nodes, null, now);
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException("transport address = " + addr, ex); throw new RedkaleException("transport address = " + addr, ex);
} }
} }

View File

@@ -209,21 +209,21 @@ public class TransportFactory {
public boolean addGroupInfo(TransportGroupInfo info) { public boolean addGroupInfo(TransportGroupInfo info) {
if (info == null) { if (info == null) {
throw new RuntimeException("TransportGroupInfo can not null"); throw new RedkaleException("TransportGroupInfo can not null");
} }
if (info.addresses == null) { if (info.addresses == null) {
throw new RuntimeException("TransportGroupInfo.addresses can not null"); throw new RedkaleException("TransportGroupInfo.addresses can not null");
} }
if (!checkName(info.name)) { if (!checkName(info.name)) {
throw new RuntimeException("Transport.group.name only 0-9 a-z A-Z _ cannot begin 0-9"); throw new RedkaleException("Transport.group.name only 0-9 a-z A-Z _ cannot begin 0-9");
} }
TransportGroupInfo old = groupInfos.get(info.name); TransportGroupInfo old = groupInfos.get(info.name);
if (old != null && !old.protocol.equals(info.protocol)) { if (old != null && !old.protocol.equals(info.protocol)) {
throw new RuntimeException("Transport.group.name repeat but protocol is different"); throw new RedkaleException("Transport.group.name repeat but protocol is different");
} }
for (InetSocketAddress addr : info.addresses) { for (InetSocketAddress addr : info.addresses) {
if (!groupAddrs.getOrDefault(addr, info.name).equals(info.name)) { if (!groupAddrs.getOrDefault(addr, info.name).equals(info.name)) {
throw new RuntimeException(addr + " repeat but different group.name"); throw new RedkaleException(addr + " repeat but different group.name");
} }
} }
if (old == null) { if (old == null) {

View File

@@ -3,6 +3,8 @@
*/ */
package org.redkale.net.http; package org.redkale.net.http;
import org.redkale.util.RedkaleException;
/** /**
* Http自定义异常类 * Http自定义异常类
* *
@@ -13,7 +15,7 @@ package org.redkale.net.http;
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public class HttpException extends RuntimeException { public class HttpException extends RedkaleException {
public HttpException() { public HttpException() {
super(); super();

View File

@@ -3,6 +3,8 @@
*/ */
package org.redkale.net.sncp; package org.redkale.net.sncp;
import org.redkale.util.RedkaleException;
/** /**
* Sncp自定义异常类 * Sncp自定义异常类
* *
@@ -13,7 +15,7 @@ package org.redkale.net.sncp;
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public class SncpException extends RuntimeException { public class SncpException extends RedkaleException {
public SncpException() { public SncpException() {
super(); super();

View File

@@ -145,9 +145,9 @@ public class RetResult<T> implements Serializable {
try { try {
return future.get(timeout, unit); return future.get(timeout, unit);
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
throw new RuntimeException(ex.getCause()); throw new RedkaleException(ex.getCause());
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }

View File

@@ -5,6 +5,8 @@
*/ */
package org.redkale.service; package org.redkale.service;
import org.redkale.util.RedkaleException;
/** /**
* 供RPC协议使用 * 供RPC协议使用
* *
@@ -13,7 +15,7 @@ package org.redkale.service;
* *
* @author zhangjx * @author zhangjx
*/ */
public class RpcRemoteException extends RuntimeException { public class RpcRemoteException extends RedkaleException {
public RpcRemoteException() { public RpcRemoteException() {
super(); super();

View File

@@ -3,6 +3,8 @@
*/ */
package org.redkale.source; package org.redkale.source;
import org.redkale.util.RedkaleException;
/** /**
* 数据源自定义异常类 * 数据源自定义异常类
* *
@@ -13,7 +15,7 @@ package org.redkale.source;
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public class SourceException extends RuntimeException { public class SourceException extends RedkaleException {
public SourceException() { public SourceException() {
super(); super();

View File

@@ -225,7 +225,7 @@ public interface Attribute<T, F> {
try { try {
return create(clazz, fieldName, (Class) null, clazz.getDeclaredField(fieldName), (java.lang.reflect.Method) null, (java.lang.reflect.Method) null, null); return create(clazz, fieldName, (Class) null, clazz.getDeclaredField(fieldName), (java.lang.reflect.Method) null, (java.lang.reflect.Method) null, null);
} catch (NoSuchFieldException | SecurityException ex) { } catch (NoSuchFieldException | SecurityException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -244,7 +244,7 @@ public interface Attribute<T, F> {
try { try {
return create(clazz, fieldName, (Class) null, clazz.getDeclaredField(fieldName), (java.lang.reflect.Method) null, (java.lang.reflect.Method) null, attach); return create(clazz, fieldName, (Class) null, clazz.getDeclaredField(fieldName), (java.lang.reflect.Method) null, (java.lang.reflect.Method) null, attach);
} catch (NoSuchFieldException | SecurityException ex) { } catch (NoSuchFieldException | SecurityException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -753,7 +753,7 @@ public interface Attribute<T, F> {
fieldkey = (fieldAlias == null ? "" : ("0_" + fieldAlias + "_")) + "2_" + setter.getName(); fieldkey = (fieldAlias == null ? "" : ("0_" + fieldAlias + "_")) + "2_" + setter.getName();
} }
if (fieldAlias == null && fieldType == null && tgetter == null && tsetter == null && tfield == null) { if (fieldAlias == null && fieldType == null && tgetter == null && tsetter == null && tfield == null) {
throw new RuntimeException("[" + clazz + "]have no public field or setter or getter"); throw new RedkaleException("[" + clazz + "]have no public field or setter or getter");
} }
final String fieldName = fieldAlias; final String fieldName = fieldAlias;
Class column = fieldType; Class column = fieldType;
@@ -768,9 +768,9 @@ public interface Attribute<T, F> {
column = tsetter.getParameterTypes()[0]; column = tsetter.getParameterTypes()[0];
generictype = tsetter.getGenericParameterTypes()[0]; generictype = tsetter.getGenericParameterTypes()[0];
} else if (fieldType == null) { } else if (fieldType == null) {
throw new RuntimeException("[" + clazz + "]have no public field or setter or getter"); throw new RedkaleException("[" + clazz + "]have no public field or setter or getter");
} else if (column == null) { } else if (column == null) {
throw new RuntimeException("[" + clazz + "]have no field type"); throw new RedkaleException("[" + clazz + "]have no field type");
} }
boolean checkCast = false; boolean checkCast = false;
if (generictype instanceof java.lang.reflect.TypeVariable) { if (generictype instanceof java.lang.reflect.TypeVariable) {
@@ -966,7 +966,7 @@ public interface Attribute<T, F> {
mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false); mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false);
m = 3; m = 3;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); //不可能会发生 throw new RedkaleException(ex); //不可能会发生
} }
} }
if (!tfield.getType().isPrimitive() && tfield.getGenericType() instanceof TypeVariable) { if (!tfield.getType().isPrimitive() && tfield.getGenericType() instanceof TypeVariable) {
@@ -984,7 +984,7 @@ public interface Attribute<T, F> {
mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false); mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false);
m = 3; m = 3;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); //不可能会发生 throw new RedkaleException(ex); //不可能会发生
} }
} }
mv.visitMethodInsn(INVOKEVIRTUAL, interName, tsetter.getName(), Type.getMethodDescriptor(tsetter), false); mv.visitMethodInsn(INVOKEVIRTUAL, interName, tsetter.getName(), Type.getMethodDescriptor(tsetter), false);
@@ -1045,7 +1045,7 @@ public interface Attribute<T, F> {
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), _attach); RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), _attach);
return rs; return rs;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }

View File

@@ -205,7 +205,7 @@ public interface Creator<T> {
return creator; return creator;
} }
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
throw new RuntimeException("[" + clazz + "] is a interface or abstract class, cannot create it's Creator."); throw new RedkaleException("[" + clazz + "] is a interface or abstract class, cannot create it's Creator.");
} }
for (final Method method : clazz.getDeclaredMethods()) { //查找类中是否存在提供创建Creator实例的静态方法 for (final Method method : clazz.getDeclaredMethods()) { //查找类中是否存在提供创建Creator实例的静态方法
if (!Modifier.isStatic(method.getModifiers())) { if (!Modifier.isStatic(method.getModifiers())) {
@@ -226,7 +226,7 @@ public interface Creator<T> {
return c; return c;
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
final String supDynName = Creator.class.getName().replace('.', '/'); final String supDynName = Creator.class.getName().replace('.', '/');
@@ -336,7 +336,7 @@ public interface Creator<T> {
final Constructor<T> constructor = constructor0; final Constructor<T> constructor = constructor0;
final SimpleEntry<String, Class>[] constructorParameters = constructorParameters0; final SimpleEntry<String, Class>[] constructorParameters = constructorParameters0;
if (constructor == null || constructorParameters == null) { if (constructor == null || constructorParameters == null) {
throw new RuntimeException("[" + clazz + "] have no public or ConstructorParameters-Annotation constructor."); throw new RedkaleException("[" + clazz + "] have no public or ConstructorParameters-Annotation constructor.");
} }
final int[] iconsts = {ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5}; final int[] iconsts = {ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5};
//------------------------------------------------------------- //-------------------------------------------------------------
@@ -497,7 +497,7 @@ public interface Creator<T> {
Method pm = bigct.getMethod(ct.getSimpleName() + "Value"); Method pm = bigct.getMethod(ct.getSimpleName() + "Value");
mv.visitMethodInsn(INVOKEVIRTUAL, bigct.getName().replace('.', '/'), pm.getName(), Type.getMethodDescriptor(pm), false); mv.visitMethodInsn(INVOKEVIRTUAL, bigct.getName().replace('.', '/'), pm.getName(), Type.getMethodDescriptor(pm), false);
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); //不可能会发生 throw new RedkaleException(ex); //不可能会发生
} }
} else { } else {
mv.visitTypeInsn(CHECKCAST, ct.getName().replace('.', '/')); mv.visitTypeInsn(CHECKCAST, ct.getName().replace('.', '/'));
@@ -550,7 +550,7 @@ public interface Creator<T> {
} }
} }
if (!ispub && resultClazz == null) { if (!ispub && resultClazz == null) {
throw new RuntimeException("[" + clazz + "] have no public or ConstructorParameters-Annotation constructor."); throw new RedkaleException("[" + clazz + "] have no public or ConstructorParameters-Annotation constructor.");
} }
try { try {
if (resultClazz == null) { if (resultClazz == null) {
@@ -564,7 +564,7 @@ public interface Creator<T> {
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.')); RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
return (Creator) resultClazz.getDeclaredConstructor().newInstance(); return (Creator) resultClazz.getDeclaredConstructor().newInstance();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -804,7 +804,7 @@ public interface Creator<T> {
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz); RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.')); RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance(); return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance();
} catch (Exception ex) { } catch (Throwable ex) {
//ex.printStackTrace(); //一般不会发生, native-image在没有预编译情况下会报错 //ex.printStackTrace(); //一般不会发生, native-image在没有预编译情况下会报错
return t -> (T[]) Array.newInstance(clazz, t); return t -> (T[]) Array.newInstance(clazz, t);
} }

View File

@@ -59,7 +59,9 @@ public class Environment implements java.io.Serializable {
public boolean getBooleanProperty(String key, boolean defaultValue) { public boolean getBooleanProperty(String key, boolean defaultValue) {
String val = properties.getProperty(key); String val = properties.getProperty(key);
if (val == null || val.isEmpty()) return defaultValue; if (val == null || val.isEmpty()) {
return defaultValue;
}
return "true".equalsIgnoreCase(val) || "1".equalsIgnoreCase(val); return "true".equalsIgnoreCase(val) || "1".equalsIgnoreCase(val);
} }
@@ -69,7 +71,9 @@ public class Environment implements java.io.Serializable {
public short getShortProperty(String key, short defaultValue) { public short getShortProperty(String key, short defaultValue) {
String val = properties.getProperty(key); String val = properties.getProperty(key);
if (val == null || val.isEmpty()) return defaultValue; if (val == null || val.isEmpty()) {
return defaultValue;
}
try { try {
return Short.parseShort(val); return Short.parseShort(val);
} catch (Exception e) { } catch (Exception e) {
@@ -83,7 +87,9 @@ public class Environment implements java.io.Serializable {
public int getIntProperty(String key, int defaultValue) { public int getIntProperty(String key, int defaultValue) {
String val = properties.getProperty(key); String val = properties.getProperty(key);
if (val == null || val.isEmpty()) return defaultValue; if (val == null || val.isEmpty()) {
return defaultValue;
}
try { try {
return Integer.parseInt(val); return Integer.parseInt(val);
} catch (Exception e) { } catch (Exception e) {
@@ -91,13 +97,31 @@ public class Environment implements java.io.Serializable {
} }
} }
public float getFloatProperty(String key) {
return Float.parseFloat(properties.getProperty(key));
}
public float getFloatProperty(String key, float defaultValue) {
String val = properties.getProperty(key);
if (val == null || val.isEmpty()) {
return defaultValue;
}
try {
return Float.parseFloat(val);
} catch (Exception e) {
return defaultValue;
}
}
public long getLongProperty(String key) { public long getLongProperty(String key) {
return Long.parseLong(properties.getProperty(key)); return Long.parseLong(properties.getProperty(key));
} }
public long getLongProperty(String key, long defaultValue) { public long getLongProperty(String key, long defaultValue) {
String val = properties.getProperty(key); String val = properties.getProperty(key);
if (val == null || val.isEmpty()) return defaultValue; if (val == null || val.isEmpty()) {
return defaultValue;
}
try { try {
return Long.parseLong(val); return Long.parseLong(val);
} catch (Exception e) { } catch (Exception e) {
@@ -105,6 +129,22 @@ public class Environment implements java.io.Serializable {
} }
} }
public double getDoubleProperty(String key) {
return Double.parseDouble(properties.getProperty(key));
}
public double getDoubleProperty(String key, double defaultValue) {
String val = properties.getProperty(key);
if (val == null || val.isEmpty()) {
return defaultValue;
}
try {
return Double.parseDouble(val);
} catch (Exception e) {
return defaultValue;
}
}
@Override @Override
public String toString() { public String toString() {
return properties.toString(); return properties.toString();

View File

@@ -108,7 +108,7 @@ public abstract class Flows {
reactorMonoClass0 = Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Mono"); reactorMonoClass0 = Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Mono");
Class<Function<Object, CompletableFuture>> monoFuncClass = null; Class<Function<Object, CompletableFuture>> monoFuncClass = null;
try { try {
monoFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.re" + "dkale.util.AnonymousMonoFutureFunction"); monoFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousMonoFutureFunction");
} catch (Throwable t) { } catch (Throwable t) {
} }
if (monoFuncClass == null) { if (monoFuncClass == null) {
@@ -117,7 +117,7 @@ public abstract class Flows {
public final Class<?> loadClass(String name, byte[] b) { public final Class<?> loadClass(String name, byte[] b) {
return defineClass(name, b, 0, b.length); return defineClass(name, b, 0, b.length);
} }
}.loadClass("org.re" + "dkale.util.AnonymousMonoFutureFunction", classBytes); }.loadClass("org.redkale.util.AnonymousMonoFutureFunction", classBytes);
RedkaleClassLoader.putDynClass(monoFuncClass.getName(), classBytes, monoFuncClass); RedkaleClassLoader.putDynClass(monoFuncClass.getName(), classBytes, monoFuncClass);
} }
RedkaleClassLoader.putReflectionDeclaredConstructors(monoFuncClass, monoFuncClass.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(monoFuncClass, monoFuncClass.getName());
@@ -126,7 +126,7 @@ public abstract class Flows {
reactorFluxClass0 = Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Flux"); reactorFluxClass0 = Thread.currentThread().getContextClassLoader().loadClass("reactor.core.publisher.Flux");
Class<Function<Object, CompletableFuture>> fluxFuncClass = null; Class<Function<Object, CompletableFuture>> fluxFuncClass = null;
try { try {
fluxFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.re" + "dkale.util.AnonymousFluxFutureFunction"); fluxFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousFluxFutureFunction");
} catch (Throwable t) { } catch (Throwable t) {
} }
if (fluxFuncClass == null) { if (fluxFuncClass == null) {
@@ -135,7 +135,7 @@ public abstract class Flows {
public final Class<?> loadClass(String name, byte[] b) { public final Class<?> loadClass(String name, byte[] b) {
return defineClass(name, b, 0, b.length); return defineClass(name, b, 0, b.length);
} }
}.loadClass("org.re" + "dkale.util.AnonymousFluxFutureFunction", classBytes); }.loadClass("org.redkale.util.AnonymousFluxFutureFunction", classBytes);
RedkaleClassLoader.putDynClass(fluxFuncClass.getName(), classBytes, fluxFuncClass); RedkaleClassLoader.putDynClass(fluxFuncClass.getName(), classBytes, fluxFuncClass);
} }
RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName());

View File

@@ -39,7 +39,7 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
try { try {
method = clazz.getMethod(methodName, paramTypes); method = clazz.getMethod(methodName, paramTypes);
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
return create(clazz, method); return create(clazz, method);
} }
@@ -221,7 +221,7 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.')); RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
return (Invoker<C, T>) resultClazz.getDeclaredConstructor().newInstance(); return (Invoker<C, T>) resultClazz.getDeclaredConstructor().newInstance();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }

View File

@@ -96,7 +96,7 @@ public class RedkaleClassLoader extends URLClassLoader {
try { try {
return new FileInputStream(f); return new FileInputStream(f);
} catch (FileNotFoundException e) { //几乎不会发生 } catch (FileNotFoundException e) { //几乎不会发生
throw new RuntimeException(e); throw new RedkaleException(e);
} }
} }
} }

View File

@@ -0,0 +1,31 @@
/*
*
*/
package org.redkale.util;
/**
* redkale的异常基础类 <br>
* <p>
* 详情见: https://redkale.org
*
* @author zhangjx
* @since 2.8.0
*/
public class RedkaleException extends RuntimeException {
public RedkaleException() {
super();
}
public RedkaleException(String s) {
super(s);
}
public RedkaleException(String message, Throwable cause) {
super(message, cause);
}
public RedkaleException(Throwable cause) {
super(cause);
}
}

View File

@@ -3,9 +3,9 @@ package org.redkale.util;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Map; import java.util.Map;
import java.util.function.*; import java.util.function.*;
import static org.redkale.asm.Opcodes.*;
import org.redkale.asm.*;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES; import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import org.redkale.asm.*;
import static org.redkale.asm.Opcodes.*;
/** /**
* JavaBean类对象的拷贝相同的字段名会被拷贝 <br> * JavaBean类对象的拷贝相同的字段名会被拷贝 <br>
@@ -186,7 +186,7 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
try { try {
return (Reproduce) newClazz.getDeclaredConstructor().newInstance(); return (Reproduce) newClazz.getDeclaredConstructor().newInstance();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }

View File

@@ -542,7 +542,7 @@ public final class ResourceFactory {
checkResourceName(name); checkResourceName(name);
Class clz = TypeToken.typeToClass(clazz); Class clz = TypeToken.typeToClass(clazz);
if (clz != null && !clz.isPrimitive() && val != null && !clz.isAssignableFrom(val.getClass())) { if (clz != null && !clz.isPrimitive() && val != null && !clz.isAssignableFrom(val.getClass())) {
throw new RuntimeException(clz + "not isAssignableFrom (" + val + ") class " + val.getClass()); throw new RedkaleException(clz + "not isAssignableFrom (" + val + ") class " + val.getClass());
} }
ConcurrentHashMap<String, ResourceEntry> map = this.store.computeIfAbsent(clazz, k -> new ConcurrentHashMap()); ConcurrentHashMap<String, ResourceEntry> map = this.store.computeIfAbsent(clazz, k -> new ConcurrentHashMap());
ResourceEntry re = map.get(name); ResourceEntry re = map.get(name);
@@ -1023,7 +1023,7 @@ public final class ResourceFactory {
return it == null ? findRegxTypeLoader(ft, field) : it; return it == null ? findRegxTypeLoader(ft, field) : it;
} }
private static class ResourceInjectException extends RuntimeException { private static class ResourceInjectException extends RedkaleException {
public ResourceInjectException() { public ResourceInjectException() {
super(); super();
@@ -1273,7 +1273,7 @@ public final class ResourceFactory {
// } catch (RuntimeException ex) { // } catch (RuntimeException ex) {
// throw ex; // throw ex;
// } catch (Exception e) { // } catch (Exception e) {
// throw new RuntimeException(e); // throw new RedkaleException(e);
// } // }
// } // }
// } // }

View File

@@ -9,9 +9,9 @@ package org.redkale.util;
* *
* @author zhangjx * @author zhangjx
*/ */
public class RetcodeException extends RuntimeException { public class RetcodeException extends RedkaleException {
private int retcode; protected int retcode;
public RetcodeException(int retcode) { public RetcodeException(int retcode) {
this.retcode = retcode; this.retcode = retcode;

View File

@@ -649,7 +649,7 @@ public abstract class TypeToken<T> {
try { try {
return newClazz.getField("field").getGenericType(); return newClazz.getField("field").getGenericType();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }

View File

@@ -189,7 +189,7 @@ public final class Utility {
// } // }
// }}, null); // }}, null);
// } catch (Exception e) { // } catch (Exception e) {
// throw new RuntimeException(e); //不会发生 // throw new RedkaleException(e); //不会发生
// } // }
} }
@@ -2850,7 +2850,7 @@ public final class Utility {
try { try {
md5 = MessageDigest.getInstance("MD5"); md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a MD5 provider", ex); throw new RedkaleException("Couldn't find a MD5 provider", ex);
} }
return md5.digest(str.getBytes(StandardCharsets.UTF_8)); return md5.digest(str.getBytes(StandardCharsets.UTF_8));
} }
@@ -2870,7 +2870,7 @@ public final class Utility {
try { try {
md5 = MessageDigest.getInstance("MD5"); md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a MD5 provider", ex); throw new RedkaleException("Couldn't find a MD5 provider", ex);
} }
return md5.digest(input); return md5.digest(input);
} }
@@ -2894,7 +2894,7 @@ public final class Utility {
md5.update(input, offset, len); md5.update(input, offset, len);
return md5.digest(); return md5.digest();
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a MD5 provider", ex); throw new RedkaleException("Couldn't find a MD5 provider", ex);
} }
} }
@@ -2972,7 +2972,7 @@ public final class Utility {
try { try {
digester = MessageDigest.getInstance("SHA-256"); digester = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a SHA-256 provider", ex); throw new RedkaleException("Couldn't find a SHA-256 provider", ex);
} }
return digester.digest(str.getBytes(StandardCharsets.UTF_8)); return digester.digest(str.getBytes(StandardCharsets.UTF_8));
} }
@@ -2992,7 +2992,7 @@ public final class Utility {
try { try {
digester = MessageDigest.getInstance("SHA-256"); digester = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
return digester.digest(input); return digester.digest(input);
} }
@@ -3016,7 +3016,7 @@ public final class Utility {
digester.update(input, offset, len); digester.update(input, offset, len);
return digester.digest(); return digester.digest();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3127,7 +3127,7 @@ public final class Utility {
mac.init(new SecretKeySpec(key, "HmacSHA1")); mac.init(new SecretKeySpec(key, "HmacSHA1"));
return mac.doFinal(input); return mac.doFinal(input);
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3151,7 +3151,7 @@ public final class Utility {
mac.update(input, offset, len); mac.update(input, offset, len);
return mac.doFinal(); return mac.doFinal();
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3262,7 +3262,7 @@ public final class Utility {
mac.init(new SecretKeySpec(key, "HmacSHA256")); mac.init(new SecretKeySpec(key, "HmacSHA256"));
return mac.doFinal(input); return mac.doFinal(input);
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3286,7 +3286,7 @@ public final class Utility {
mac.update(input, offset, len); mac.update(input, offset, len);
return mac.doFinal(); return mac.doFinal();
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3398,7 +3398,7 @@ public final class Utility {
mac.init(sk); mac.init(sk);
return mac.doFinal(input); return mac.doFinal(input);
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3423,7 +3423,7 @@ public final class Utility {
mac.update(input, offset, len); mac.update(input, offset, len);
return mac.doFinal(); return mac.doFinal();
} catch (InvalidKeyException | NoSuchAlgorithmException ex) { } catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new RuntimeException(ex); throw new RedkaleException(ex);
} }
} }
@@ -3440,7 +3440,7 @@ public final class Utility {
MessageDigest digest = MessageDigest.getInstance(algorithm.toUpperCase()); MessageDigest digest = MessageDigest.getInstance(algorithm.toUpperCase());
return digest.digest(input); return digest.digest(input);
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a " + algorithm + " provider", ex); throw new RedkaleException("Couldn't find a " + algorithm + " provider", ex);
} }
} }
@@ -3460,7 +3460,7 @@ public final class Utility {
digest.update(input, offset, length); digest.update(input, offset, length);
return digest.digest(); return digest.digest();
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Couldn't find a " + algorithm + " provider", ex); throw new RedkaleException("Couldn't find a " + algorithm + " provider", ex);
} }
} }