mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
updates
This commit is contained in:
parent
3e362451d2
commit
824e96ffcc
|
@ -1,38 +1,42 @@
|
||||||
package com.seaweedfs.examples;
|
package com.seaweedfs.examples;
|
||||||
|
|
||||||
import seaweedfs.client.FilerClient;
|
import seaweedfs.client.FilerClient;
|
||||||
import seaweedfs.client.FilerGrpcClient;
|
|
||||||
import seaweedfs.client.FilerProto;
|
import seaweedfs.client.FilerProto;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class WatchFiles {
|
public class WatchFiles {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
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(
|
Iterator<FilerProto.SubscribeMetadataResponse> watch = filerClient.watch(
|
||||||
"/buckets",
|
"/buckets",
|
||||||
"exampleClient",
|
"exampleClientName",
|
||||||
System.currentTimeMillis() * 1000000L
|
sinceNs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
System.out.println("Connected to filer, subscribing from " + new Date());
|
||||||
|
|
||||||
while (watch.hasNext()) {
|
while (watch.hasNext()) {
|
||||||
FilerProto.SubscribeMetadataResponse event = watch.next();
|
FilerProto.SubscribeMetadataResponse event = watch.next();
|
||||||
FilerProto.EventNotification notification = event.getEventNotification();
|
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
|
// move an entry to a new directory, possibly with a new name
|
||||||
if (notification.hasOldEntry() && notification.hasNewEntry()) {
|
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 {
|
} else {
|
||||||
System.out.println("this should not happen.");
|
System.out.println("this should not happen.");
|
||||||
}
|
}
|
||||||
} else if (notification.hasNewEntry() && !notification.hasOldEntry()) {
|
} 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()) {
|
} 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()) {
|
} else if (notification.hasNewEntry() && notification.hasOldEntry()) {
|
||||||
System.out.println("updated entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
|
System.out.println("updated entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue