This commit is contained in:
Redkale
2018-03-12 21:41:36 +08:00
parent 3a13d242f6
commit e223548b23
20 changed files with 76 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ public class MethodDebugVisitor {
System.out.println();
}
private final Map<Label, Integer> labels = new LinkedHashMap();
private final Map<Label, Integer> labels = new LinkedHashMap<>();
private static final String[] opcodes = new String[200]; //0 -18

View File

@@ -502,6 +502,7 @@ public final class Application {
if (listenClass.isEmpty()) continue;
Class clazz = classLoader.loadClass(listenClass);
if (!ApplicationListener.class.isAssignableFrom(clazz)) continue;
@SuppressWarnings("unchecked")
ApplicationListener listener = (ApplicationListener) clazz.getDeclaredConstructor().newInstance();
listener.init(config);
this.listeners.add(listener);

View File

@@ -56,16 +56,19 @@ public class NodeHttpServer extends NodeServer {
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Service> createServiceClassFilter() {
return createClassFilter(this.sncpGroup, null, Service.class, new Class[]{org.redkale.watch.WatchService.class}, Annotation.class, "services", "service");
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Filter> createFilterClassFilter() {
return createClassFilter(null, null, HttpFilter.class, new Class[]{WatchFilter.class}, null, "filters", "filter");
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Servlet> createServletClassFilter() {
return createClassFilter(null, WebServlet.class, HttpServlet.class, new Class[]{WatchServlet.class}, null, "servlets", "servlet");
}
@@ -87,6 +90,7 @@ public class NodeHttpServer extends NodeServer {
}
@Override
@SuppressWarnings("unchecked")
protected void loadServlet(ClassFilter<? extends Servlet> servletFilter, ClassFilter otherFilter) throws Exception {
if (httpServer != null) loadHttpServlet(servletFilter, otherFilter);
}

View File

@@ -24,16 +24,19 @@ public class NodeWatchServer extends NodeHttpServer {
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Service> createServiceClassFilter() {
return createClassFilter(this.sncpGroup, null, WatchService.class, null, Annotation.class, "services", "service");
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Filter> createFilterClassFilter() {
return createClassFilter(null, null, WatchFilter.class, null, null, "filters", "filter");
}
@Override
@SuppressWarnings("unchecked")
protected ClassFilter<Servlet> createServletClassFilter() {
return createClassFilter(null, WebServlet.class, WatchServlet.class, null, null, "servlets", "servlet");
}

View File

@@ -34,6 +34,7 @@ public class OptionalCoder<R extends Reader, W extends Writer, T> extends Simple
private final Object lock = new Object();
@SuppressWarnings("unchecked")
public OptionalCoder(final ConvertFactory factory, final Type type) {
this.type = type;
try {

View File

@@ -25,6 +25,7 @@ public final class BigIntegerSimpledCoder<R extends Reader, W extends Writer> ex
public static final BigIntegerSimpledCoder instance = new BigIntegerSimpledCoder();
@Override
@SuppressWarnings("unchecked")
public void convertTo(W out, BigInteger value) {
if (value == null) {
out.writeNull();
@@ -34,6 +35,7 @@ public final class BigIntegerSimpledCoder<R extends Reader, W extends Writer> ex
}
@Override
@SuppressWarnings("unchecked")
public BigInteger convertFrom(R in) {
byte[] bytes = ByteArraySimpledCoder.instance.convertFrom(in);
return bytes == null ? null : new BigInteger(bytes);

View File

@@ -27,6 +27,7 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
public static final DLongSimpledCoder instance = new DLongSimpledCoder();
@Override
@SuppressWarnings("unchecked")
public void convertTo(final W out, final DLong value) {
if (value == null) {
out.writeNull();
@@ -36,6 +37,7 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
}
@Override
@SuppressWarnings("unchecked")
public DLong convertFrom(R in) {
byte[] bs = bsSimpledCoder.convertFrom(in);
if (bs == null) return null;

View File

@@ -74,6 +74,7 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
public static final DoubleStreamSimpledCoder instance = new DoubleStreamSimpledCoder();
@Override
@SuppressWarnings("unchecked")
public void convertTo(W out, DoubleStream values) {
if (values == null) {
out.writeNull();
@@ -83,6 +84,7 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
}
@Override
@SuppressWarnings("unchecked")
public DoubleStream convertFrom(R in) {
double[] value = DoubleArraySimpledCoder.instance.convertFrom(in);
return value == null ? null : DoubleStream.of(value);

View File

@@ -74,6 +74,7 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
public static final IntStreamSimpledCoder instance = new IntStreamSimpledCoder();
@Override
@SuppressWarnings("unchecked")
public void convertTo(W out, IntStream values) {
if (values == null) {
out.writeNull();
@@ -83,6 +84,7 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
}
@Override
@SuppressWarnings("unchecked")
public IntStream convertFrom(R in) {
int[] value = IntArraySimpledCoder.instance.convertFrom(in);
return value == null ? null : IntStream.of(value);

View File

@@ -74,6 +74,7 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
public static final LongStreamSimpledCoder instance = new LongStreamSimpledCoder();
@Override
@SuppressWarnings("unchecked")
public void convertTo(W out, LongStream values) {
if (values == null) {
out.writeNull();
@@ -83,6 +84,7 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
}
@Override
@SuppressWarnings("unchecked")
public LongStream convertFrom(R in) {
long[] value = LongArraySimpledCoder.instance.convertFrom(in);
return value == null ? null : LongStream.of(value);

View File

@@ -170,7 +170,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
*/
public static CompletableFuture<AsyncConnection> createTCP(final AsynchronousChannelGroup group, final SSLContext sslContext,
final SocketAddress address, final boolean noDelay, final int readTimeoutSecond, final int writeTimeoutSecond) {
final CompletableFuture future = new CompletableFuture();
final CompletableFuture<AsyncConnection> future = new CompletableFuture<>();
try {
final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);
channel.connect(address, null, new CompletionHandler<Void, Void>() {

View File

@@ -0,0 +1,26 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.net;
import java.io.IOException;
import javax.net.ssl.SSLContext;
import org.redkale.util.*;
/**
* 根据配置生成SSLContext
*
* <p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
public interface SSLCreator {
default SSLContext create(Server server, AnyValue sslConf) throws IOException {
return null;
}
}

View File

@@ -124,6 +124,19 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
this.responsePoolSize = config.getIntValue("responsePoolSize", this.threads * 2);
this.name = config.getValue("name", "Server-" + protocol + "-" + this.address.getPort());
if (!this.name.matches("^[a-zA-Z][\\w_-]{1,64}$")) throw new RuntimeException("server.name (" + this.name + ") is illegal");
AnyValue sslConf = config.getAnyValue("ssl");
if (sslConf != null) {
String creatorClass = sslConf.getValue("creator", SSLCreator.class.getName());
if (SSLCreator.class.getName().equals(creatorClass) || creatorClass.isEmpty()) {
this.sslContext = new SSLCreator() {
}.create(this, sslConf);
} else {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
@SuppressWarnings("unchecked")
SSLCreator creator = ((SSLCreator) classLoader.loadClass(creatorClass).getDeclaredConstructor().newInstance());
this.sslContext = creator.create(this, sslConf);
}
}
final AtomicInteger counter = new AtomicInteger();
final Format f = createFormat();
final String n = name;

View File

@@ -126,7 +126,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
List<HttpServlet> list = removeHttpServlet(predicateEntry, predicateFilter);
return list == null || list.isEmpty() ? null : list.get(0);
}
@SuppressWarnings("unchecked")
public <T extends WebSocket> HttpServlet removeHttpServlet(Class<T> websocketOrServletType) {
Predicate<MappingEntry> predicateEntry = (t) -> {
Class type = t.servlet.getClass();
@@ -144,6 +144,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
return list == null || list.isEmpty() ? null : list.get(0);
}
@SuppressWarnings("unchecked")
public boolean addForbidURIReg(final String urlreg) {
if (urlreg == null || urlreg.isEmpty()) return false;
synchronized (excludeLock) {
@@ -169,6 +170,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
}
}
@SuppressWarnings("unchecked")
public boolean removeForbidURIReg(final String urlreg) {
if (urlreg == null || urlreg.isEmpty()) return false;
synchronized (excludeLock) {
@@ -198,6 +200,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
}
@Override
@SuppressWarnings("unchecked")
public void init(HttpContext context, AnyValue config) {
super.init(context, config); //必须要执行
Collection<HttpServlet> servlets = getServlets();

View File

@@ -59,10 +59,12 @@ public class HttpScope {
return this;
}
@SuppressWarnings("unchecked")
public <T> T find(String name) {
return this.attributes == null ? null : (T) this.attributes.get(name);
}
@SuppressWarnings("unchecked")
public <T> T find(HttpScope parent, String name) {
T rs = this.attributes == null ? null : (T) this.attributes.get(name);
if (rs != null) return rs;

View File

@@ -294,7 +294,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
HttpMapping mapping = method.getAnnotation(HttpMapping.class);
this.ignore = mapping == null || !mapping.auth();
this.cacheseconds = mapping == null ? 0 : mapping.cacheseconds();
this.cache = cacheseconds > 0 ? new ConcurrentHashMap() : null;
this.cache = cacheseconds > 0 ? new ConcurrentHashMap<>() : null;
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, ByteBuffer[] buffers) -> {
int status = response.getStatus();
if (status != 200) return null;

View File

@@ -441,6 +441,7 @@ public final class SncpClient {
}
}
@SuppressWarnings("unchecked")
public void success() {
future.complete(this.body);
transport.offerBuffer(buffer);
@@ -547,6 +548,7 @@ public final class SncpClient {
protected final Creator<? extends CompletableFuture> futureCreator;
@SuppressWarnings("unchecked")
public SncpAction(final Class clazz, Method method, DLong actionid) {
this.actionid = actionid == null ? Sncp.hash(method) : actionid;
Type rt = TypeToken.getGenericType(method.getGenericReturnType(), clazz);

View File

@@ -105,6 +105,7 @@ public final class SncpDynServlet extends SncpServlet {
}
@Override
@SuppressWarnings("unchecked")
public void execute(SncpRequest request, SncpResponse response) throws IOException {
if (bufferSupplier == null) {
bufferSupplier = request.getContext().getBufferSupplier();

View File

@@ -27,6 +27,7 @@ import org.redkale.util.*;
*
* @author zhangjx
*/
@SuppressWarnings("unchecked")
@Local
@AutoLoad(false)
@ResourceType(CacheSource.class)
@@ -85,6 +86,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
}
@Override
@SuppressWarnings("unchecked")
public void init(AnyValue conf) {
if (this.convert == null) this.convert = this.defaultConvert;
if (this.convert == null) this.convert = JsonConvert.root();
@@ -320,6 +322,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
}
@Override
@SuppressWarnings("unchecked")
public V get(String key) {
if (key == null) return null;
CacheEntry entry = container.get(key);
@@ -362,6 +365,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
@Override
@RpcMultiRun
@SuppressWarnings("unchecked")
public V getAndRefresh(String key, final int expireSeconds) {
if (key == null) return null;
CacheEntry entry = container.get(key);
@@ -375,6 +379,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
@Override
@RpcMultiRun
@SuppressWarnings("unchecked")
public String getStringAndRefresh(String key, final int expireSeconds) {
if (key == null) return null;
CacheEntry entry = container.get(key);

View File

@@ -18,6 +18,7 @@ import org.redkale.util.*;
* @param <T> Entity类的类型
* @param <F> 字段的类型
*/
@SuppressWarnings("unchecked")
public final class DataCallArrayAttribute<T, F> implements Attribute<T[], F> {
public static final DataCallArrayAttribute instance = new DataCallArrayAttribute();