@@ -45,18 +45,36 @@ public void run() {
4545 Notification obj = queue .take ();
4646 if (obj instanceof UpdateNotification ) {
4747 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+ }
5056 } else if (obj instanceof AddNotification ) {
5157 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+ }
5365 } else if (obj instanceof DeleteNotification ) {
5466 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 ;
6078 }
6179 } else {
6280 throw new BadNotificationException ("unrecognized notification" );
0 commit comments