This commit is contained in:
Looly 2019-10-17 11:19:59 +08:00
parent 2602f91327
commit 1b3a19f07e
9 changed files with 50 additions and 47 deletions

View File

@ -22,6 +22,7 @@ public interface BitMap{
* 检查是否包含值 * 检查是否包含值
* *
* @param i * @param i
* @return 是否包含
*/ */
boolean contains(long i); boolean contains(long i);
@ -30,5 +31,5 @@ public interface BitMap{
* *
* @param i * @param i
*/ */
public void remove(long i); void remove(long i);
} }

View File

@ -11,7 +11,7 @@ import java.io.Serializable;
public class IntMap implements BitMap, Serializable { public class IntMap implements BitMap, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int[] ints = null; private int[] ints;
/** /**
* 构造 * 构造
@ -40,10 +40,7 @@ public class IntMap implements BitMap, Serializable {
public boolean contains(long i) { public boolean contains(long i) {
int r = (int) (i / BitMap.MACHINE32); int r = (int) (i / BitMap.MACHINE32);
int c = (int) (i % BitMap.MACHINE32); int c = (int) (i % BitMap.MACHINE32);
if (((int) ((ints[r] >>> c)) & 1) == 1) { return ((int) ((ints[r] >>> c)) & 1) == 1;
return true;
}
return false;
} }
@Override @Override

View File

@ -11,7 +11,7 @@ import java.io.Serializable;
public class LongMap implements BitMap, Serializable { public class LongMap implements BitMap, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private long[] longs = null; private long[] longs;
/** /**
* 构造 * 构造
@ -40,10 +40,7 @@ public class LongMap implements BitMap, Serializable {
public boolean contains(long i) { public boolean contains(long i) {
int r = (int) (i / BitMap.MACHINE64); int r = (int) (i / BitMap.MACHINE64);
long c = i % BitMap.MACHINE64; long c = i % BitMap.MACHINE64;
if (((longs[r] >>> c) & 1) == 1) { return ((longs[r] >>> c) & 1) == 1;
return true;
}
return false;
} }
@Override @Override

View File

@ -4,20 +4,20 @@ import cn.hutool.core.util.HashUtil;
/** /**
* 默认Bloom过滤器使用Java自带的Hash算法 * 默认Bloom过滤器使用Java自带的Hash算法
* @author loolly
* *
* @author loolly
*/ */
public class DefaultFilter extends AbstractFilter { public class DefaultFilter extends AbstractFilter {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public DefaultFilter(long maxValue, int MACHINENUM) { public DefaultFilter(long maxValue, int machineNumber) {
super(maxValue, MACHINENUM); super(maxValue, machineNumber);
} }
public DefaultFilter(long maxValue) { public DefaultFilter(long maxValue) {
super(maxValue); super(maxValue);
} }
@Override @Override
public long hash(String str) { public long hash(String str) {
return HashUtil.javaDefaultHash(str) % size; return HashUtil.javaDefaultHash(str) % size;

View File

@ -5,8 +5,8 @@ import cn.hutool.core.util.HashUtil;
public class ELFFilter extends AbstractFilter { public class ELFFilter extends AbstractFilter {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public ELFFilter(long maxValue, int MACHINENUM) { public ELFFilter(long maxValue, int machineNumber) {
super(maxValue, MACHINENUM); super(maxValue, machineNumber);
} }
public ELFFilter(long maxValue) { public ELFFilter(long maxValue) {

View File

@ -64,6 +64,7 @@ public class AioClient implements Closeable{
* @param <T> 选项泛型 * @param <T> 选项泛型
* @param name {@link SocketOption} 枚举 * @param name {@link SocketOption} 枚举
* @param value SocketOption参数 * @param value SocketOption参数
* @return this
* @throws IOException IO异常 * @throws IOException IO异常
*/ */
public <T> AioClient setOption(SocketOption<T> name, T value) throws IOException { public <T> AioClient setOption(SocketOption<T> name, T value) throws IOException {
@ -92,7 +93,8 @@ public class AioClient implements Closeable{
/** /**
* 写数据到服务端 * 写数据到服务端
* *
* @param data 数据
* @return this * @return this
*/ */
public AioClient write(ByteBuffer data) { public AioClient write(ByteBuffer data) {

View File

@ -18,11 +18,10 @@ import cn.hutool.socket.SocketConfig;
/** /**
* 基于AIO的Socket服务端实现 * 基于AIO的Socket服务端实现
*
* @author looly
* *
* @author looly
*/ */
public class AioServer implements Closeable{ public class AioServer implements Closeable {
private static final Log log = LogFactory.get(); private static final Log log = LogFactory.get();
private static AcceptHandler ACCEPT_HANDLER = new AcceptHandler(); private static AcceptHandler ACCEPT_HANDLER = new AcceptHandler();
@ -30,11 +29,11 @@ public class AioServer implements Closeable{
private AsynchronousServerSocketChannel channel; private AsynchronousServerSocketChannel channel;
protected IoAction<ByteBuffer> ioAction; protected IoAction<ByteBuffer> ioAction;
protected SocketConfig config; protected SocketConfig config;
/** /**
* 构造 * 构造
* *
* @param port 端口 * @param port 端口
*/ */
public AioServer(int port) { public AioServer(int port) {
@ -43,9 +42,9 @@ public class AioServer implements Closeable{
/** /**
* 构造 * 构造
* *
* @param address 地址 * @param address 地址
* @param config {@link SocketConfig} 配置项 * @param config {@link SocketConfig} 配置项
*/ */
public AioServer(InetSocketAddress address, SocketConfig config) { public AioServer(InetSocketAddress address, SocketConfig config) {
this.config = config; this.config = config;
@ -54,7 +53,7 @@ public class AioServer implements Closeable{
/** /**
* 初始化 * 初始化
* *
* @param address 地址和端口 * @param address 地址和端口
* @return this * @return this
*/ */
@ -73,7 +72,7 @@ public class AioServer implements Closeable{
/** /**
* 开始监听 * 开始监听
* *
* @param sync 是否阻塞 * @param sync 是否阻塞
*/ */
public void start(boolean sync) { public void start(boolean sync) {
@ -88,9 +87,10 @@ public class AioServer implements Closeable{
* 设置 Socket Option 选项<br> * 设置 Socket Option 选项<br>
* 选项见{@link java.net.StandardSocketOptions} * 选项见{@link java.net.StandardSocketOptions}
* *
* @param <T> 选项泛型 * @param <T> 选项泛型
* @param name {@link SocketOption} 枚举 * @param name {@link SocketOption} 枚举
* @param value SocketOption参数 * @param value SocketOption参数
* @return this
* @throws IOException IO异常 * @throws IOException IO异常
*/ */
public <T> AioServer setOption(SocketOption<T> name, T value) throws IOException { public <T> AioServer setOption(SocketOption<T> name, T value) throws IOException {
@ -100,7 +100,7 @@ public class AioServer implements Closeable{
/** /**
* 获取IO处理器 * 获取IO处理器
* *
* @return {@link IoAction} * @return {@link IoAction}
*/ */
public IoAction<ByteBuffer> getIoAction() { public IoAction<ByteBuffer> getIoAction() {
@ -109,7 +109,7 @@ public class AioServer implements Closeable{
/** /**
* 设置IO处理器单例存在 * 设置IO处理器单例存在
* *
* @param ioAction {@link IoAction} * @param ioAction {@link IoAction}
* @return this; * @return this;
*/ */
@ -120,7 +120,7 @@ public class AioServer implements Closeable{
/** /**
* 获取{@link AsynchronousServerSocketChannel} * 获取{@link AsynchronousServerSocketChannel}
* *
* @return {@link AsynchronousServerSocketChannel} * @return {@link AsynchronousServerSocketChannel}
*/ */
public AsynchronousServerSocketChannel getChannel() { public AsynchronousServerSocketChannel getChannel() {
@ -129,7 +129,7 @@ public class AioServer implements Closeable{
/** /**
* 处理接入的客户端 * 处理接入的客户端
* *
* @return this * @return this
*/ */
public AioServer accept() { public AioServer accept() {
@ -139,7 +139,7 @@ public class AioServer implements Closeable{
/** /**
* 服务是否开启状态 * 服务是否开启状态
* *
* @return 服务是否开启状态 * @return 服务是否开启状态
*/ */
public boolean isOpen() { public boolean isOpen() {
@ -168,9 +168,10 @@ public class AioServer implements Closeable{
} }
// ------------------------------------------------------------------------------------- Private method start // ------------------------------------------------------------------------------------- Private method start
/** /**
* 开始监听 * 开始监听
* *
* @param sync 是否阻塞 * @param sync 是否阻塞
* @throws IOException IO异常 * @throws IOException IO异常
*/ */

View File

@ -118,7 +118,8 @@ public class AioSession implements Closeable{
/** /**
* 写数据到目标端并关闭输出 * 写数据到目标端并关闭输出
* *
* @param data 数据
* @return this * @return this
*/ */
public AioSession writeAndClose(ByteBuffer data) { public AioSession writeAndClose(ByteBuffer data) {
@ -128,7 +129,8 @@ public class AioSession implements Closeable{
/** /**
* 写数据到目标端 * 写数据到目标端
* *
* @param data 数据
* @return {@link Future} * @return {@link Future}
*/ */
public Future<Integer> write(ByteBuffer data) { public Future<Integer> write(ByteBuffer data) {
@ -137,7 +139,8 @@ public class AioSession implements Closeable{
/** /**
* 写数据到目标端 * 写数据到目标端
* *
* @param data 数据
* @param handler {@link CompletionHandler} * @param handler {@link CompletionHandler}
* @return this * @return this
*/ */

View File

@ -11,17 +11,17 @@ import cn.hutool.core.io.IoUtil;
/** /**
* NIO客户端 * NIO客户端
* *
* @author looly * @author looly
* @since 4.4.5 * @since 4.4.5
*/ */
public class NioClient implements Closeable{ public class NioClient implements Closeable {
private SocketChannel channel; private SocketChannel channel;
/** /**
* 构造 * 构造
* *
* @param host 服务器地址 * @param host 服务器地址
* @param port 端口 * @param port 端口
*/ */
@ -31,7 +31,7 @@ public class NioClient implements Closeable{
/** /**
* 构造 * 构造
* *
* @param address 服务器地址 * @param address 服务器地址
*/ */
public NioClient(InetSocketAddress address) { public NioClient(InetSocketAddress address) {
@ -40,7 +40,7 @@ public class NioClient implements Closeable{
/** /**
* 初始化 * 初始化
* *
* @param address 地址和端口 * @param address 地址和端口
* @return this * @return this
*/ */
@ -56,8 +56,9 @@ public class NioClient implements Closeable{
/** /**
* 处理读事件<br> * 处理读事件<br>
* 当收到读取准备就绪的信号后回调此方法用户可读取从客户端传世来的消息 * 当收到读取准备就绪的信号后回调此方法用户可读取从客户端传世来的消息
* *
* @param buffer 服务端数据存储缓存 * @param buffer 服务端数据存储缓存
* @return this
*/ */
public NioClient read(ByteBuffer buffer) { public NioClient read(ByteBuffer buffer) {
try { try {
@ -71,8 +72,9 @@ public class NioClient implements Closeable{
/** /**
* 实现写逻辑<br> * 实现写逻辑<br>
* 当收到写出准备就绪的信号后回调此方法用户可向客户端发送消息 * 当收到写出准备就绪的信号后回调此方法用户可向客户端发送消息
* *
* @param datas 发送的数据 * @param datas 发送的数据
* @return this
*/ */
public NioClient write(ByteBuffer... datas) { public NioClient write(ByteBuffer... datas) {
try { try {