Skip to content

Commit

Permalink
Merge branch 'master' into mongodb_2
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava authored Apr 19, 2024
2 parents 145a8bf + 408d8ec commit 049a8c3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 45 deletions.
1 change: 1 addition & 0 deletions jcommon/ai/aws/src/main/java/run/mone/ModelEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum ModelEnum {
Opus("anthropic.claude-3-opus-20240229-v1:0");



public String modelName;

ModelEnum(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,57 @@ public void reg(String path, Predicate<String> predicate) throws IOException, In
WatchService watchService = FileSystems.getDefault().newWatchService();
directory.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_CREATE);
while (true) {
WatchKey key = watchService.take();
for (WatchEvent<?> event : key.pollEvents()) {
Path modifiedFile = (Path) event.context();
String filePath = String.format("%s%s", path, modifiedFile.getFileName().toString());
if (!predicate.test(filePath) || modifiedFile.getFileName().toString().startsWith(".")) {
continue;
}
HeraFile hfile = fileMap.get(filePath);

if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
if (null == hfile) {
hfile = initFile(new File(filePath));
}
modify(hfile);
}

if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
fileMap.remove(filePath);
if (null != hfile) {
map.remove(hfile.getFileKey());
listener.onEvent(FileEvent.builder().type(EventType.delete).fileName(filePath).fileKey(hfile.getFileKey()).build());
}
}

if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
File file = new File(filePath);
Object k = FileUtils.fileKey(file);

if (map.containsKey(k)) {
log.info("change name " + map.get(k) + "--->" + file);
listener.onEvent(FileEvent.builder().fileKey(k).type(EventType.rename).build());
} else {
log.info("ENTRY_CREATE filePath:{},fileKey:{}", filePath, k);
HeraFile hf = HeraFile.builder().file(file).fileKey(k).fileName(filePath).build();
map.putIfAbsent(k, hf);
fileMap.put(filePath, hf);

listener.onEvent(FileEvent.builder().type(EventType.create).fileName(file.getPath()).build());
try {
WatchKey key = watchService.take();
try {
for (WatchEvent<?> event : key.pollEvents()) {
Path modifiedFile = (Path) event.context();
String filePath = String.format("%s%s", path, modifiedFile.getFileName().toString());
if (!predicate.test(filePath) || modifiedFile.getFileName().toString().startsWith(".")) {
continue;
}
HeraFile hfile = fileMap.get(filePath);

if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
if (null == hfile) {
hfile = initFile(new File(filePath));
}
modify(hfile);
}

if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
fileMap.remove(filePath);
if (null != hfile) {
map.remove(hfile.getFileKey());
listener.onEvent(FileEvent.builder().type(EventType.delete).fileName(filePath).fileKey(hfile.getFileKey()).build());
}
}

if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
File file = new File(filePath);
Object k = FileUtils.fileKey(file);

if (map.containsKey(k)) {
log.info("change name " + map.get(k) + "--->" + file);
listener.onEvent(FileEvent.builder().fileKey(k).type(EventType.rename).build());
} else {
log.info("ENTRY_CREATE filePath:{},fileKey:{}", filePath, k);
HeraFile hf = HeraFile.builder().file(file).fileKey(k).fileName(filePath).build();
map.putIfAbsent(k, hf);
fileMap.put(filePath, hf);

listener.onEvent(FileEvent.builder().type(EventType.create).fileName(file.getPath()).build());
}
}
}
} catch (Exception e1) {
log.error("watchService poll events error", e1);
} finally {
key.reset();
}
} catch (Exception e) {
log.error("watchService error", e);
}
key.reset();
}
}

Expand Down Expand Up @@ -165,11 +174,13 @@ private HeraFile initFile(File it) {


private void modify(HeraFile hfile) {
hfile.getUtime().set(System.currentTimeMillis());
if (hfile.getFile().length() == 0) {
listener.onEvent(FileEvent.builder().type(EventType.empty).fileName(hfile.getFileName()).fileKey(hfile.getFileKey()).build());
} else {
listener.onEvent(FileEvent.builder().type(EventType.modify).build());
if (null != hfile) {
hfile.getUtime().set(System.currentTimeMillis());
if (hfile.getFile().length() == 0) {
listener.onEvent(FileEvent.builder().type(EventType.empty).fileName(hfile.getFileName()).fileKey(hfile.getFileKey()).build());
} else {
listener.onEvent(FileEvent.builder().type(EventType.modify).build());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testLogFileMonitor() {

@Test
public void testLogWS() throws IOException {
LogFileWS log = new LogFileWS("D:\\t", new ReadListener() {
LogFile log = new LogFile("D:\\test.log", new ReadListener() {
@Override
public void onEvent(ReadEvent event) {
System.out.println(event.getReadResult().getLines());
Expand Down Expand Up @@ -132,4 +132,5 @@ public void testReadFileCutting() throws IOException {
log.readLine();
System.in.read();
}

}

0 comments on commit 049a8c3

Please sign in to comment.