@@ -45,18 +45,36 @@ public void run() {
45
45
Notification obj = queue .take ();
46
46
if (obj instanceof UpdateNotification ) {
47
47
UpdateNotification notification = (UpdateNotification ) obj ;
48
- this .handler .onUpdate (
49
- (ApiType ) notification .getOldObj (), (ApiType ) notification .getNewObj ());
48
+ try {
49
+ this .handler .onUpdate (
50
+ (ApiType ) notification .getOldObj (), (ApiType ) notification .getNewObj ());
51
+ } catch (Throwable t ) {
52
+ // Catch all exceptions here so that listeners won't quit unexpectedly
53
+ log .error ("failed invoking UPDATE event handler: {}" , t .getMessage ());
54
+ continue ;
55
+ }
50
56
} else if (obj instanceof AddNotification ) {
51
57
AddNotification notification = (AddNotification ) obj ;
52
- this .handler .onAdd ((ApiType ) notification .getNewObj ());
58
+ try {
59
+ this .handler .onAdd ((ApiType ) notification .getNewObj ());
60
+ } catch (Throwable t ) {
61
+ // Catch all exceptions here so that listeners won't quit unexpectedly
62
+ log .error ("failed invoking ADD event handler: {}" , t .getMessage ());
63
+ continue ;
64
+ }
53
65
} else if (obj instanceof DeleteNotification ) {
54
66
Object deletedObj = ((DeleteNotification ) obj ).getOldObj ();
55
- if (deletedObj instanceof DeltaFIFO .DeletedFinalStateUnknown ) {
56
- this .handler .onDelete (
57
- ((DeltaFIFO .DeletedFinalStateUnknown <ApiType >) deletedObj ).getObj (), true );
58
- } else {
59
- this .handler .onDelete ((ApiType ) deletedObj , false );
67
+ try {
68
+ if (deletedObj instanceof DeltaFIFO .DeletedFinalStateUnknown ) {
69
+ this .handler .onDelete (
70
+ ((DeltaFIFO .DeletedFinalStateUnknown <ApiType >) deletedObj ).getObj (), true );
71
+ } else {
72
+ this .handler .onDelete ((ApiType ) deletedObj , false );
73
+ }
74
+ } catch (Throwable t ) {
75
+ // Catch all exceptions here so that listeners won't quit unexpectedly
76
+ log .error ("failed invoking DELETE event handler: {}" , t .getMessage ());
77
+ continue ;
60
78
}
61
79
} else {
62
80
throw new BadNotificationException ("unrecognized notification" );
@@ -72,7 +90,9 @@ public void add(Notification<ApiType> obj) {
72
90
if (obj == null ) {
73
91
return ;
74
92
}
75
- this .queue .add (obj );
93
+ if (!this .queue .offer (obj )) {
94
+ log .warn ("notification queue full!" );
95
+ }
76
96
}
77
97
78
98
public void determineNextResync (DateTime now ) {
0 commit comments