-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588e6dc
commit f95e637
Showing
5 changed files
with
152 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"log/slog" | ||
"os" | ||
"time" | ||
) | ||
|
||
func init() { | ||
|
||
// log 日志记录器 | ||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
AddSource: true, | ||
Level: slog.LevelDebug, | ||
}))) | ||
} | ||
|
||
func main() { | ||
file, err := os.Open("C:\\Users\\KevinBlandy\\Desktop\\adsense.txt") | ||
if err != nil { | ||
slog.Error("err", slog.String("err", err.Error())) | ||
return | ||
} | ||
|
||
// 指针 | ||
var position int64 = 0 | ||
|
||
for { | ||
_, err := file.Seek(position, io.SeekStart) | ||
if err != nil { | ||
slog.Error("seek err", slog.String("err", err.Error())) | ||
return | ||
} | ||
|
||
scanner := bufio.NewScanner(file) | ||
scanner.Split(bufio.ScanLines) | ||
|
||
for scanner.Scan() { | ||
if err := scanner.Err(); err != nil { | ||
slog.Error("scan err", slog.String("err", err.Error())) | ||
return | ||
} | ||
line := scanner.Text() | ||
slog.Debug(line) | ||
} | ||
|
||
// 获取到文件指针位置 | ||
count, err := file.Seek(0, io.SeekCurrent) | ||
if err != nil { | ||
slog.Error("seek err", slog.String("err", err.Error())) | ||
return | ||
} | ||
|
||
// 更新指针 | ||
position = count | ||
|
||
time.Sleep(time.Millisecond * 10) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
------------------------ | ||
密封类 | ||
------------------------ | ||
# JDK 17 后新增的三个关键字 | ||
sealed:(封闭)用于修饰类/接口,代表这个类/接口为密封类/接口; | ||
non-sealed:(非封闭)用于修饰类/接口,代表这个类/接口为非密封类/接口; | ||
permits:(允许)用于 extends 和 implements 之后,指定能够继承或实现封闭类的子类/接口; | ||
|
||
|
||
# 总结 | ||
1. sealed 声明类/接口是一个密封类 | ||
2. non-sealed 声明类/接口是一个非密封类 | ||
|
||
2. permits 如果是密封类,那么设置允许继承、实现当前类的类 | ||
* 如果当前类是 sealed 密封类,直接子类也必须要声明当前类是 sealed 还是 non-sealed | ||
|
||
|
||
public sealed interface Foo permits Bar, Zoo{} | ||
// sealed 密封类 | ||
// permits Bar 和 Zoo 可以实现此接口 | ||
|
||
public non-sealed class Bar implements Foo {} | ||
// non-sealed 非密封类 | ||
|
||
public sealed class Zoo implements Foo permits Qoo {} | ||
// sealed 密封类 | ||
// permits Qoo 可以实现此接口 | ||
|
||
public non-sealed class Qoo extends Zoo {} | ||
// non-sealed 非密封类 | ||
|
||
public class Koo extends Bar{} | ||
// 继承 非密封类 Bar,不需要声明 sealed 或者是 non-sealed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
----------------- | ||
普通集群 | ||
----------------- | ||
# 队列分布在集群中的任意节点。但是每个节点都同步 queue 的元数据。 | ||
# 消费队列的时候,如果连接到了“非队列所在节点”,那么当前连接节点会从“队列所在节点” 拉取数据。 | ||
# 基本上就是说,队列都完整放到某个节点上的。节点宕机,队列费不了了。 | ||
|
||
----------------- | ||
镜像集群 | ||
----------------- | ||
# 高可用模式 | ||
# 队列会在多个节点上有“复制节点”,每个节点都包含了完整的数据。 | ||
# 写入消息的时候,会把数据同步到其他节点。 | ||
|
||
|