注释优化

This commit is contained in:
redkale
2023-11-12 19:59:01 +08:00
parent cb2abab70c
commit 5e25bc623c
52 changed files with 297 additions and 103 deletions

View File

@@ -360,6 +360,7 @@ public class Type {
break; break;
} else if (car == 'L') { } else if (car == 'L') {
while (buf[off++] != ';') { while (buf[off++] != ';') {
//do nothing
} }
++size; ++size;
} else if (car != '[') { } else if (car != '[') {
@@ -413,6 +414,7 @@ public class Type {
return getType(buf, off); return getType(buf, off);
} else if (car == 'L') { } else if (car == 'L') {
while (buf[off++] != ';') { while (buf[off++] != ';') {
//do nothing
} }
} }
} }
@@ -453,6 +455,7 @@ public class Type {
| (car == 'V' ? 0 : (car == 'D' || car == 'J' ? 2 : 1)); | (car == 'V' ? 0 : (car == 'D' || car == 'J' ? 2 : 1));
} else if (car == 'L') { } else if (car == 'L') {
while (desc.charAt(c++) != ';') { while (desc.charAt(c++) != ';') {
//do nothing
} }
n += 1; n += 1;
} else if (car == '[') { } else if (car == '[') {

View File

@@ -687,6 +687,7 @@ public final class ApiDocCommand {
Type valType = pt.getActualTypeArguments()[0]; Type valType = pt.getActualTypeArguments()[0];
return formatExample(factory, example, valType instanceof ParameterizedType ? (Class) ((ParameterizedType) valType).getRawType() : ((Class) valType), valType); return formatExample(factory, example, valType instanceof ParameterizedType ? (Class) ((ParameterizedType) valType).getRawType() : ((Class) valType), valType);
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} else if (Sheet.class.isAssignableFrom(type)) { //要在Collection前面 } else if (Sheet.class.isAssignableFrom(type)) { //要在Collection前面
@@ -698,6 +699,7 @@ public final class ApiDocCommand {
Object val = formatExample(factory, example, valClass, valType); Object val = formatExample(factory, example, valClass, valType);
return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "{'rows':[" + val + "," + val + "]}"))); return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "{'rows':[" + val + "," + val + "]}")));
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} else if (type.isArray()) { } else if (type.isArray()) {
@@ -705,6 +707,7 @@ public final class ApiDocCommand {
Object val = formatExample(factory, example, type.getComponentType(), type.getComponentType()); Object val = formatExample(factory, example, type.getComponentType(), type.getComponentType());
return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "[" + val + "," + val + "]"))); return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "[" + val + "," + val + "]")));
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} else if (Collection.class.isAssignableFrom(type)) { } else if (Collection.class.isAssignableFrom(type)) {
if (genericType instanceof ParameterizedType) { if (genericType instanceof ParameterizedType) {
@@ -715,6 +718,7 @@ public final class ApiDocCommand {
Object val = formatExample(factory, example, valClass, valType); Object val = formatExample(factory, example, valClass, valType);
return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "[" + val + "," + val + "]"))); return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "[" + val + "," + val + "]")));
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} else if (type == RetResult.class) { } else if (type == RetResult.class) {
@@ -726,6 +730,7 @@ public final class ApiDocCommand {
Object val = formatExample(factory, example, valClass, valType); Object val = formatExample(factory, example, valClass, valType);
return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "{'result':" + val + "}"))); return new StringWrapper(jsonFactory.getConvert().convertTo(jsonFactory.getConvert().convertFrom(genericType, "{'result':" + val + "}")));
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} else if (type != void.class) { } else if (type != void.class) {
@@ -752,6 +757,7 @@ public final class ApiDocCommand {
Creator creator = Creator.create(type); Creator creator = Creator.create(type);
return new StringWrapper(jsonFactory.getConvert().convertTo(creator.create())); return new StringWrapper(jsonFactory.getConvert().convertTo(creator.create()));
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
return example; return example;

View File

@@ -375,6 +375,7 @@ public final class Application {
in.close(); in.close();
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
if (cacheClasses == null) { if (cacheClasses == null) {

View File

@@ -131,6 +131,7 @@ public abstract class LoggingBaseHandler extends Handler {
ps.println(handlerName + ".formatter = " + LoggingFormater.class.getName()); ps.println(handlerName + ".formatter = " + LoggingFormater.class.getName());
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(out.toByteArray())); LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(out.toByteArray()));
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }

View File

@@ -57,6 +57,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
this.denyRegx = Pattern.compile(denyregxstr); this.denyRegx = Pattern.compile(denyregxstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
@@ -267,6 +268,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
this.limit = ls; this.limit = ls;
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String countstr = manager.getProperty(cname + ".count"); String countstr = manager.getProperty(cname + ".count");
try { try {
@@ -274,6 +276,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
this.count = Math.max(1, Math.abs(Integer.decode(countstr))); this.count = Math.max(1, Math.abs(Integer.decode(countstr)));
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String appendstr = manager.getProperty(cname + ".append"); String appendstr = manager.getProperty(cname + ".append");
try { try {
@@ -281,6 +284,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
this.append = "true".equalsIgnoreCase(appendstr) || "1".equals(appendstr); this.append = "true".equalsIgnoreCase(appendstr) || "1".equals(appendstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String levelstr = manager.getProperty(cname + ".level"); String levelstr = manager.getProperty(cname + ".level");
try { try {
@@ -289,6 +293,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
setLevel(l != null ? l : Level.ALL); setLevel(l != null ? l : Level.ALL);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String filterstr = manager.getProperty(cname + ".filter"); String filterstr = manager.getProperty(cname + ".filter");
try { try {
@@ -298,6 +303,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
setFilter((Filter) clz.getDeclaredConstructor().newInstance()); setFilter((Filter) clz.getDeclaredConstructor().newInstance());
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String formatterstr = manager.getProperty(cname + ".formatter"); String formatterstr = manager.getProperty(cname + ".formatter");
try { try {
@@ -307,6 +313,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
setFormatter((Formatter) clz.getDeclaredConstructor().newInstance()); setFormatter((Formatter) clz.getDeclaredConstructor().newInstance());
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
if (getFormatter() == null) { if (getFormatter() == null) {
setFormatter(new SimpleFormatter()); setFormatter(new SimpleFormatter());
@@ -318,6 +325,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
setEncoding(encodingstr); setEncoding(encodingstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String denyregxstr = manager.getProperty(cname + ".denyregx"); String denyregxstr = manager.getProperty(cname + ".denyregx");
@@ -326,6 +334,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
denyregx = Pattern.compile(denyregxstr); denyregx = Pattern.compile(denyregxstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }

View File

@@ -174,6 +174,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
setLevel(l != null ? l : Level.ALL); setLevel(l != null ? l : Level.ALL);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String filterstr = manager.getProperty(cname + ".filter"); String filterstr = manager.getProperty(cname + ".filter");
try { try {
@@ -183,6 +184,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
setFilter((Filter) clz.getDeclaredConstructor().newInstance()); setFilter((Filter) clz.getDeclaredConstructor().newInstance());
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String formatterstr = manager.getProperty(cname + ".formatter"); String formatterstr = manager.getProperty(cname + ".formatter");
try { try {
@@ -192,6 +194,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
setFormatter((Formatter) clz.getDeclaredConstructor().newInstance()); setFormatter((Formatter) clz.getDeclaredConstructor().newInstance());
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
if (getFormatter() == null) { if (getFormatter() == null) {
setFormatter(new SimpleFormatter()); setFormatter(new SimpleFormatter());
@@ -203,6 +206,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
setEncoding(encodingstr); setEncoding(encodingstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String denyregxstr = manager.getProperty(cname + ".denyregx"); String denyregxstr = manager.getProperty(cname + ".denyregx");
@@ -211,6 +215,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
denyRegx = Pattern.compile(denyregxstr); denyRegx = Pattern.compile(denyregxstr);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }

View File

@@ -131,6 +131,7 @@ public class PrepareCompiler {
try { try {
FilterNodeBean.load(clz); FilterNodeBean.load(clz);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
for (ApplicationListener listener : application.listeners) { for (ApplicationListener listener : application.listeners) {

View File

@@ -213,6 +213,7 @@ public abstract class ClusterAgent {
try { try {
Thread.sleep(s * 1000); Thread.sleep(s * 1000);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
//do nothing
} }
logger.info(this.getClass().getSimpleName() + " wait for " + s * 1000 + "ms after deregister"); logger.info(this.getClass().getSimpleName() + " wait for " + s * 1000 + "ms after deregister");
} }

View File

@@ -200,6 +200,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
}); });
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} }
@@ -707,6 +708,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
encoder = (Encodeable) instanceField.get(null); encoder = (Encodeable) instanceField.get(null);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
if (encoder == null) { if (encoder == null) {
Creator<? extends Encodeable> creator = Creator.create(enClazz); Creator<? extends Encodeable> creator = Creator.create(enClazz);
@@ -774,6 +776,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
decoder = (Decodeable) instanceField.get(null); decoder = (Decodeable) instanceField.get(null);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
if (decoder == null) { if (decoder == null) {
Creator<? extends Decodeable> creator = Creator.create(deClazz); Creator<? extends Decodeable> creator = Creator.create(deClazz);
@@ -947,6 +950,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
try { try {
field = type.getDeclaredField(column); field = type.getDeclaredField(column);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
String get = "get"; String get = "get";
if (field != null && (field.getType() == boolean.class || field.getType() == Boolean.class)) { if (field != null && (field.getType() == boolean.class || field.getType() == Boolean.class)) {
@@ -962,13 +966,16 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
try { try {
register(type.getMethod("is" + bigColumn), entry); register(type.getMethod("is" + bigColumn), entry);
} catch (Exception ex) { } catch (Exception ex) {
//do nothing
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
//do nothing
} }
try { try {
register(type.getMethod("set" + bigColumn, field.getType()), entry); register(type.getMethod("set" + bigColumn, field.getType()), entry);
} catch (Exception ex) { } catch (Exception ex) {
//do nothing
} }
return field == null ? true : register(field, entry); return field == null ? true : register(field, entry);
} }

View File

@@ -5,7 +5,6 @@
*/ */
package org.redkale.convert; package org.redkale.convert;
import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
@@ -17,7 +16,7 @@ import org.redkale.convert.json.JsonConvert;
* *
* @author zhangjx * @author zhangjx
*/ */
public class ConvertField implements Serializable { public class ConvertField {
protected String name; protected String name;

View File

@@ -105,6 +105,7 @@ public class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -83,6 +83,7 @@ public class MapEncoder<K, V> implements Encodeable<Writer, Map<K, V>> {
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -407,6 +407,7 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
try { try {
ref = factory.findRef(clazz, clazz.getDeclaredField(mfieldname)); ref = factory.findRef(clazz, clazz.getDeclaredField(mfieldname));
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name(); fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name();
@@ -417,6 +418,7 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
try { try {
ref = factory.findRef(clazz, clazz.getDeclaredField(mfieldname)); ref = factory.findRef(clazz, clazz.getDeclaredField(mfieldname));
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name(); fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name();

View File

@@ -85,6 +85,7 @@ public class OptionalCoder<R extends Reader, W extends Writer, T> extends Simple
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@@ -101,6 +102,7 @@ public class OptionalCoder<R extends Reader, W extends Writer, T> extends Simple
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -66,7 +66,9 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
byte[] typevals = new byte[1]; byte[] typevals = new byte[1];
int len = in.readArrayB(member, typevals, this.componentDecoder); int len = in.readArrayB(member, typevals, this.componentDecoder);
int contentLength = -1; int contentLength = -1;
if (len == Reader.SIGN_NULL) return null; if (len == Reader.SIGN_NULL) {
return null;
}
if (len == Reader.SIGN_NOLENBUTBYTES) { if (len == Reader.SIGN_NOLENBUTBYTES) {
contentLength = in.readMemberContentLength(member, this.componentDecoder); contentLength = in.readMemberContentLength(member, this.componentDecoder);
len = Reader.SIGN_NOLENGTH; len = Reader.SIGN_NOLENGTH;
@@ -77,6 +79,7 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@@ -89,7 +92,9 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
int startPosition = in.position(); int startPosition = in.position();
while (hasNext(in, member, startPosition, contentLength, first)) { while (hasNext(in, member, startPosition, contentLength, first)) {
Reader itemReader = getItemReader(in, member, first); Reader itemReader = getItemReader(in, member, first);
if (itemReader == null) break; if (itemReader == null) {
break;
}
result.add(readMemberValue(itemReader, member, localdecoder, first)); result.add(readMemberValue(itemReader, member, localdecoder, first));
first = false; first = false;
} }

View File

@@ -78,6 +78,7 @@ public class StreamEncoder<T> implements Encodeable<Writer, Stream<T>> {
try { try {
condition.await(); condition.await();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -21,7 +21,7 @@ import org.redkale.util.*;
*/ */
public class BsonWriter extends Writer implements ByteTuple { public class BsonWriter extends Writer implements ByteTuple {
private static final int defaultSize = Integer.getInteger("redkale.convert.bson.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024)); private static final int DEFAULT_SIZE = Integer.getInteger("redkale.convert.bson.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024));
private byte[] content; private byte[] content;
@@ -81,7 +81,7 @@ public class BsonWriter extends Writer implements ByteTuple {
} }
public BsonWriter() { public BsonWriter() {
this(defaultSize); this(DEFAULT_SIZE);
this.features = BsonFactory.root().getFeatures(); this.features = BsonFactory.root().getFeatures();
} }
@@ -144,8 +144,8 @@ public class BsonWriter extends Writer implements ByteTuple {
super.recycle(); super.recycle();
this.count = 0; this.count = 0;
this.specificObjectType = null; this.specificObjectType = null;
if (this.content != null && this.content.length > defaultSize) { if (this.content != null && this.content.length > DEFAULT_SIZE) {
this.content = new byte[defaultSize]; this.content = new byte[DEFAULT_SIZE];
} }
return true; return true;
} }

View File

@@ -135,6 +135,7 @@ public class JsonByteBufferReader extends JsonReader {
try { try {
while ((one = nextChar()) != 0) sb.append(one); while ((one = nextChar()) != 0) sb.append(one);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
throw new ConvertException("a json object text must begin with '{' (position = " + pos + ") but '" + ch + "' in (" + sb + ")"); throw new ConvertException("a json object text must begin with '{' (position = " + pos + ") but '" + ch + "' in (" + sb + ")");
} }
@@ -167,6 +168,7 @@ public class JsonByteBufferReader extends JsonReader {
try { try {
while ((one = nextChar()) != 0) sb.append(one); while ((one = nextChar()) != 0) sb.append(one);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
throw new ConvertException("a json array text must begin with '[' (position = " + pos + ") but '" + ch + "' in (" + sb + ")"); throw new ConvertException("a json array text must begin with '[' (position = " + pos + ") but '" + ch + "' in (" + sb + ")");
} }
@@ -187,6 +189,7 @@ public class JsonByteBufferReader extends JsonReader {
try { try {
while ((one = nextChar()) != 0) sb.append(one); while ((one = nextChar()) != 0) sb.append(one);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
throw new ConvertException("expected a ':' but '" + ch + "'(position = " + pos + ") in (" + sb + ")"); throw new ConvertException("expected a ':' but '" + ch + "'(position = " + pos + ") in (" + sb + ")");
} }

View File

@@ -8,8 +8,8 @@ package org.redkale.convert.json;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import org.redkale.asm.*; import org.redkale.asm.*;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
import org.redkale.convert.*; import org.redkale.convert.*;
import org.redkale.convert.ext.*; import org.redkale.convert.ext.*;
@@ -315,6 +315,7 @@ public abstract class JsonDynEncoder<T> implements Encodeable<JsonWriter, T> {
small = f.getAnnotation(ConvertSmallString.class); small = f.getAnnotation(ConvertSmallString.class);
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
return small; return small;
@@ -403,6 +404,7 @@ public abstract class JsonDynEncoder<T> implements Encodeable<JsonWriter, T> {
} }
return resultEncoder; return resultEncoder;
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);

View File

@@ -20,7 +20,7 @@ import org.redkale.util.*;
*/ */
public class ProtobufWriter extends Writer implements ByteTuple { public class ProtobufWriter extends Writer implements ByteTuple {
private static final int defaultSize = Integer.getInteger("redkale.convert.protobuf.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024)); private static final int DEFAULT_SIZE = Integer.getInteger("redkale.convert.protobuf.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024));
private byte[] content; private byte[] content;
@@ -68,7 +68,7 @@ public class ProtobufWriter extends Writer implements ByteTuple {
} }
public ProtobufWriter() { public ProtobufWriter() {
this(defaultSize); this(DEFAULT_SIZE);
} }
public ProtobufWriter(int size) { public ProtobufWriter(int size) {
@@ -85,8 +85,8 @@ public class ProtobufWriter extends Writer implements ByteTuple {
super.recycle(); super.recycle();
this.count = 0; this.count = 0;
this.initOffset = 0; this.initOffset = 0;
if (this.content.length > defaultSize) { if (this.content.length > DEFAULT_SIZE) {
this.content = new byte[defaultSize]; this.content = new byte[DEFAULT_SIZE];
} }
return true; return true;
} }
@@ -195,6 +195,7 @@ public class ProtobufWriter extends Writer implements ByteTuple {
@Override @Override
public void writeNull() { public void writeNull() {
//do nothing
} }
@Override @Override
@@ -204,6 +205,7 @@ public class ProtobufWriter extends Writer implements ByteTuple {
@Override @Override
public void writeClassName(String clazz) { public void writeClassName(String clazz) {
//do nothing
} }
@Override @Override
@@ -380,10 +382,12 @@ public class ProtobufWriter extends Writer implements ByteTuple {
@Override @Override
public void writeArrayMark() { public void writeArrayMark() {
//do nothing
} }
@Override @Override
public void writeArrayE() { public void writeArrayE() {
//do nothing
} }
@Override @Override
@@ -393,10 +397,12 @@ public class ProtobufWriter extends Writer implements ByteTuple {
@Override @Override
public void writeMapMark() { public void writeMapMark() {
//do nothing
} }
@Override @Override
public void writeMapE() { public void writeMapE() {
//do nothing
} }
@Override @Override

View File

@@ -227,7 +227,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
// public abstract <A> AsyncConnection fastHandler(CompletionHandler<Integer, ? super A> handler); // public abstract <A> AsyncConnection fastHandler(CompletionHandler<Integer, ? super A> handler);
// //
// public abstract <A> void fastWrite(byte[] data); // public abstract <A> void fastWrite(byte[] data);
protected abstract void readRegisterImpl(CompletionHandler<Integer, ByteBuffer> handler); protected abstract void readRegisterImpl(CompletionHandler<Integer, ByteBuffer> handler);
protected abstract void readImpl(CompletionHandler<Integer, ByteBuffer> handler); protected abstract void readImpl(CompletionHandler<Integer, ByteBuffer> handler);
@@ -804,6 +803,7 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
try { try {
this.close(); this.close();
} catch (IOException io) { } catch (IOException io) {
//do nothing
} }
} }
@@ -827,6 +827,7 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
sslEngine.closeInbound(); sslEngine.closeInbound();
sslEngine.closeOutbound(); sslEngine.closeOutbound();
} catch (SSLException e) { } catch (SSLException e) {
//do nothing
} }
sslEngine = null; sslEngine = null;
} }
@@ -834,6 +835,7 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
try { try {
beforeCloseListener.accept(this); beforeCloseListener.accept(this);
} catch (Exception io) { } catch (Exception io) {
//do nothing
} }
} }
if (this.readBuffer != null && Thread.currentThread() == this.ioReadThread) { if (this.readBuffer != null && Thread.currentThread() == this.ioReadThread) {
@@ -853,6 +855,7 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
} }
attributes.clear(); attributes.clear();
} catch (Exception io) { } catch (Exception io) {
//do nothing
} }
} }

View File

@@ -165,7 +165,7 @@ public abstract class Request<C extends Context> {
@Deprecated(since = "2.7.0") //replace by getCreateTime() @Deprecated(since = "2.7.0") //replace by getCreateTime()
@ConvertDisabled @ConvertDisabled
public long getCreatetime() { public long getCreatetime() {
return createTime; return getCreateTime();
} }
public long getCreateTime() { public long getCreateTime() {

View File

@@ -458,6 +458,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
try { try {
this.serverChannel.close(); this.serverChannel.close();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
logger.info(this.getClass().getSimpleName() + "-" + this.netprotocol + " shutdow prepare servlet"); logger.info(this.getClass().getSimpleName() + "-" + this.netprotocol + " shutdow prepare servlet");
this.dispatcher.destroy(this.context, config); this.dispatcher.destroy(this.context, config);

View File

@@ -169,6 +169,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
conn.writeChannel(req).thenAccept(p -> handlePingResult((C) conn, p)); conn.writeChannel(req).thenAccept(p -> handlePingResult((C) conn, p));
} }
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
}, pingIntervalSeconds(), pingIntervalSeconds(), TimeUnit.SECONDS); }, pingIntervalSeconds(), pingIntervalSeconds(), TimeUnit.SECONDS);
} }
@@ -213,6 +214,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
try { try {
conn.writeChannel(closeReq).get(1, TimeUnit.SECONDS); conn.writeChannel(closeReq).get(1, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
conn.dispose(null); conn.dispose(null);
} }

View File

@@ -14,7 +14,6 @@ import org.redkale.annotation.ConstructorParameters;
import org.redkale.asm.*; import org.redkale.asm.*;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
import org.redkale.net.*; import org.redkale.net.*;
import org.redkale.net.Context;
import org.redkale.net.Context.ContextConfig; import org.redkale.net.Context.ContextConfig;
import org.redkale.util.*; import org.redkale.util.*;
@@ -117,6 +116,7 @@ public class HttpContext extends Context {
Class newHandlerClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz; Class newHandlerClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz;
return Creator.create(newHandlerClazz); return Creator.create(newHandlerClazz);
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

View File

@@ -6,11 +6,10 @@
package org.redkale.net.http; package org.redkale.net.http;
import java.io.*; import java.io.*;
import static java.nio.file.StandardWatchEventKinds.*;
import java.nio.file.*; import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*; import static java.nio.file.StandardWatchEventKinds.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.*; import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
import java.util.logging.*; import java.util.logging.*;
@@ -84,6 +83,7 @@ public class HttpResourceServlet extends HttpServlet {
key.reset(); key.reset();
} }
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
} }

View File

@@ -59,9 +59,9 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
protected static final byte[] connectAliveBytes = "none".equalsIgnoreCase(System.getProperty("redkale.http.response.header.connection")) ? new byte[0] : "Connection: keep-alive\r\n".getBytes(); protected static final byte[] connectAliveBytes = "none".equalsIgnoreCase(System.getProperty("redkale.http.response.header.connection")) ? new byte[0] : "Connection: keep-alive\r\n".getBytes();
protected static final String contentTypeHtmlUTF8 = "text/html; charset=utf-8"; protected static final String CONTENT_TYPE_HTML_UTF8 = "text/html; charset=utf-8";
private static final int cacheMaxContentLength = 1000; private static final int CACHE_MAX_CONTENT_LENGTH = 1000;
private static final byte[] status200_server_live_Bytes = append(append(status200Bytes, serverNameBytes), connectAliveBytes); private static final byte[] status200_server_live_Bytes = append(append(status200Bytes, serverNameBytes), connectAliveBytes);
@@ -71,7 +71,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
private static final Map<Integer, String> httpCodes = new HashMap<>(); private static final Map<Integer, String> httpCodes = new HashMap<>();
private static final byte[][] contentLengthArray = new byte[cacheMaxContentLength][]; private static final byte[][] contentLengthArray = new byte[CACHE_MAX_CONTENT_LENGTH][];
private static final JsonConvert jsonRootConvert = JsonConvert.root(); private static final JsonConvert jsonRootConvert = JsonConvert.root();
@@ -122,7 +122,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
httpCodes.put(504, "Gateway Timeout"); httpCodes.put(504, "Gateway Timeout");
httpCodes.put(505, "HTTP Version Not Supported"); httpCodes.put(505, "HTTP Version Not Supported");
for (int i = 0; i < cacheMaxContentLength; i++) { for (int i = 0; i < CACHE_MAX_CONTENT_LENGTH; i++) {
contentLengthArray[i] = ("Content-Length: " + i + "\r\n").getBytes(); contentLengthArray[i] = ("Content-Length: " + i + "\r\n").getBytes();
} }
} }
@@ -729,7 +729,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
return; return;
} }
if (httpRender != null) { if (httpRender != null) {
setContentType(contentTypeHtmlUTF8); setContentType(CONTENT_TYPE_HTML_UTF8);
if (result.getHeaders() != null) { if (result.getHeaders() != null) {
addHeader(result.getHeaders()); addHeader(result.getHeaders());
} }
@@ -1301,6 +1301,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
try { try {
fileChannel.close(); fileChannel.close();
} catch (IOException ie) { } catch (IOException ie) {
//do nothing
} }
completeFinishBytes(result, attachment); completeFinishBytes(result, attachment);
return; return;
@@ -1333,6 +1334,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
try { try {
fileChannel.close(); fileChannel.close();
} catch (IOException ie) { } catch (IOException ie) {
//do nothing
} }
} }
failed(e, attachment); failed(e, attachment);
@@ -1638,13 +1640,13 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
public AnyValue renderConfig; public AnyValue renderConfig;
public final byte[][] plainLiveContentLengthArray = new byte[cacheMaxContentLength][]; public final byte[][] plainLiveContentLengthArray = new byte[CACHE_MAX_CONTENT_LENGTH][];
public final byte[][] jsonLiveContentLengthArray = new byte[cacheMaxContentLength][]; public final byte[][] jsonLiveContentLengthArray = new byte[CACHE_MAX_CONTENT_LENGTH][];
public final byte[][] plainCloseContentLengthArray = new byte[cacheMaxContentLength][]; public final byte[][] plainCloseContentLengthArray = new byte[CACHE_MAX_CONTENT_LENGTH][];
public final byte[][] jsonCloseContentLengthArray = new byte[cacheMaxContentLength][]; public final byte[][] jsonCloseContentLengthArray = new byte[CACHE_MAX_CONTENT_LENGTH][];
public HttpResponseConfig init(AnyValue config) { public HttpResponseConfig init(AnyValue config) {
if (this.plainContentTypeBytes == null) { if (this.plainContentTypeBytes == null) {
@@ -1654,7 +1656,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
this.jsonContentType = jsonct; this.jsonContentType = jsonct;
this.plainContentTypeBytes = ("Content-Type: " + plainct + "\r\n").getBytes(); this.plainContentTypeBytes = ("Content-Type: " + plainct + "\r\n").getBytes();
this.jsonContentTypeBytes = ("Content-Type: " + jsonct + "\r\n").getBytes(); this.jsonContentTypeBytes = ("Content-Type: " + jsonct + "\r\n").getBytes();
for (int i = 0; i < cacheMaxContentLength; i++) { for (int i = 0; i < CACHE_MAX_CONTENT_LENGTH; i++) {
byte[] lenbytes = ("Content-Length: " + i + "\r\n").getBytes(); byte[] lenbytes = ("Content-Length: " + i + "\r\n").getBytes();
plainLiveContentLengthArray[i] = append(append(status200_server_live_Bytes, plainContentTypeBytes), lenbytes); plainLiveContentLengthArray[i] = append(append(status200_server_live_Bytes, plainContentTypeBytes), lenbytes);
plainCloseContentLengthArray[i] = append(append(status200_server_close_Bytes, plainContentTypeBytes), lenbytes); plainCloseContentLengthArray[i] = append(append(status200_server_close_Bytes, plainContentTypeBytes), lenbytes);

View File

@@ -512,6 +512,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
instance.getClass().getField("_factServlet").set(instance, this); instance.getClass().getField("_factServlet").set(instance, this);
return instance; return instance;
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);

View File

@@ -111,7 +111,7 @@ public final class MultiPart {
*/ */
@Deprecated(since = "2.8.0") @Deprecated(since = "2.8.0")
public String getFilename() { public String getFilename() {
return fileName; return getFileName();
} }
public String getName() { public String getName() {

View File

@@ -427,6 +427,7 @@ public final class Rest {
} }
namePresent = m0 == null ? true : m0.getParameters()[0].isNamePresent(); namePresent = m0 == null ? true : m0.getParameters()[0].isNamePresent();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
final Map<String, List<String>> asmParamMap = namePresent ? null : MethodParamClassVisitor.getMethodParamNames(new HashMap<>(), webSocketType); final Map<String, List<String>> asmParamMap = namePresent ? null : MethodParamClassVisitor.getMethodParamNames(new HashMap<>(), webSocketType);
final Set<String> messageNames = new HashSet<>(); final Set<String> messageNames = new HashSet<>();
@@ -518,6 +519,7 @@ public final class Rest {
} }
return servlet; return servlet;
} catch (Throwable e) { } catch (Throwable e) {
//do nothing
} }
final List<Field> resourcesFields = new ArrayList<>(resourcesFieldSet); final List<Field> resourcesFields = new ArrayList<>(resourcesFieldSet);
@@ -1390,8 +1392,11 @@ public final class Rest {
} else if (pname != null && pname.charAt(0) == '#') { //从request.getRequstURIPath 中去参数 } else if (pname != null && pname.charAt(0) == '#') { //从request.getRequstURIPath 中去参数
} else if ("&".equals(pname) && ptype == userType) { //当前用户对象的类名 } else if ("&".equals(pname) && ptype == userType) { //当前用户对象的类名
} else if (ptype.isPrimitive()) { } else if (ptype.isPrimitive()) {
//do nothing
} else if (ptype == String.class) { } else if (ptype == String.class) {
//do nothing
} else if (ptype == Flipper.class) { } else if (ptype == Flipper.class) {
//do nothing
} else { //其他Json对象 } else { //其他Json对象
//构建 RestHeader、RestCookie、RestAddress 等赋值操作 //构建 RestHeader、RestCookie、RestAddress 等赋值操作
Class loop = ptype; Class loop = ptype;
@@ -1476,20 +1481,31 @@ public final class Rest {
if (en.getKey().contains("_header_")) { if (en.getKey().contains("_header_")) {
String headerkey = en.getValue()[0].toString(); String headerkey = en.getValue()[0].toString();
if ("Host".equalsIgnoreCase(headerkey)) { if ("Host".equalsIgnoreCase(headerkey)) {
//do nothing
} else if ("Content-Type".equalsIgnoreCase(headerkey)) { } else if ("Content-Type".equalsIgnoreCase(headerkey)) {
//do nothing
} else if ("Connection".equalsIgnoreCase(headerkey)) { } else if ("Connection".equalsIgnoreCase(headerkey)) {
//do nothing
} else if ("Method".equalsIgnoreCase(headerkey)) { } else if ("Method".equalsIgnoreCase(headerkey)) {
//do nothing
} else if (en.getKey().contains("_header_json_")) { } else if (en.getKey().contains("_header_json_")) {
String typefieldname = "_redkale_body_jsontype_" + bodyTypes.size(); String typefieldname = "_redkale_body_jsontype_" + bodyTypes.size();
bodyTypes.put(typefieldname, (java.lang.reflect.Type) en.getValue()[2]); bodyTypes.put(typefieldname, (java.lang.reflect.Type) en.getValue()[2]);
} }
} else if (en.getKey().contains("_cookie_")) { } else if (en.getKey().contains("_cookie_")) {
//do nothing
} else if (en.getKey().contains("_sessionid_")) { } else if (en.getKey().contains("_sessionid_")) {
//do nothing
} else if (en.getKey().contains("_address_")) { } else if (en.getKey().contains("_address_")) {
//do nothing
} else if (en.getKey().contains("_locale_")) { } else if (en.getKey().contains("_locale_")) {
//do nothing
} else if (en.getKey().contains("_uri_")) { } else if (en.getKey().contains("_uri_")) {
//do nothing
} else if (en.getKey().contains("_bodystring_")) { } else if (en.getKey().contains("_bodystring_")) {
//do nothing
} else if (en.getKey().contains("_bodybytes_")) { } else if (en.getKey().contains("_bodybytes_")) {
//do nothing
} else if (en.getKey().contains("_bodyjson_")) {//JavaBean 转 Json } else if (en.getKey().contains("_bodyjson_")) {//JavaBean 转 Json
String typefieldname = "_redkale_body_jsontype_" + bodyTypes.size(); String typefieldname = "_redkale_body_jsontype_" + bodyTypes.size();
bodyTypes.put(typefieldname, (java.lang.reflect.Type) en.getValue()[2]); bodyTypes.put(typefieldname, (java.lang.reflect.Type) en.getValue()[2]);
@@ -1870,6 +1886,7 @@ public final class Rest {
} }
namePresent = m0 == null ? true : m0.getParameters()[0].isNamePresent(); namePresent = m0 == null ? true : m0.getParameters()[0].isNamePresent();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
final Map<String, List<String>> asmParamMap = namePresent ? null : MethodParamClassVisitor.getMethodParamNames(new HashMap<>(), serviceType); final Map<String, List<String>> asmParamMap = namePresent ? null : MethodParamClassVisitor.getMethodParamNames(new HashMap<>(), serviceType);

View File

@@ -100,18 +100,18 @@ public class WebSocketEngine {
if (conf != null && conf.getAnyValue("properties") != null) { if (conf != null && conf.getAnyValue("properties") != null) {
props = conf.getAnyValue("properties"); props = conf.getAnyValue("properties");
} }
this.liveInterval = props == null ? (liveInterval < 0 ? DEFAILT_LIVEINTERVAL : liveInterval) : props.getIntValue(WEBPARAM__LIVEINTERVAL, (liveInterval < 0 ? DEFAILT_LIVEINTERVAL : liveInterval)); this.liveInterval = props == null ? (liveInterval < 0 ? DEFAILT_LIVEINTERVAL : liveInterval) : props.getIntValue(WEBPARAM_LIVEINTERVAL, (liveInterval < 0 ? DEFAILT_LIVEINTERVAL : liveInterval));
if (liveInterval <= 0) { if (liveInterval <= 0) {
return; return;
} }
if (props != null) { if (props != null) {
this.wsMaxConns = props.getIntValue(WEBPARAM__WSMAXCONNS, this.wsMaxConns); this.wsMaxConns = props.getIntValue(WEBPARAM_WSMAXCONNS, this.wsMaxConns);
} }
if (props != null) { if (props != null) {
this.wsThreads = props.getIntValue(WEBPARAM__WSTHREADS, this.wsThreads); this.wsThreads = props.getIntValue(WEBPARAM_WSTHREADS, this.wsThreads);
} }
if (props != null) { if (props != null) {
this.wsMaxBody = props.getIntValue(WEBPARAM__WSMAXBODY, this.wsMaxBody); this.wsMaxBody = props.getIntValue(WEBPARAM_WSMAXBODY, this.wsMaxBody);
} }
if (scheduler != null) { if (scheduler != null) {
return; return;

View File

@@ -49,19 +49,19 @@ import org.redkale.util.*;
public abstract class WebSocketServlet extends HttpServlet implements Resourcable { public abstract class WebSocketServlet extends HttpServlet implements Resourcable {
@Comment("WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒") @Comment("WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒")
public static final String WEBPARAM__LIVEINTERVAL = "liveinterval"; public static final String WEBPARAM_LIVEINTERVAL = "liveinterval";
@Comment("WebScoket服务器最大连接数为0表示无限制") @Comment("WebScoket服务器最大连接数为0表示无限制")
public static final String WEBPARAM__WSMAXCONNS = "wsmaxconns"; public static final String WEBPARAM_WSMAXCONNS = "wsmaxconns";
@Comment("WebScoket服务器操作WebSocketNode对应CacheSource并发数, 为-1表示无限制为0表示系统默认值(CPU*8)") @Comment("WebScoket服务器操作WebSocketNode对应CacheSource并发数, 为-1表示无限制为0表示系统默认值(CPU*8)")
public static final String WEBPARAM__WSTHREADS = "wsthreads"; public static final String WEBPARAM_WSTHREADS = "wsthreads";
@Comment("最大消息体长度, 小于1表示无限制") @Comment("最大消息体长度, 小于1表示无限制")
public static final String WEBPARAM__WSMAXBODY = "wsmaxbody"; public static final String WEBPARAM_WSMAXBODY = "wsmaxbody";
@Comment("加密解密器") @Comment("加密解密器")
public static final String WEBPARAM__CRYPTOR = "cryptor"; public static final String WEBPARAM_CRYPTOR = "cryptor";
@Comment("WebScoket服务器给客户端进行ping操作的默认间隔时间, 单位: 秒") @Comment("WebScoket服务器给客户端进行ping操作的默认间隔时间, 单位: 秒")
public static final int DEFAILT_LIVEINTERVAL = 15; public static final int DEFAILT_LIVEINTERVAL = 15;
@@ -173,7 +173,7 @@ public abstract class WebSocketServlet extends HttpServlet implements Resourcabl
props = conf.getAnyValue("properties"); props = conf.getAnyValue("properties");
} }
if (props != null) { if (props != null) {
String cryptorClass = props.getValue(WEBPARAM__CRYPTOR); String cryptorClass = props.getValue(WEBPARAM_CRYPTOR);
if (cryptorClass != null && !cryptorClass.isEmpty()) { if (cryptorClass != null && !cryptorClass.isEmpty()) {
try { try {
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(cryptorClass); Class clazz = Thread.currentThread().getContextClassLoader().loadClass(cryptorClass);

View File

@@ -95,6 +95,7 @@ public class WebSocketWriteHandler implements CompletionHandler<Integer, Void> {
} }
respList.clear(); respList.clear();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
webSocket.kill(RETCODE_SENDEXCEPTION, "websocket send message failed on CompletionHandler"); webSocket.kill(RETCODE_SENDEXCEPTION, "websocket send message failed on CompletionHandler");
if (exc != null && context.getLogger().isLoggable(Level.FINER)) { if (exc != null && context.getLogger().isLoggable(Level.FINER)) {

View File

@@ -65,6 +65,59 @@ public abstract class Sncp {
Class type(); //serviceType Class type(); //serviceType
int index() default 0; //排列顺序, 主要用于Method int index() default 0; //排列顺序, 主要用于Method
}
public static class SchedulingEntry {
private Class serviceType;
private String methodName;
private Scheduled schedule;
private Runnable task;
public SchedulingEntry(Class serviceType, String methodName, Scheduled schedule, Runnable task) {
Objects.requireNonNull(serviceType);
Objects.requireNonNull(methodName);
Objects.requireNonNull(schedule);
Objects.requireNonNull(task);
this.serviceType = serviceType;
this.methodName = methodName;
this.schedule = schedule;
this.task = task;
}
public Class getServiceType() {
return serviceType;
}
public String getMethodName() {
return methodName;
}
public Scheduled getSchedule() {
return schedule;
}
public Runnable getTask() {
return task;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{"
+ "serviceType=" + serviceType
+ ", methodName=" + methodName
+ ", schedule.cron=" + schedule.cron()
+ ", schedule.zone=" + schedule.zone()
+ ", schedule.fixedDelay=" + schedule.fixedDelay()
+ ", schedule.fixedRate=" + schedule.fixedRate()
+ ", schedule.initialDelay=" + schedule.initialDelay()
+ ", schedule.timeUnit=" + schedule.timeUnit()
+ '}';
}
} }
private Sncp() { private Sncp() {
@@ -492,6 +545,7 @@ public abstract class Sncp {
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
return (Class<T>) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz); return (Class<T>) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
//do nothing
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
@@ -562,6 +616,7 @@ public abstract class Sncp {
c = newClazz.getDeclaredField(FIELDPREFIX + "_mq"); c = newClazz.getDeclaredField(FIELDPREFIX + "_mq");
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), c); RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), c);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
return (Class<T>) newClazz; return (Class<T>) newClazz;
} }
@@ -771,6 +826,7 @@ public abstract class Sncp {
} }
return service; return service;
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);

View File

@@ -58,6 +58,7 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
Class newHandlerClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz; Class newHandlerClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz;
return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz); return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz);
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

View File

@@ -58,7 +58,7 @@ public class SncpClientResult implements ClientResult {
@Override @Override
public boolean isKeepAlive() { public boolean isKeepAlive() {
return header == null ? false : header.isKeepAlive(); return header != null && header.isKeepAlive();
} }
@Override @Override

View File

@@ -236,6 +236,7 @@ public class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse>
} }
} }
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
java.lang.reflect.Type[] originalParamTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), service.getClass()); java.lang.reflect.Type[] originalParamTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), service.getClass());
java.lang.reflect.Type originalReturnType = TypeToken.getGenericType(method.getGenericReturnType(), service.getClass()); java.lang.reflect.Type originalReturnType = TypeToken.getGenericType(method.getGenericReturnType(), service.getClass());
@@ -474,6 +475,7 @@ public class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse>
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
newClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz; newClazz = clz == null ? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.')) : clz;
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
final java.lang.reflect.Type[] originalParamTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), serviceClass); final java.lang.reflect.Type[] originalParamTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), serviceClass);
@@ -667,6 +669,7 @@ public class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse>
try { try {
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), newClazz.getField("service")); RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), newClazz.getField("service"));
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
for (java.lang.reflect.Type t : originalParamTypes) { for (java.lang.reflect.Type t : originalParamTypes) {
if (t.toString().startsWith("java.lang.")) { if (t.toString().startsWith("java.lang.")) {

View File

@@ -77,7 +77,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
protected final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader = (s, i) protected final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader = (s, i)
-> ((CompletableFuture<Sheet>) querySheetDBAsync(i, false, false, false, null, null, (FilterNode) null)).thenApply(e -> e == null ? new ArrayList() : e.list(true)); -> ((CompletableFuture<Sheet>) querySheetDBAsync(i, false, false, false, null, null, (FilterNode) null)).thenApply(e -> e == null ? new ArrayList() : e.list(true));
protected final Function<Integer, String> signFunc = index -> prepareParamSign(index); protected final IntFunction<String> signFunc = index -> prepareParamSign(index);
//超过多少毫秒视为较慢, 会打印警告级别的日志, 默认值: 2000 //超过多少毫秒视为较慢, 会打印警告级别的日志, 默认值: 2000
protected long slowmsWarn; protected long slowmsWarn;

View File

@@ -1170,6 +1170,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
conn.commit(); conn.commit();
conn.offerUpdateStatement(stmt); conn.offerUpdateStatement(stmt);
} catch (SQLException e2) { } catch (SQLException e2) {
//do nothing
} }
} }
//表不存在更新条数为0 //表不存在更新条数为0
@@ -2994,6 +2995,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
stmt.close(); stmt.close();
conn.close(); conn.close();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
if (this.maxConns > newMaxconns) { //配置连接数过大 if (this.maxConns > newMaxconns) { //配置连接数过大
changeMaxConns(newMaxconns); changeMaxConns(newMaxconns);
@@ -3118,6 +3120,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
try { try {
x.close(); x.close();
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
}); });
} }

View File

@@ -4,7 +4,7 @@
package org.redkale.source; package org.redkale.source;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.IntFunction;
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.RedkaleClassLoader; import org.redkale.util.RedkaleClassLoader;
@@ -21,10 +21,10 @@ import org.redkale.util.RedkaleClassLoader;
*/ */
public interface DataNativeSqlParser { public interface DataNativeSqlParser {
NativeSqlStatement parse(Function<Integer, String> signFunc, String dbtype, String rawSql, Map<String, Object> params); NativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params);
public static DataNativeSqlParser loadFirst() { public static DataNativeSqlParser loadFirst() {
if (NativeSqlStatement._first_parser != NativeSqlStatement._NIL) { if (NativeSqlStatement._first_parser != NativeSqlStatement.PARSER_NIL) {
return NativeSqlStatement._first_parser; return NativeSqlStatement._first_parser;
} }
Iterator<DataNativeSqlParserProvider> it = ServiceLoader.load(DataNativeSqlParserProvider.class).iterator(); Iterator<DataNativeSqlParserProvider> it = ServiceLoader.load(DataNativeSqlParserProvider.class).iterator();
@@ -41,14 +41,14 @@ public interface DataNativeSqlParser {
public static class NativeSqlStatement { public static class NativeSqlStatement {
private static final DataNativeSqlParser _NIL = new DataNativeSqlParser() { private static final DataNativeSqlParser PARSER_NIL = new DataNativeSqlParser() {
@Override @Override
public NativeSqlStatement parse(Function<Integer, String> signFunc, String dbtype, String rawSql, Map<String, Object> params) { public NativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params) {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
}; };
private static DataNativeSqlParser _first_parser = _NIL; private static DataNativeSqlParser _first_parser = PARSER_NIL;
//根据参数值集合重新生成的带?参数可执行的sql //根据参数值集合重新生成的带?参数可执行的sql
protected String nativeSql; protected String nativeSql;

View File

@@ -735,6 +735,7 @@ public interface Attribute<T, F> {
getter = m; getter = m;
} }
} catch (Exception ex2) { } catch (Exception ex2) {
//do nothing
} }
} }
} }
@@ -742,6 +743,7 @@ public interface Attribute<T, F> {
try { try {
setter = clazz.getMethod("set" + mn, field.getType()); setter = clazz.getMethod("set" + mn, field.getType());
} catch (Exception ex) { } catch (Exception ex) {
//do nothing
} }
} }
} }
@@ -868,6 +870,7 @@ public interface Attribute<T, F> {
_attach.set(rs, attach); _attach.set(rs, attach);
return rs; return rs;
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
//--------------------------------------------------- //---------------------------------------------------
final ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); final ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);

View File

@@ -1054,6 +1054,7 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
} }
} }
} catch (Exception e2) { } catch (Exception e2) {
//do nothing
} }
} }
if (setter == null) { if (setter == null) {

View File

@@ -272,6 +272,7 @@ public interface Creator<T> {
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
return (Creator) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance(); return (Creator) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance();
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
Constructor<T> constructor0 = null; Constructor<T> constructor0 = null;

View File

@@ -33,7 +33,7 @@ public abstract class Flows {
* } * }
* </pre></blockquote> * </pre></blockquote>
*/ */
private static final String functionMonoFutureBinary = "cafebabe0000003700220a000200030700040c0005000" private static final String FUNCTION_MONO_FUTRUE_BINARY = "cafebabe0000003700220a000200030700040c0005000"
+ "60100106a6176612f6c616e672f4f626a6563740100063c696e69743e01000328295607000801001b72656163746f722f636f72652" + "60100106a6176612f6c616e672f4f626a6563740100063c696e69743e01000328295607000801001b72656163746f722f636f72652"
+ "f7075626c69736865722f4d6f6e6f0a0007000a0c000b000c010008746f46757475726501002a28294c6a6176612f7574696c2f636" + "f7075626c69736865722f4d6f6e6f0a0007000a0c000b000c010008746f46757475726501002a28294c6a6176612f7574696c2f636"
+ "f6e63757272656e742f436f6d706c657461626c654675747572653b0a000e000f0700100c0011001201002c6f72672f7265646b616" + "f6e63757272656e742f436f6d706c657461626c654675747572653b0a000e000f0700100c0011001201002c6f72672f7265646b616"
@@ -65,7 +65,7 @@ public abstract class Flows {
* } * }
* </pre></blockquote> * </pre></blockquote>
*/ */
private static final String functionFluxFutureBinary = "cafebabe0000003700280a000200030700040c0005000" private static final String FUNCTION_FLUX_FUTRUE_BINARY = "cafebabe0000003700280a000200030700040c0005000"
+ "60100106a6176612f6c616e672f4f626a6563740100063c696e69743e01000328295607000801001b72656163746f722f636f72" + "60100106a6176612f6c616e672f4f626a6563740100063c696e69743e01000328295607000801001b72656163746f722f636f72"
+ "652f7075626c69736865722f466c75780a0007000a0c000b000c01000b636f6c6c6563744c69737401001f28294c72656163746" + "652f7075626c69736865722f466c75780a0007000a0c000b000c01000b636f6c6c6563744c69737401001f28294c72656163746"
+ "f722f636f72652f7075626c69736865722f4d6f6e6f3b0a000e000f0700100c0011001201001b72656163746f722f636f72652f" + "f722f636f72652f7075626c69736865722f4d6f6e6f3b0a000e000f0700100c0011001201001b72656163746f722f636f72652f"
@@ -110,9 +110,10 @@ public abstract class Flows {
try { try {
monoFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousMonoFutureFunction"); monoFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousMonoFutureFunction");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (monoFuncClass == null) { if (monoFuncClass == null) {
byte[] classBytes = hexToBin(functionMonoFutureBinary); byte[] classBytes = hexToBin(FUNCTION_MONO_FUTRUE_BINARY);
monoFuncClass = (Class<Function<Object, CompletableFuture>>) new ClassLoader() { monoFuncClass = (Class<Function<Object, CompletableFuture>>) new ClassLoader() {
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);
@@ -128,9 +129,10 @@ public abstract class Flows {
try { try {
fluxFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousFluxFutureFunction"); fluxFuncClass = (Class) Thread.currentThread().getContextClassLoader().loadClass("org.redkale.util.AnonymousFluxFutureFunction");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (fluxFuncClass == null) { if (fluxFuncClass == null) {
byte[] classBytes = hexToBin(functionFluxFutureBinary); byte[] classBytes = hexToBin(FUNCTION_FLUX_FUTRUE_BINARY);
fluxFuncClass = (Class<Function<Object, CompletableFuture>>) new ClassLoader() { fluxFuncClass = (Class<Function<Object, CompletableFuture>>) new ClassLoader() {
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);
@@ -141,6 +143,7 @@ public abstract class Flows {
RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName());
reactorFluxFunction0 = (Function<Object, CompletableFuture>) fluxFuncClass.getDeclaredConstructor().newInstance(); reactorFluxFunction0 = (Function<Object, CompletableFuture>) fluxFuncClass.getDeclaredConstructor().newInstance();
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }

View File

@@ -12,18 +12,18 @@ import static org.redkale.asm.Opcodes.*;
import org.redkale.asm.Type; import org.redkale.asm.Type;
/** /**
* 动态生成指定方法的调用对象, 替代Method.invoke的反射方式 * 动态生成指定public方法的调用对象, 替代Method.invoke的反射方式
* *
* <p> * <p>
* 详情见: https://redkale.org * 详情见: https://redkale.org
* *
* @param <OBJECT_TYPE> 泛型 * @param <C> 泛型
* @param <RETURN_TYPE> 泛型 * @param <R> 泛型
* *
* @author zhangjx * @author zhangjx
* @since 2.5.0 * @since 2.5.0
*/ */
public interface Invoker<OBJECT_TYPE, RETURN_TYPE> { public interface Invoker<C, R> {
/** /**
* 调用方法放回值, 调用静态方法obj=null * 调用方法放回值, 调用静态方法obj=null
@@ -33,9 +33,9 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
* *
* @return 方法返回的结果 * @return 方法返回的结果
*/ */
public RETURN_TYPE invoke(OBJECT_TYPE obj, Object... params); public R invoke(C obj, Object... params);
public static <OBJECT_TYPE, RETURN_TYPE> Invoker<OBJECT_TYPE, RETURN_TYPE> load(final Class<OBJECT_TYPE> clazz, final String methodName, final Class... paramTypes) { public static <C, T> Invoker<C, T> load(final Class<C> clazz, final String methodName, final Class... paramTypes) {
java.lang.reflect.Method method = null; java.lang.reflect.Method method = null;
try { try {
method = clazz.getMethod(methodName, paramTypes); method = clazz.getMethod(methodName, paramTypes);
@@ -45,7 +45,7 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
return load(clazz, method); return load(clazz, method);
} }
public static <OBJECT_TYPE, RETURN_TYPE> Invoker<OBJECT_TYPE, RETURN_TYPE> create(final Class<OBJECT_TYPE> clazz, final String methodName, final Class... paramTypes) { public static <C, T> Invoker<C, T> create(final Class<C> clazz, final String methodName, final Class... paramTypes) {
java.lang.reflect.Method method = null; java.lang.reflect.Method method = null;
try { try {
method = clazz.getMethod(methodName, paramTypes); method = clazz.getMethod(methodName, paramTypes);
@@ -64,8 +64,8 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
public static <C, T> Invoker<C, T> create(final Class<C> clazz, final Method method) { public static <C, T> Invoker<C, T> create(final Class<C> clazz, final Method method) {
RedkaleClassLoader.putReflectionDeclaredMethods(clazz.getName()); RedkaleClassLoader.putReflectionDeclaredMethods(clazz.getName());
RedkaleClassLoader.putReflectionMethod(clazz.getName(), method); RedkaleClassLoader.putReflectionMethod(clazz.getName(), method);
boolean throwflag = Utility.contains(method.getExceptionTypes(), e -> !RuntimeException.class.isAssignableFrom(e)); //方法是否会抛出非RuntimeException异常 boolean throwFlag = Utility.contains(method.getExceptionTypes(), e -> !RuntimeException.class.isAssignableFrom(e)); //方法是否会抛出非RuntimeException异常
boolean staticflag = Modifier.isStatic(method.getModifiers()); boolean staticFlag = Modifier.isStatic(method.getModifiers());
final Class<T> returnType = (Class<T>) method.getReturnType(); final Class<T> returnType = (Class<T>) method.getReturnType();
final String supDynName = Invoker.class.getName().replace('.', '/'); final String supDynName = Invoker.class.getName().replace('.', '/');
final String interName = clazz.getName().replace('.', '/'); final String interName = clazz.getName().replace('.', '/');
@@ -100,6 +100,7 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
return (Invoker<C, T>) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance(); return (Invoker<C, T>) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance();
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
//------------------------------------------------------------- //-------------------------------------------------------------
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
@@ -122,11 +123,11 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
Label label0 = new Label(); Label label0 = new Label();
Label label1 = new Label(); Label label1 = new Label();
Label label2 = new Label(); Label label2 = new Label();
if (throwflag) { if (throwFlag) {
mv.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable"); mv.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable");
mv.visitLabel(label0); mv.visitLabel(label0);
} }
if (!staticflag) { if (!staticFlag) {
mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1);
} }
@@ -142,11 +143,11 @@ public interface Invoker<OBJECT_TYPE, RETURN_TYPE> {
paramIndex++; paramIndex++;
} }
mv.visitMethodInsn(staticflag ? INVOKESTATIC : (clazz.isInterface() ? INVOKEINTERFACE : INVOKEVIRTUAL), interName, method.getName(), "(" + paramDescs + ")" + returnPrimiveDesc, !staticflag && clazz.isInterface()); mv.visitMethodInsn(staticFlag ? INVOKESTATIC : (clazz.isInterface() ? INVOKEINTERFACE : INVOKEVIRTUAL), interName, method.getName(), "(" + paramDescs + ")" + returnPrimiveDesc, !staticFlag && clazz.isInterface());
Asms.visitPrimitiveValueOf(mv, returnType); Asms.visitPrimitiveValueOf(mv, returnType);
mv.visitLabel(label1); mv.visitLabel(label1);
mv.visitInsn(ARETURN); mv.visitInsn(ARETURN);
if (throwflag) { if (throwFlag) {
mv.visitLabel(label2); mv.visitLabel(label2);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[]{"java/lang/Throwable"}); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[]{"java/lang/Throwable"});
mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ASTORE, 3);

View File

@@ -1041,13 +1041,14 @@ public class NonBlockingHashMap<TypeK, TypeV> extends AbstractMap<TypeK, TypeV>
newkvs = _newkvs; // Between dorking around, another thread did it newkvs = _newkvs; // Between dorking around, another thread did it
if (newkvs != null) // See if resize is already in progress if (newkvs != null) // See if resize is already in progress
return newkvs; // Use the new table already return newkvs; // Use the new table already
// TODO - use a wait with timeout, so we'll wakeup as soon as the new table // TO DO - use a wait with timeout, so we'll wakeup as soon as the new table
// is ready, or after the timeout in any case. // is ready, or after the timeout in any case.
// For now, sleep a tad and see if the 2 guys already trying to make // For now, sleep a tad and see if the 2 guys already trying to make
// the table actually get around to making it happen. // the table actually get around to making it happen.
try { try {
Thread.sleep(megs); Thread.sleep(megs);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }
// Last check, since the 'new' below is expensive and there is a chance // Last check, since the 'new' below is expensive and there is a chance

View File

@@ -14,13 +14,13 @@ package org.redkale.util;
*/ */
public final class Redkale { public final class Redkale {
private static final String rootPackage = "org.redkale"; private static final String ROOT_PACKAGE = "org.redkale";
private Redkale() { private Redkale() {
} }
public static String getRootPackage() { public static String getRootPackage() {
return rootPackage; return ROOT_PACKAGE;
} }
public static String getDotedVersion() { public static String getDotedVersion() {

View File

@@ -3,8 +3,8 @@ 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.ClassWriter.COMPUTE_FRAMES;
import org.redkale.asm.*; import org.redkale.asm.*;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
/** /**
@@ -17,7 +17,8 @@ import static org.redkale.asm.Opcodes.*;
* @author zhangjx * @author zhangjx
* @param <D> 目标对象的数据类型 * @param <D> 目标对象的数据类型
* @param <S> 源对象的数据类型 * @param <S> 源对象的数据类型
* @deprecated *
* @deprecated
*/ */
@Deprecated(since = "2.8.0") @Deprecated(since = "2.8.0")
public interface Reproduce<D, S> extends BiFunction<D, S, D> { public interface Reproduce<D, S> extends BiFunction<D, S, D> {
@@ -64,6 +65,7 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
return (Reproduce) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance(); return (Reproduce) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz).getDeclaredConstructor().newInstance();
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
@@ -87,16 +89,26 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
//mv.setDebug(true); //mv.setDebug(true);
for (java.lang.reflect.Field field : srcClass.getFields()) { for (java.lang.reflect.Field field : srcClass.getFields()) {
if (Modifier.isStatic(field.getModifiers())) continue; if (Modifier.isStatic(field.getModifiers())) {
if (Modifier.isFinal(field.getModifiers())) continue; continue;
if (!Modifier.isPublic(field.getModifiers())) continue; }
if (Modifier.isFinal(field.getModifiers())) {
continue;
}
if (!Modifier.isPublic(field.getModifiers())) {
continue;
}
final String sfname = field.getName(); final String sfname = field.getName();
if (srcColumnPredicate != null && !srcColumnPredicate.test(field, sfname)) continue; if (srcColumnPredicate != null && !srcColumnPredicate.test(field, sfname)) {
continue;
}
final String dfname = names == null ? sfname : names.getOrDefault(sfname, sfname); final String dfname = names == null ? sfname : names.getOrDefault(sfname, sfname);
java.lang.reflect.Method setter = null; java.lang.reflect.Method setter = null;
try { try {
if (!field.getType().equals(destClass.getField(dfname).getType())) continue; if (!field.getType().equals(destClass.getField(dfname).getType())) {
continue;
}
} catch (Exception e) { } catch (Exception e) {
try { try {
char[] cs = dfname.toCharArray(); char[] cs = dfname.toCharArray();
@@ -119,19 +131,31 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
} }
for (java.lang.reflect.Method getter : srcClass.getMethods()) { for (java.lang.reflect.Method getter : srcClass.getMethods()) {
if (Modifier.isStatic(getter.getModifiers())) continue; if (Modifier.isStatic(getter.getModifiers())) {
if (getter.getParameterTypes().length > 0) continue; continue;
if ("getClass".equals(getter.getName())) continue; }
if (!getter.getName().startsWith("get") && !getter.getName().startsWith("is")) continue; if (getter.getParameterTypes().length > 0) {
continue;
}
if ("getClass".equals(getter.getName())) {
continue;
}
if (!getter.getName().startsWith("get") && !getter.getName().startsWith("is")) {
continue;
}
final boolean is = getter.getName().startsWith("is"); final boolean is = getter.getName().startsWith("is");
String sfname = getter.getName().substring(is ? 2 : 3); String sfname = getter.getName().substring(is ? 2 : 3);
if (sfname.isEmpty()) continue; if (sfname.isEmpty()) {
continue;
}
if (sfname.length() < 2 || Character.isLowerCase(sfname.charAt(1))) { if (sfname.length() < 2 || Character.isLowerCase(sfname.charAt(1))) {
char[] cs = sfname.toCharArray(); char[] cs = sfname.toCharArray();
cs[0] = Character.toLowerCase(cs[0]); cs[0] = Character.toLowerCase(cs[0]);
sfname = new String(cs); sfname = new String(cs);
} }
if (srcColumnPredicate != null && !srcColumnPredicate.test(getter, sfname)) continue; if (srcColumnPredicate != null && !srcColumnPredicate.test(getter, sfname)) {
continue;
}
final String dfname = names == null ? sfname : names.getOrDefault(sfname, sfname); final String dfname = names == null ? sfname : names.getOrDefault(sfname, sfname);
java.lang.reflect.Method setter = null; java.lang.reflect.Method setter = null;
@@ -144,7 +168,9 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
} catch (Exception e) { } catch (Exception e) {
try { try {
srcField = destClass.getField(dfname); srcField = destClass.getField(dfname);
if (!getter.getReturnType().equals(srcField.getType())) continue; if (!getter.getReturnType().equals(srcField.getType())) {
continue;
}
} catch (Exception e2) { } catch (Exception e2) {
continue; continue;
} }

View File

@@ -34,24 +34,24 @@ public class SelectColumn implements Predicate<String> {
if (len < 1) { if (len < 1) {
return; return;
} }
Pattern[] regs = null; Pattern[] regxs = null;
String[] cols = null; String[] cols = null;
int regcount = 0; int regcount = 0;
int colcount = 0; int colcount = 0;
for (String col : columns0) { for (String col : columns0) {
boolean reg = false; boolean regx = false;
for (int i = 0; i < col.length(); i++) { for (int i = 0; i < col.length(); i++) {
char ch = col.charAt(i); char ch = col.charAt(i);
if (ch == '^' || ch == '$' || ch == '*' || ch == '?' || ch == '+' || ch == '[' || ch == '(') { if (ch == '^' || ch == '$' || ch == '*' || ch == '?' || ch == '+' || ch == '[' || ch == '(') {
reg = true; regx = true;
break; break;
} }
} }
if (reg) { if (regx) {
if (regs == null) { if (regxs == null) {
regs = new Pattern[len]; regxs = new Pattern[len];
} }
regs[regcount++] = Pattern.compile(col); regxs[regcount++] = Pattern.compile(col);
} else { } else {
if (cols == null) { if (cols == null) {
cols = new String[len]; cols = new String[len];
@@ -59,11 +59,11 @@ public class SelectColumn implements Predicate<String> {
cols[colcount++] = col; cols[colcount++] = col;
} }
} }
if (regs != null) { if (regxs != null) {
if (regcount == len) { if (regcount == len) {
this.patterns = regs; this.patterns = regxs;
} else { } else {
this.patterns = Arrays.copyOf(regs, regcount); this.patterns = Arrays.copyOf(regxs, regcount);
} }
} }
if (cols != null) { if (cols != null) {

View File

@@ -17,9 +17,9 @@ import java.util.function.Supplier;
*/ */
public class Traces { public class Traces {
private static final boolean enable = !Boolean.getBoolean("redkale.trace.disable"); private static final boolean ENABLE = !Boolean.getBoolean("redkale.trace.disable");
private static final String PROCESS_ID = UUID.randomUUID().toString().replaceAll("-", ""); private static final String PROCESS_ID = UUID.randomUUID().toString().replace("-", "");
private static final AtomicLong sequence = new AtomicLong(System.currentTimeMillis()); private static final AtomicLong sequence = new AtomicLong(System.currentTimeMillis());
@@ -33,7 +33,7 @@ public class Traces {
* @return boolean * @return boolean
*/ */
public static boolean enable() { public static boolean enable() {
return enable; return ENABLE;
} }
/** /**
@@ -42,7 +42,7 @@ public class Traces {
* @return String * @return String
*/ */
public static String createTraceid() { public static String createTraceid() {
return enable ? tidSupplier.get() : null; return ENABLE ? tidSupplier.get() : null;
} }
/** /**
@@ -51,14 +51,14 @@ public class Traces {
* @return String * @return String
*/ */
public static String currentTraceid() { public static String currentTraceid() {
return enable ? localTrace.get() : null; return ENABLE ? localTrace.get() : null;
} }
/** /**
* 移除当前线程的traceid * 移除当前线程的traceid
*/ */
public static void removeTraceid() { public static void removeTraceid() {
if (enable) { if (ENABLE) {
localTrace.remove(); localTrace.remove();
} }
} }
@@ -70,7 +70,7 @@ public class Traces {
* *
*/ */
public static void currentTraceid(String traceid) { public static void currentTraceid(String traceid) {
if (enable) { if (ENABLE) {
if (traceid != null && !traceid.isEmpty()) { if (traceid != null && !traceid.isEmpty()) {
localTrace.set(traceid); localTrace.set(traceid);
} else { } else {
@@ -87,7 +87,7 @@ public class Traces {
* @return String * @return String
*/ */
public static String computeIfAbsent(String traceid) { public static String computeIfAbsent(String traceid) {
if (enable) { if (ENABLE) {
String rs = traceid; String rs = traceid;
if (rs == null || rs.isEmpty()) { if (rs == null || rs.isEmpty()) {
rs = tidSupplier.get(); rs = tidSupplier.get();
@@ -107,7 +107,7 @@ public class Traces {
* @return String * @return String
*/ */
public static String computeIfAbsent(String traceid, String traceid2) { public static String computeIfAbsent(String traceid, String traceid2) {
if (enable) { if (ENABLE) {
String rs = traceid; String rs = traceid;
if (rs == null || rs.isEmpty()) { if (rs == null || rs.isEmpty()) {
if (traceid2 == null || traceid2.isEmpty()) { if (traceid2 == null || traceid2.isEmpty()) {

View File

@@ -639,6 +639,7 @@ public abstract class TypeToken<T> {
try { try {
return loader.loadClass(newDynName.replace('/', '.')).getField("field").getGenericType(); return loader.loadClass(newDynName.replace('/', '.')).getField("field").getGenericType();
} catch (Throwable ex) { } catch (Throwable ex) {
//do nothing
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
org.redkale.asm.ClassWriter cw = new org.redkale.asm.ClassWriter(COMPUTE_FRAMES); org.redkale.asm.ClassWriter cw = new org.redkale.asm.ClassWriter(COMPUTE_FRAMES);

View File

@@ -41,7 +41,7 @@ public final class Utility {
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private static final int cpus = Integer.getInteger("redkale.cpus", Runtime.getRuntime().availableProcessors()); private static final int CPUS = Integer.getInteger("redkale.cpus", Runtime.getRuntime().availableProcessors());
private static final int MAX_POW2 = 1 << 30; private static final int MAX_POW2 = 1 << 30;
@@ -148,6 +148,7 @@ public final class Utility {
try { try {
virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousThreadLocal"); virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousThreadLocal");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (virtualClazz1 == null) { if (virtualClazz1 == null) {
byte[] classBytes = hexToBin(functionThreadLocalBinary); byte[] classBytes = hexToBin(functionThreadLocalBinary);
@@ -162,6 +163,7 @@ public final class Utility {
Supplier supplier = () -> null; Supplier supplier = () -> null;
virtualThreadLocalFunction0 = virtualClazz1.getConstructor(Supplier.class).newInstance(supplier); virtualThreadLocalFunction0 = virtualClazz1.getConstructor(Supplier.class).newInstance(supplier);
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} }
@@ -170,6 +172,7 @@ public final class Utility {
try { try {
virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousThreadFactory"); virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousThreadFactory");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (virtualClazz1 == null) { if (virtualClazz1 == null) {
byte[] classBytes = hexToBin(functionThreadFactoryBinary); byte[] classBytes = hexToBin(functionThreadFactoryBinary);
@@ -183,6 +186,7 @@ public final class Utility {
RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName());
virtualThreadFactoryFunction0 = virtualClazz1.getConstructor(String.class).newInstance(null); virtualThreadFactoryFunction0 = virtualClazz1.getConstructor(String.class).newInstance(null);
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} }
@@ -191,6 +195,7 @@ public final class Utility {
try { try {
virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousVirtualPoolFunction"); virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousVirtualPoolFunction");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (virtualClazz1 == null) { if (virtualClazz1 == null) {
byte[] classBytes = hexToBin(functionVirtualPoolBinary); byte[] classBytes = hexToBin(functionVirtualPoolBinary);
@@ -204,6 +209,7 @@ public final class Utility {
RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName());
virtualPoolFunction0 = virtualClazz1.getConstructor().newInstance(); virtualPoolFunction0 = virtualClazz1.getConstructor().newInstance();
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} }
@@ -212,6 +218,7 @@ public final class Utility {
try { try {
virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousVirtualExecutor"); virtualClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousVirtualExecutor");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (virtualClazz1 == null) { if (virtualClazz1 == null) {
byte[] classBytes = hexToBin(consumerVirtualExecutorBinary); byte[] classBytes = hexToBin(consumerVirtualExecutorBinary);
@@ -225,6 +232,7 @@ public final class Utility {
RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName()); RedkaleClassLoader.putReflectionDeclaredConstructors(virtualClazz1, virtualClazz1.getName());
virtualExecutorConsumer0 = virtualClazz1.getConstructor().newInstance(); virtualExecutorConsumer0 = virtualClazz1.getConstructor().newInstance();
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
} }
} }
@@ -240,6 +248,7 @@ public final class Utility {
try { try {
unsafeClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousUnsafe"); unsafeClazz1 = (Class) loader.loadClass("org.redkale.util.AnonymousUnsafe");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (unsafeClazz1 == null) { if (unsafeClazz1 == null) {
byte[] classBytes = hexToBin(funcAnonymousUnsafeBinary); byte[] classBytes = hexToBin(funcAnonymousUnsafeBinary);
@@ -269,6 +278,7 @@ public final class Utility {
try { try {
shutdownClazz1 = (Class) loader.loadClass("org.redkale.util.SignalShutDown"); shutdownClazz1 = (Class) loader.loadClass("org.redkale.util.SignalShutDown");
} catch (Throwable t) { } catch (Throwable t) {
//do nothing
} }
if (shutdownClazz1 == null) { if (shutdownClazz1 == null) {
byte[] classBytes = hexToBin(consumerSignalShutdownBinary); byte[] classBytes = hexToBin(consumerSignalShutdownBinary);
@@ -329,7 +339,7 @@ public final class Utility {
} }
public static int cpus() { public static int cpus() {
return cpus; return CPUS;
} }
public static Function<String, ExecutorService> virtualExecutorFunction() { public static Function<String, ExecutorService> virtualExecutorFunction() {
@@ -422,6 +432,7 @@ public final class Utility {
try { try {
Thread.sleep(millis); Thread.sleep(millis);
} catch (Exception e) { } catch (Exception e) {
//do nothing
} }
} }