aboutsummaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-11-13 12:47:46 -0800
committerChris Lu <chris.lu@gmail.com>2020-11-13 12:47:46 -0800
commit824e96ffcc3903260479b26aa0f27e07fa23a795 (patch)
tree52137e8dd2c0fcb661bc415cdfcc38b52149aa62 /other
parent3e362451d226d9e19b4b652a02926dedc02f6cf9 (diff)
downloadseaweedfs-824e96ffcc3903260479b26aa0f27e07fa23a795.tar.xz
seaweedfs-824e96ffcc3903260479b26aa0f27e07fa23a795.zip
updates
Diffstat (limited to 'other')
-rw-r--r--other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java b/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
index c4f4c81b0..e489cb3b1 100644
--- a/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
+++ b/other/java/examples/src/main/java/com/seaweedfs/examples/WatchFiles.java
@@ -1,38 +1,42 @@
package com.seaweedfs.examples;
import seaweedfs.client.FilerClient;
-import seaweedfs.client.FilerGrpcClient;
import seaweedfs.client.FilerProto;
import java.io.IOException;
+import java.util.Date;
import java.util.Iterator;
public class WatchFiles {
public static void main(String[] args) throws IOException {
- FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888);
- FilerClient filerClient = new FilerClient(filerGrpcClient);
+
+ FilerClient filerClient = new FilerClient("localhost", 18888);
+
+ long sinceNs = (System.currentTimeMillis() - 3600 * 1000) * 1000000L;
Iterator<FilerProto.SubscribeMetadataResponse> watch = filerClient.watch(
"/buckets",
- "exampleClient",
- System.currentTimeMillis() * 1000000L
+ "exampleClientName",
+ sinceNs
);
+ System.out.println("Connected to filer, subscribing from " + new Date());
+
while (watch.hasNext()) {
FilerProto.SubscribeMetadataResponse event = watch.next();
FilerProto.EventNotification notification = event.getEventNotification();
- if (notification.getNewParentPath() != null) {
+ if (!event.getDirectory().equals(notification.getNewParentPath())) {
// move an entry to a new directory, possibly with a new name
if (notification.hasOldEntry() && notification.hasNewEntry()) {
- System.out.println("move " + event.getDirectory() + "/" + notification.getOldEntry().getName() + " to " + notification.getNewParentPath() + "/" + notification.getNewEntry().getName());
+ System.out.println("moved " + event.getDirectory() + "/" + notification.getOldEntry().getName() + " to " + notification.getNewParentPath() + "/" + notification.getNewEntry().getName());
} else {
System.out.println("this should not happen.");
}
} else if (notification.hasNewEntry() && !notification.hasOldEntry()) {
- System.out.println("create entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
+ System.out.println("created entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
} else if (!notification.hasNewEntry() && notification.hasOldEntry()) {
- System.out.println("delete entry " + event.getDirectory() + "/" + notification.getOldEntry().getName());
+ System.out.println("deleted entry " + event.getDirectory() + "/" + notification.getOldEntry().getName());
} else if (notification.hasNewEntry() && notification.hasOldEntry()) {
System.out.println("updated entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
}