Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b3658143a | ||
|
|
6d69ff546b | ||
|
|
9555e3c9b9 | ||
|
|
744634dbdd | ||
|
|
de5ee844c4 | ||
|
|
ae73cee357 | ||
|
|
d1cf9be8d7 | ||
|
|
43ae77ab33 | ||
|
|
182a75cfad | ||
|
|
222dc0edce | ||
|
|
c7a81513fe |
@@ -22,6 +22,7 @@ import java.util.logging.Formatter;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class LogFileHandler extends Handler {
|
public class LogFileHandler extends Handler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ public class NodeHttpServer extends NodeServer {
|
|||||||
}, WebSocketNode.class);
|
}, WebSocketNode.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void loadHttpFilter(final AnyValue filtersConf, final ClassFilter<? extends Filter> classFilter) throws Exception {
|
protected void loadHttpFilter(final AnyValue filtersConf, final ClassFilter<? extends Filter> classFilter) throws Exception {
|
||||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||||
@@ -138,6 +139,7 @@ public class NodeHttpServer extends NodeServer {
|
|||||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
|
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void loadHttpServlet(final ClassFilter<? extends Servlet> servletFilter, ClassFilter<? extends WebSocket> webSocketFilter) throws Exception {
|
protected void loadHttpServlet(final ClassFilter<? extends Servlet> servletFilter, ClassFilter<? extends WebSocket> webSocketFilter) throws Exception {
|
||||||
final AnyValue servletsConf = this.serverConf.getAnyValue("servlets");
|
final AnyValue servletsConf = this.serverConf.getAnyValue("servlets");
|
||||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||||
@@ -195,6 +197,7 @@ public class NodeHttpServer extends NodeServer {
|
|||||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString().trim());
|
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void loadRestServlet(final ClassFilter<? extends WebSocket> webSocketFilter, final AnyValue restConf, final List<Object> restedObjects, final StringBuilder sb) throws Exception {
|
protected void loadRestServlet(final ClassFilter<? extends WebSocket> webSocketFilter, final AnyValue restConf, final List<Object> restedObjects, final StringBuilder sb) throws Exception {
|
||||||
if (!rest) return;
|
if (!rest) return;
|
||||||
if (restConf == null) return; //不存在REST服务
|
if (restConf == null) return; //不存在REST服务
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class NodeSncpServer extends NodeServer {
|
|||||||
if (sncpServer != null) loadSncpFilter(this.serverConf.getAnyValue("fliters"), filterFilter);
|
if (sncpServer != null) loadSncpFilter(this.serverConf.getAnyValue("fliters"), filterFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void loadSncpFilter(final AnyValue servletsConf, final ClassFilter<? extends Filter> classFilter) throws Exception {
|
protected void loadSncpFilter(final AnyValue servletsConf, final ClassFilter<? extends Filter> classFilter) throws Exception {
|
||||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||||
@@ -106,6 +107,7 @@ public class NodeSncpServer extends NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected ClassFilter<Filter> createFilterClassFilter() {
|
protected ClassFilter<Filter> createFilterClassFilter() {
|
||||||
return createClassFilter(null, null, SncpFilter.class, new Class[]{org.redkale.watch.WatchFilter.class}, null, "filters", "filter");
|
return createClassFilter(null, null, SncpFilter.class, new Class[]{org.redkale.watch.WatchFilter.class}, null, "filters", "filter");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,23 @@ public final class AnyEncoder<T> implements Encodeable<Writer, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void convertMapTo(final Writer out, final Object... values) {
|
||||||
|
if (values == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
int count = values.length - values.length % 2;
|
||||||
|
out.writeMapB(count / 2);
|
||||||
|
for (int i = 0; i < count; i += 2) {
|
||||||
|
if (i > 0) out.writeArrayMark();
|
||||||
|
this.convertTo(out, (T) values[i]);
|
||||||
|
out.writeMapMark();
|
||||||
|
this.convertTo(out, (T) values[i + 1]);
|
||||||
|
}
|
||||||
|
out.writeMapE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Object.class;
|
return Object.class;
|
||||||
|
|||||||
@@ -40,4 +40,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
|||||||
public abstract ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value);
|
public abstract ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value);
|
||||||
|
|
||||||
public abstract ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value);
|
public abstract ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value);
|
||||||
|
|
||||||
|
public abstract ByteBuffer[] convertMapTo(final Supplier<ByteBuffer> supplier, final Object... values);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
return convertFrom(type, bytes, 0, bytes.length);
|
return convertFrom(type, bytes, 0, bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertFrom(final Type type, final byte[] bytes, final int start, final int len) {
|
public <T> T convertFrom(final Type type, final byte[] bytes, final int start, final int len) {
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
final BsonReader in = readerPool.get();
|
final BsonReader in = readerPool.get();
|
||||||
@@ -114,23 +115,27 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertFrom(final Type type, final InputStream in) {
|
public <T> T convertFrom(final Type type, final InputStream in) {
|
||||||
if (type == null || in == null) return null;
|
if (type == null || in == null) return null;
|
||||||
return (T) factory.loadDecoder(type).convertFrom(new BsonStreamReader(in));
|
return (T) factory.loadDecoder(type).convertFrom(new BsonStreamReader(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertFrom(final Type type, final ByteBuffer... buffers) {
|
public <T> T convertFrom(final Type type, final ByteBuffer... buffers) {
|
||||||
if (type == null || buffers.length < 1) return null;
|
if (type == null || buffers.length < 1) return null;
|
||||||
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader((ConvertMask) null, buffers));
|
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader((ConvertMask) null, buffers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) {
|
public <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) {
|
||||||
if (type == null || buffers.length < 1) return null;
|
if (type == null || buffers.length < 1) return null;
|
||||||
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader(mask, buffers));
|
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader(mask, buffers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertFrom(final Type type, final BsonReader reader) {
|
public <T> T convertFrom(final Type type, final BsonReader reader) {
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -159,6 +164,15 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] convertMapTo(final Object... values) {
|
||||||
|
if (values == null) return null;
|
||||||
|
final BsonWriter out = writerPool.get().tiny(tiny);
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
byte[] result = out.toArray();
|
||||||
|
writerPool.offer(out);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void convertTo(final OutputStream out, final Object value) {
|
public void convertTo(final OutputStream out, final Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
new BsonStreamWriter(tiny, out).writeNull();
|
new BsonStreamWriter(tiny, out).writeNull();
|
||||||
@@ -176,6 +190,14 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convertMapTo(final OutputStream out, final Object... values) {
|
||||||
|
if (values == null) {
|
||||||
|
new BsonStreamWriter(tiny, out).writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(new BsonStreamWriter(tiny, out), values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value) {
|
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value) {
|
||||||
if (supplier == null) return null;
|
if (supplier == null) return null;
|
||||||
@@ -200,6 +222,18 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
return out.toBuffers();
|
return out.toBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ByteBuffer[] convertMapTo(final Supplier<ByteBuffer> supplier, final Object... values) {
|
||||||
|
if (supplier == null) return null;
|
||||||
|
BsonByteBufferWriter out = new BsonByteBufferWriter(tiny, supplier);
|
||||||
|
if (values == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
}
|
||||||
|
return out.toBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
public void convertTo(final BsonWriter writer, final Object value) {
|
public void convertTo(final BsonWriter writer, final Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
@@ -213,6 +247,14 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
factory.loadEncoder(type).convertTo(writer, value);
|
factory.loadEncoder(type).convertTo(writer, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convertMapTo(final BsonWriter writer, final Object... values) {
|
||||||
|
if (values == null) {
|
||||||
|
writer.writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(writer, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BsonWriter convertToWriter(final Object value) {
|
public BsonWriter convertToWriter(final Object value) {
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
return convertToWriter(value.getClass(), value);
|
return convertToWriter(value.getClass(), value);
|
||||||
@@ -225,4 +267,9 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BsonWriter convertMapToWriter(final Object... values) {
|
||||||
|
final BsonWriter out = writerPool.get().tiny(tiny);
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ public class BsonReader extends Reader {
|
|||||||
* 跳过属性的值
|
* 跳过属性的值
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final void skipValue() {
|
public final void skipValue() {
|
||||||
if (typeval == 0) return;
|
if (typeval == 0) return;
|
||||||
final byte val = this.typeval;
|
final byte val = this.typeval;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public final class DateSimpledCoder<R extends Reader, W extends Writer> extends
|
|||||||
@Override
|
@Override
|
||||||
public Date convertFrom(R in) {
|
public Date convertFrom(R in) {
|
||||||
long t = in.readLong();
|
long t = in.readLong();
|
||||||
return t == 0 ? null : new Date();
|
return t == 0 ? null : new Date(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.net.*;
|
|||||||
* @param <R> Reader输入的子类型
|
* @param <R> Reader输入的子类型
|
||||||
* @param <W> Writer输出的子类型
|
* @param <W> Writer输出的子类型
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final class InetAddressSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetAddress> {
|
public final class InetAddressSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetAddress> {
|
||||||
|
|
||||||
public static final InetAddressSimpledCoder instance = new InetAddressSimpledCoder();
|
public static final InetAddressSimpledCoder instance = new InetAddressSimpledCoder();
|
||||||
@@ -50,6 +51,7 @@ public final class InetAddressSimpledCoder<R extends Reader, W extends Writer> e
|
|||||||
* @param <R> Reader输入的子类型
|
* @param <R> Reader输入的子类型
|
||||||
* @param <W> Writer输出的子类型
|
* @param <W> Writer输出的子类型
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final static class InetSocketAddressSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetSocketAddress> {
|
public final static class InetSocketAddressSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, InetSocketAddress> {
|
||||||
|
|
||||||
public static final InetSocketAddressSimpledCoder instance = new InetSocketAddressSimpledCoder();
|
public static final InetSocketAddressSimpledCoder instance = new InetSocketAddressSimpledCoder();
|
||||||
|
|||||||
@@ -149,6 +149,15 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String convertMapTo(final Object... values) {
|
||||||
|
if (values == null) return "null";
|
||||||
|
final JsonWriter out = writerPool.get().tiny(tiny);
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
String result = out.toString();
|
||||||
|
writerPool.offer(out);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void convertTo(final OutputStream out, final Object value) {
|
public void convertTo(final OutputStream out, final Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
new JsonStreamWriter(tiny, out).writeNull();
|
new JsonStreamWriter(tiny, out).writeNull();
|
||||||
@@ -166,6 +175,14 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convertMapTo(final OutputStream out, final Object... values) {
|
||||||
|
if (values == null) {
|
||||||
|
new JsonStreamWriter(tiny, out).writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(new JsonStreamWriter(tiny, out), values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value) {
|
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Object value) {
|
||||||
if (supplier == null) return null;
|
if (supplier == null) return null;
|
||||||
@@ -190,6 +207,18 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
return out.toBuffers();
|
return out.toBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ByteBuffer[] convertMapTo(final Supplier<ByteBuffer> supplier, final Object... values) {
|
||||||
|
if (supplier == null) return null;
|
||||||
|
JsonByteBufferWriter out = new JsonByteBufferWriter(tiny, null, supplier);
|
||||||
|
if (values == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
}
|
||||||
|
return out.toBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
public void convertTo(final JsonWriter writer, final Object value) {
|
public void convertTo(final JsonWriter writer, final Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
writer.writeNull();
|
writer.writeNull();
|
||||||
@@ -207,6 +236,14 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convertMapTo(final JsonWriter writer, final Object... values) {
|
||||||
|
if (values == null) {
|
||||||
|
writer.writeNull();
|
||||||
|
} else {
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(writer, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public JsonWriter convertToWriter(final Object value) {
|
public JsonWriter convertToWriter(final Object value) {
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
return convertToWriter(value.getClass(), value);
|
return convertToWriter(value.getClass(), value);
|
||||||
@@ -218,4 +255,10 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
factory.loadEncoder(type).convertTo(out, value);
|
factory.loadEncoder(type).convertTo(out, value);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonWriter convertMapToWriter(final Object... values) {
|
||||||
|
final JsonWriter out = writerPool.get().tiny(tiny);
|
||||||
|
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(out, values);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.redkale.util.*;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||||
|
|
||||||
private static final JsonFactory instance = new JsonFactory(null, Boolean.getBoolean("convert.json.tiny"));
|
private static final JsonFactory instance = new JsonFactory(null, Boolean.getBoolean("convert.json.tiny"));
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void init(C context, AnyValue config) {
|
public void init(C context, AnyValue config) {
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
if (!filters.isEmpty()) {
|
if (!filters.isEmpty()) {
|
||||||
@@ -136,6 +137,7 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void destroy(C context, AnyValue config) {
|
public void destroy(C context, AnyValue config) {
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
if (!filters.isEmpty()) {
|
if (!filters.isEmpty()) {
|
||||||
@@ -146,6 +148,7 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void addFilter(Filter<C, R, P> filter, AnyValue conf) {
|
public void addFilter(Filter<C, R, P> filter, AnyValue conf) {
|
||||||
filter._conf = conf;
|
filter._conf = conf;
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
@@ -176,6 +179,7 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Filter<C, R, P>> T removeFilter(Predicate<T> predicate) {
|
public <T extends Filter<C, R, P>> T removeFilter(Predicate<T> predicate) {
|
||||||
if (this.headFilter == null || predicate == null) return null;
|
if (this.headFilter == null || predicate == null) return null;
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
@@ -198,10 +202,12 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Filter<C, R, P>> List<T> getFilters() {
|
public <T extends Filter<C, R, P>> List<T> getFilters() {
|
||||||
return (List) new ArrayList<>(filters);
|
return (List) new ArrayList<>(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public abstract void addServlet(S servlet, Object attachment, AnyValue conf, K... mappings);
|
public abstract void addServlet(S servlet, Object attachment, AnyValue conf, K... mappings);
|
||||||
|
|
||||||
public final void prepare(final ByteBuffer buffer, final R request, final P response) throws IOException {
|
public final void prepare(final ByteBuffer buffer, final R request, final P response) throws IOException {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public abstract class Request<C extends Context> {
|
|||||||
* 返回值:Integer.MIN_VALUE: 帧数据; -1:数据不合法; 0:解析完毕; >0: 需再读取的字节数。
|
* 返回值:Integer.MIN_VALUE: 帧数据; -1:数据不合法; 0:解析完毕; >0: 需再读取的字节数。
|
||||||
*
|
*
|
||||||
* @param buffer ByteBuffer对象
|
* @param buffer ByteBuffer对象
|
||||||
|
*
|
||||||
* @return 缺少的字节数
|
* @return 缺少的字节数
|
||||||
*/
|
*/
|
||||||
protected abstract int readHeader(ByteBuffer buffer);
|
protected abstract int readHeader(ByteBuffer buffer);
|
||||||
@@ -59,6 +60,7 @@ public abstract class Request<C extends Context> {
|
|||||||
* 读取buffer,并返回读取的有效数据长度
|
* 读取buffer,并返回读取的有效数据长度
|
||||||
*
|
*
|
||||||
* @param buffer ByteBuffer对象
|
* @param buffer ByteBuffer对象
|
||||||
|
*
|
||||||
* @return 有效数据长度
|
* @return 有效数据长度
|
||||||
*/
|
*/
|
||||||
protected abstract int readBody(ByteBuffer buffer);
|
protected abstract int readBody(ByteBuffer buffer);
|
||||||
@@ -82,6 +84,7 @@ public abstract class Request<C extends Context> {
|
|||||||
return (T) properties.get(name);
|
return (T) properties.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected <T> T removeProperty(String name) {
|
protected <T> T removeProperty(String name) {
|
||||||
return (T) properties.remove(name);
|
return (T) properties.remove(name);
|
||||||
}
|
}
|
||||||
@@ -100,6 +103,7 @@ public abstract class Request<C extends Context> {
|
|||||||
return (T) attributes.get(name);
|
return (T) attributes.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T removeAttribute(String name) {
|
public <T> T removeAttribute(String name) {
|
||||||
return (T) attributes.remove(name);
|
return (T) attributes.remove(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class HttpContext extends Context {
|
|||||||
return responsePool;
|
return responsePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected <H extends AsyncHandler> Creator<H> loadAsyncHandlerCreator(Class<H> handlerClass) {
|
protected <H extends AsyncHandler> Creator<H> loadAsyncHandlerCreator(Class<H> handlerClass) {
|
||||||
Creator<H> creator = asyncHandlerCreators.get(handlerClass);
|
Creator<H> creator = asyncHandlerCreators.get(handlerClass);
|
||||||
if (creator == null) {
|
if (creator == null) {
|
||||||
@@ -62,6 +63,7 @@ public class HttpContext extends Context {
|
|||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private <H extends AsyncHandler> Creator<H> createAsyncHandlerCreator(Class<H> handlerClass) {
|
private <H extends AsyncHandler> Creator<H> createAsyncHandlerCreator(Class<H> handlerClass) {
|
||||||
//生成规则与SncpAsyncHandler.Factory 很类似
|
//生成规则与SncpAsyncHandler.Factory 很类似
|
||||||
//-------------------------------------------------------------
|
//-------------------------------------------------------------
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void thenEvent(Servlet servlet) {
|
protected void thenEvent(Servlet servlet) {
|
||||||
this.servlet = servlet;
|
this.servlet = servlet;
|
||||||
}
|
}
|
||||||
@@ -248,6 +249,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*
|
*
|
||||||
* @return AsyncHandler AsyncHandler
|
* @return AsyncHandler AsyncHandler
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <H extends AsyncHandler> H createAsyncHandler(Class<H> handlerClass) {
|
public <H extends AsyncHandler> H createAsyncHandler(Class<H> handlerClass) {
|
||||||
if (handlerClass == null || handlerClass == AsyncHandler.class) return (H) createAsyncHandler();
|
if (handlerClass == null || handlerClass == AsyncHandler.class) return (H) createAsyncHandler();
|
||||||
return context.loadAsyncHandlerCreator(handlerClass).create(createAsyncHandler());
|
return context.loadAsyncHandlerCreator(handlerClass).create(createAsyncHandler());
|
||||||
@@ -264,6 +266,18 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
finish(request.getJsonConvert().convertTo(context.getBufferSupplier(), obj));
|
finish(request.getJsonConvert().convertTo(context.getBufferSupplier(), obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象数组用Map的形式以JSON格式输出 <br>
|
||||||
|
* 例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||||
|
*
|
||||||
|
* @param objs 输出对象
|
||||||
|
*/
|
||||||
|
public void finishMapJson(final Object... objs) {
|
||||||
|
this.contentType = "text/plain; charset=utf-8";
|
||||||
|
if (this.recycleListener != null) this.output = objs;
|
||||||
|
finish(request.getJsonConvert().convertMapTo(context.getBufferSupplier(), objs));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将对象以JSON格式输出
|
* 将对象以JSON格式输出
|
||||||
*
|
*
|
||||||
@@ -276,6 +290,19 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
finish(convert.convertTo(context.getBufferSupplier(), obj));
|
finish(convert.convertTo(context.getBufferSupplier(), obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象数组用Map的形式以JSON格式输出 <br>
|
||||||
|
* 例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||||
|
*
|
||||||
|
* @param convert 指定的JsonConvert
|
||||||
|
* @param objs 输出对象
|
||||||
|
*/
|
||||||
|
public void finishMapJson(final JsonConvert convert, final Object... objs) {
|
||||||
|
this.contentType = "text/plain; charset=utf-8";
|
||||||
|
if (this.recycleListener != null) this.output = objs;
|
||||||
|
finish(convert.convertMapTo(context.getBufferSupplier(), objs));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将对象以JSON格式输出
|
* 将对象以JSON格式输出
|
||||||
*
|
*
|
||||||
@@ -358,6 +385,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
* @param convert 指定的JsonConvert
|
* @param convert 指定的JsonConvert
|
||||||
* @param future 输出对象的句柄
|
* @param future 输出对象的句柄
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void finishJson(final JsonConvert convert, final CompletableFuture future) {
|
public void finishJson(final JsonConvert convert, final CompletableFuture future) {
|
||||||
future.whenComplete((v, e) -> {
|
future.whenComplete((v, e) -> {
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
@@ -382,6 +410,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
* @param type 指定的类型
|
* @param type 指定的类型
|
||||||
* @param future 输出对象的句柄
|
* @param future 输出对象的句柄
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void finishJson(final JsonConvert convert, final Type type, final CompletableFuture future) {
|
public void finishJson(final JsonConvert convert, final Type type, final CompletableFuture future) {
|
||||||
future.whenComplete((v, e) -> {
|
future.whenComplete((v, e) -> {
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
@@ -416,6 +445,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
* @param convert 指定的JsonConvert
|
* @param convert 指定的JsonConvert
|
||||||
* @param result HttpResult对象
|
* @param result HttpResult对象
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void finishJson(final JsonConvert convert, final HttpResult result) {
|
public void finishJson(final JsonConvert convert, final HttpResult result) {
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
finish("");
|
finish("");
|
||||||
@@ -996,54 +1026,59 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
|
|
||||||
private long count;//读取文件的字节数
|
private long count;//读取文件的字节数
|
||||||
|
|
||||||
private long position = 0;
|
private long readpos = 0;
|
||||||
|
|
||||||
private boolean next = false;
|
private boolean hdwrite = true; //写入Header
|
||||||
|
|
||||||
private boolean read = true;
|
private boolean read = false;
|
||||||
|
|
||||||
public TransferFileHandler(File file) throws IOException {
|
public TransferFileHandler(File file) throws IOException {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.filechannel = AsynchronousFileChannel.open(file.toPath(), options, ((HttpContext) context).getExecutor());
|
this.filechannel = AsynchronousFileChannel.open(file.toPath(), options, ((HttpContext) context).getExecutor());
|
||||||
this.position = 0;
|
this.readpos = 0;
|
||||||
this.max = file.length();
|
this.max = file.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransferFileHandler(File file, long offset, long len) throws IOException {
|
public TransferFileHandler(File file, long offset, long len) throws IOException {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.filechannel = AsynchronousFileChannel.open(file.toPath(), options, ((HttpContext) context).getExecutor());
|
this.filechannel = AsynchronousFileChannel.open(file.toPath(), options, ((HttpContext) context).getExecutor());
|
||||||
this.position = offset <= 0 ? 0 : offset;
|
this.readpos = offset <= 0 ? 0 : offset;
|
||||||
this.max = len <= 0 ? file.length() : len;
|
this.max = len <= 0 ? file.length() : len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void completed(Integer result, ByteBuffer attachment) {
|
public void completed(Integer result, ByteBuffer attachment) {
|
||||||
//(Thread.currentThread().getName() + "-----------" + file + "-------------------result: " + result + ", max = " + max + ", count = " + count);
|
//(Utility.now() + "---" + Thread.currentThread().getName() + "-----------" + file + "-------------------result: " + result + ", max = " + max + ", readpos = " + readpos + ", count = " + count + ", " + (hdwrite ? "正在写Header" : (read ? "准备读" : "准备写")));
|
||||||
if (result < 0 || count >= max) {
|
if (result < 0 || count >= max) {
|
||||||
failed(null, attachment);
|
failed(null, attachment);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!next && attachment.hasRemaining()) { //Header还没写完
|
if (hdwrite && attachment.hasRemaining()) { //Header还没写完
|
||||||
|
channel.write(attachment, attachment, this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (hdwrite) {
|
||||||
|
//(Utility.now() + "---" + Thread.currentThread().getName() + "-----------" + file + "-------------------Header写入完毕, 准备读取文件.");
|
||||||
|
hdwrite = false;
|
||||||
|
read = true;
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
if (read) {
|
||||||
|
count += result;
|
||||||
|
} else {
|
||||||
|
readpos += result;
|
||||||
|
}
|
||||||
|
if (read && attachment.hasRemaining()) { //Buffer还没写完
|
||||||
channel.write(attachment, attachment, this);
|
channel.write(attachment, attachment, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next && read && attachment.hasRemaining()) { //Buffer还没写完
|
|
||||||
channel.write(attachment, attachment, this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (read) {
|
if (read) {
|
||||||
read = false;
|
read = false;
|
||||||
if (next) {
|
|
||||||
position += result;
|
|
||||||
} else {
|
|
||||||
next = true;
|
|
||||||
}
|
|
||||||
attachment.clear();
|
attachment.clear();
|
||||||
filechannel.read(attachment, position, attachment, this);
|
filechannel.read(attachment, readpos, attachment, this);
|
||||||
} else {
|
} else {
|
||||||
read = true;
|
read = true;
|
||||||
count += result;
|
|
||||||
if (count > max) {
|
if (count > max) {
|
||||||
attachment.limit((int) (attachment.position() + max - count));
|
attachment.limit((int) (attachment.position() + max - count));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
*
|
*
|
||||||
* @return RestServlet
|
* @return RestServlet
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <S extends Service, T extends HttpServlet> T addRestServlet(final ClassLoader classLoader, final String name, final S service, final Class userType, final Class<T> baseServletType, final String prefix) {
|
public <S extends Service, T extends HttpServlet> T addRestServlet(final ClassLoader classLoader, final String name, final S service, final Class userType, final Class<T> baseServletType, final String prefix) {
|
||||||
T servlet = null;
|
T servlet = null;
|
||||||
final boolean sncp = Sncp.isSncpDyn(service);
|
final boolean sncp = Sncp.isSncpDyn(service);
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
void preInit(HttpContext context, AnyValue config) {
|
void preInit(HttpContext context, AnyValue config) {
|
||||||
String path = _prefix == null ? "" : _prefix;
|
String path = _prefix == null ? "" : _prefix;
|
||||||
WebServlet ws = this.getClass().getAnnotation(WebServlet.class);
|
WebServlet ws = this.getClass().getAnnotation(WebServlet.class);
|
||||||
|
|||||||
@@ -92,7 +92,16 @@ public final class Rest {
|
|||||||
return new MethodVisitor(Opcodes.ASM5) {
|
return new MethodVisitor(Opcodes.ASM5) {
|
||||||
@Override
|
@Override
|
||||||
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
||||||
if (index > 0) fieldnames.add(name);
|
if (index < 1) return;
|
||||||
|
int size = fieldnames.size();
|
||||||
|
//index并不会按顺序执行的
|
||||||
|
if (index > size) {
|
||||||
|
for (int i = size; i < index; i++) {
|
||||||
|
fieldnames.add(" ");
|
||||||
|
}
|
||||||
|
fieldnames.set(index - 1, name);
|
||||||
|
}
|
||||||
|
fieldnames.set(index - 1, name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public final class WebSocketPacket {
|
|||||||
ByteBuffer[] duplicateSendBuffers() {
|
ByteBuffer[] duplicateSendBuffers() {
|
||||||
ByteBuffer[] rs = new ByteBuffer[this.sendBuffers.length];
|
ByteBuffer[] rs = new ByteBuffer[this.sendBuffers.length];
|
||||||
for (int i = 0; i < this.sendBuffers.length; i++) {
|
for (int i = 0; i < this.sendBuffers.length; i++) {
|
||||||
rs[i] = this.sendBuffers[i].duplicate().asReadOnlyBuffer();
|
rs[i] = this.sendBuffers[i].duplicate().asReadOnlyBuffer(); //必须使用asReadOnlyBuffer, 否则会导致ByteBuffer对应的byte[]被ObjectPool回收两次
|
||||||
}
|
}
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public final class DataSources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, Properties> loadPersistenceXml(final InputStream in0) {
|
public static Map<String, Properties> loadPersistenceXml(final InputStream in0) {
|
||||||
final Map<String, Properties> map = new LinkedHashMap();
|
final Map<String, Properties> map = new LinkedHashMap();
|
||||||
Properties result = new Properties();
|
Properties result = new Properties();
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||||||
* @param <T> 字段依附的类
|
* @param <T> 字段依附的类
|
||||||
* @param <F> 字段的数据类型
|
* @param <F> 字段的数据类型
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public interface Attribute<T, F> {
|
public interface Attribute<T, F> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public interface Creator<T> {
|
|||||||
|
|
||||||
String[] value();
|
String[] value();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static class CreatorInner {
|
static class CreatorInner {
|
||||||
|
|
||||||
static class SimpleClassVisitor extends ClassVisitor {
|
static class SimpleClassVisitor extends ClassVisitor {
|
||||||
@@ -108,7 +109,16 @@ public interface Creator<T> {
|
|||||||
return new MethodVisitor(Opcodes.ASM5) {
|
return new MethodVisitor(Opcodes.ASM5) {
|
||||||
@Override
|
@Override
|
||||||
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
||||||
if (index > 0) fieldnames.add(name);
|
if (index < 1) return;
|
||||||
|
int size = fieldnames.size();
|
||||||
|
//index不会按顺序执行的
|
||||||
|
if (index > size) {
|
||||||
|
for (int i = size; i < index; i++) {
|
||||||
|
fieldnames.add(" ");
|
||||||
|
}
|
||||||
|
fieldnames.set(index - 1, name);
|
||||||
|
}
|
||||||
|
fieldnames.set(index - 1, name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public final class Redkale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getDotedVersion() {
|
public static String getDotedVersion() {
|
||||||
return "1.8.2";
|
return "1.8.3";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMajorVersion() {
|
public static int getMajorVersion() {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.lang.ref.WeakReference;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@@ -471,11 +471,11 @@ public final class ResourceFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <A> List<A> query(Class<? extends A> clazz) {
|
public <A> List<A> query(Class<? extends A> clazz) {
|
||||||
return query(new ArrayList<A>(), clazz);
|
return query(new ArrayList<>(), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <A> List<A> query(Type clazz) {
|
public <A> List<A> query(Type clazz) {
|
||||||
return query(new ArrayList<A>(), clazz);
|
return query(new ArrayList<>(), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <A> List<A> query(final List<A> list, Type clazz) {
|
private <A> List<A> query(final List<A> list, Type clazz) {
|
||||||
@@ -489,6 +489,23 @@ public final class ResourceFactory {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <A> List<A> query(final BiPredicate<String, Object> predicate) {
|
||||||
|
return query(new ArrayList<>(), predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <A> List<A> query(final List<A> list, final BiPredicate<String, Object> predicate) {
|
||||||
|
if (predicate == null) return list;
|
||||||
|
for (ConcurrentHashMap<String, ResourceEntry> map : this.store.values()) {
|
||||||
|
for (Map.Entry<String, ResourceEntry> en : map.entrySet()) {
|
||||||
|
if (predicate.test(en.getKey(), en.getValue().value)) {
|
||||||
|
list.add((A) en.getValue().value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parent != null) query(list, predicate);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
private <A> ResourceEntry<A> findEntry(String name, Class<? extends A> clazz) {
|
private <A> ResourceEntry<A> findEntry(String name, Class<? extends A> clazz) {
|
||||||
Map<String, ResourceEntry> map = this.store.get(clazz);
|
Map<String, ResourceEntry> map = this.store.get(clazz);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user