snf4j / snf4j
Showing 11 of 24 files from the diff.

@@ -1,7 +1,7 @@
Loading
1 1
/*
2 2
 * -------------------------------- MIT License --------------------------------
3 3
 * 
4 -
 * Copyright (c) 2017-2021 SNF4J contributors
4 +
 * Copyright (c) 2017-2022 SNF4J contributors
5 5
 * 
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
@@ -755,8 +755,8 @@
Loading
755 755
			try {
756 756
				handler.event(event, length);
757 757
			}
758 -
			catch (Exception e) {
759 -
				elogger.error(logger, "Failed event {} for {}: {}", event, this, e);
758 +
			catch (Throwable e) {
759 +
				fireException(SessionIncident.DATA_EVENT_FAILURE, event, e);
760 760
			}
761 761
		}
762 762
	}
@@ -765,8 +765,8 @@
Loading
765 765
		try {
766 766
			handler.timer(event);
767 767
		}
768 -
		catch (Exception e) {
769 -
			elogger.error(logger, "Failed timer event for {}: {}", this, e);
768 +
		catch (Throwable e) {
769 +
			fireException(SessionIncident.TIMER_EVENT_FAILURE, event, e);
770 770
		}
771 771
	}
772 772
	
@@ -774,8 +774,8 @@
Loading
774 774
		try {
775 775
			handler.timer(task);
776 776
		}
777 -
		catch (Exception e) {
778 -
			elogger.error(logger, "Failed timer task for {}: {}", this, e);
777 +
		catch (Throwable e) {
778 +
			fireException(SessionIncident.TIMER_TASK_FAILURE, task, e);
779 779
		}
780 780
	}
781 781
	
@@ -791,8 +791,8 @@
Loading
791 791
				}
792 792
				handler.event(event);
793 793
			}
794 -
			catch (Exception e) {
795 -
				elogger.error(logger, "Failed event {} for {}: {}", event, this, e);
794 +
			catch (Throwable e) {
795 +
				fireException(SessionIncident.SESSION_EVENT_FAILURE, event, e);
796 796
			}
797 797
		}
798 798
	}
@@ -838,20 +838,41 @@
Loading
838 838
					quickClose();
839 839
				}
840 840
			}
841 -
			catch (Exception e) {
841 +
			catch (Throwable e) {
842 842
				elogger.error(logger, "Failed event {} for {}: {}", EventType.EXCEPTION_CAUGHT, this, e);
843 843
				futuresController.exception(t);
844 844
				quickClose();
845 845
			}
846 846
		}
847 847
	}
848 +
849 +
	void fireException(Throwable t) {
850 +
		if (logger.isDebugEnabled()) {
851 +
			logger.debug("Firing event {} for {}", EventType.EXCEPTION_CAUGHT, this);
852 +
		}
853 +
		exception(t);
854 +
		if (logger.isTraceEnabled()) {
855 +
			logger.trace("Ending event {} for {}", EventType.EXCEPTION_CAUGHT, this);
856 +
		}
857 +
	}
858 +
	
859 +
	/** Returns true the exception was triggered */
860 +
	boolean fireException(SessionIncident incident, Object event, Throwable t) {
861 +
		if (!incident(incident, t)) {
862 +
			elogger.error(logger, incident.defaultMessage(), event, this, t);
863 +
			fireException(t);
864 +
			return true;
865 +
		}
866 +
		return false;
867 +
	}
848 868
	
849 869
	boolean incident(SessionIncident incident, Throwable t) {
850 870
		try {
851 871
			return handler.incident(incident, t);
852 872
		}
853 -
		catch (Exception e) {
873 +
		catch (Throwable e) {
854 874
			elogger.error(logger, "Failed incident {} for {}: {}", incident, this, e);
875 +
			exception(e);
855 876
		}
856 877
		return false;
857 878
	}

@@ -40,6 +40,7 @@
Loading
40 40
import org.snf4j.core.handler.DataEvent;
41 41
import org.snf4j.core.handler.IDatagramHandler;
42 42
import org.snf4j.core.handler.SessionEvent;
43 +
import org.snf4j.core.handler.SessionIncident;
43 44
import org.snf4j.core.logger.ILogger;
44 45
import org.snf4j.core.logger.LoggerFactory;
45 46
import org.snf4j.core.session.IDatagramSession;
@@ -126,8 +127,8 @@
Loading
126 127
			try {
127 128
				getHandler().event(remoteAddress, event, length);
128 129
			}
129 -
			catch (Exception e) {
130 -
				elogger.error(logger, "Failed event {} for {}: {}", event, this, e);
130 +
			catch (Throwable e) {
131 +
				fireException(SessionIncident.DATA_EVENT_FAILURE, event, e);
131 132
			}
132 133
		}
133 134
	}

@@ -1,7 +1,7 @@
Loading
1 1
/*
2 2
 * -------------------------------- MIT License --------------------------------
3 3
 * 
4 -
 * Copyright (c) 2020-2021 SNF4J contributors
4 +
 * Copyright (c) 2020-2022 SNF4J contributors
5 5
 * 
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
@@ -433,7 +433,14 @@
Loading
433 433
		if (event == SessionEvent.CLOSED) {
434 434
			handleClosed();
435 435
		}
436 -
		handler.event(event);
436 +
		try {
437 +
			handler.event(event);
438 +
		}
439 +
		catch (Throwable t) {
440 +
			if (session.fireException(SessionIncident.SESSION_EVENT_FAILURE, event, t)) {
441 +
				return;
442 +
			}
443 +
		}
437 444
		if (event == SessionEvent.OPENED) {
438 445
			handleOpened();
439 446
		}

@@ -159,7 +159,7 @@
Loading
159 159
					super.quickClose();
160 160
				}
161 161
			}
162 -
			catch (Exception e) {
162 +
			catch (Throwable e) {
163 163
				elogger.error(logger, "Failed event {} for {}: {}", EventType.EXCEPTION_CAUGHT, this, e);
164 164
				futuresController.exception(t);
165 165
				super.quickClose();

@@ -162,7 +162,7 @@
Loading
162 162
				futuresController.exception(t);
163 163
				super.quickClose();
164 164
			}
165 -
			catch (Exception e) {
165 +
			catch (Throwable e) {
166 166
				elogger.error(logger, "Failed event {} for {}: {}", EventType.EXCEPTION_CAUGHT, this, e);
167 167
				futuresController.exception(t);
168 168
				super.quickClose();

@@ -1,7 +1,7 @@
Loading
1 1
/*
2 2
 * -------------------------------- MIT License --------------------------------
3 3
 * 
4 -
 * Copyright (c) 2021 SNF4J contributors
4 +
 * Copyright (c) 2021-2022 SNF4J contributors
5 5
 * 
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
@@ -200,7 +200,7 @@
Loading
200 200
				shutdowns.add(association);
201 201
			}
202 202
		}
203 -
		catch (Exception e) {
203 +
		catch (Throwable e) {
204 204
			elogger.error(logger, "Shutting down of ssociations failed for {}: {}", this, e);
205 205
		}
206 206
	}

@@ -367,6 +367,7 @@
Loading
367 367
			}
368 368
			if (!session.incident(incident, e)) {
369 369
				elogger.error(LOGGER, incident.defaultMessage(), session, e);
370 +
				session.fireException(e);
370 371
			}
371 372
			return;
372 373
		}

@@ -1,7 +1,7 @@
Loading
1 1
/*
2 2
 * -------------------------------- MIT License --------------------------------
3 3
 * 
4 -
 * Copyright (c) 2017-2021 SNF4J contributors
4 +
 * Copyright (c) 2017-2022 SNF4J contributors
5 5
 * 
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
@@ -190,7 +190,7 @@
Loading
190 190
		try {
191 191
			newSelector = factory.openSelector();
192 192
		}
193 -
		catch (Exception e) {
193 +
		catch (Throwable e) {
194 194
			elogger.error(logger, "Failed to create new selector during rebuilding process: {}", e);
195 195
			return;
196 196
		}
@@ -221,7 +221,7 @@
Loading
221 221
					}
222 222
					
223 223
				}
224 -
				catch (Exception e) {
224 +
				catch (Throwable e) {
225 225
					elogger.error(logger, "Failed to re-register channel {} to new selector during rebuilding process: {}" , ctx.toString(channel), e);
226 226
					try {
227 227
						if (ctx.isServer()) {
@@ -233,7 +233,7 @@
Loading
233 233
							handleInvalidKey(key, stoppingKeys, true);
234 234
						}
235 235
					}
236 -
					catch (Exception e2) {
236 +
					catch (Throwable e2) {
237 237
						elogger.error(logger, "Failed to close channel {} during rebuilding process: {}", ctx.toString(channel), e2);
238 238
					}
239 239
				}
@@ -245,7 +245,7 @@
Loading
245 245
		try {
246 246
			selector.close();
247 247
		}
248 -
		catch (Exception e) {
248 +
		catch (Throwable e) {
249 249
			elogger.error(logger, "Failed to close old selector during rebuilding process: {}" , e);
250 250
		}
251 251
		
@@ -547,7 +547,7 @@
Loading
547 547
								key.channel().close();
548 548
								ctx.postClose(key.channel());
549 549
							}
550 -
							catch (Exception e) {
550 +
							catch (Throwable e) {
551 551
								elogWarnOrError(logger, "Closing of channel {} failed: {}", ctx.toString(key.channel()), e);
552 552
							}
553 553
						}
@@ -565,7 +565,7 @@
Loading
565 565
						try {
566 566
							handleInvalidKey(key, stoppingKeys);
567 567
						}
568 -
						catch (Exception e){
568 +
						catch (Throwable e) {
569 569
							elogger.error(logger, "Processing of invalidated key for {} failed: {}", key.attachment(), e);
570 570
						}
571 571
					}
@@ -599,7 +599,7 @@
Loading
599 599
								elogger.error(logger, incident.defaultMessage(), session, e.getCause());
600 600
							}
601 601
						}
602 -
						catch (Exception e) {
602 +
						catch (Throwable e) {
603 603
							if (key.isValid()) {
604 604
								fireException(key, e);
605 605
							}
@@ -628,7 +628,7 @@
Loading
628 628
								handleInvalidKey(key, stoppingKeys);
629 629
							}
630 630
						}
631 -
						catch (Exception e) {
631 +
						catch (Throwable e) {
632 632
							elogger.error(logger, "Processing of invalidated key for {} failed: {}", key.attachment(), e);
633 633
						}
634 634
						
@@ -650,7 +650,7 @@
Loading
650 650
								it.remove();
651 651
								handleInvalidKey(key, null);
652 652
							}
653 -
							catch (Exception e) {
653 +
							catch (Throwable e) {
654 654
								elogger.error(logger, "Processing of not handled invalidated key for {} failed: {}", key.attachment(), e);
655 655
							}
656 656
						}
@@ -689,7 +689,7 @@
Loading
689 689
							abortRegistration(reg, true, null);
690 690
							throw e;
691 691
						}
692 -
						catch (Exception e) {
692 +
						catch (Throwable e) {
693 693
							//JDK1.6 does not throw ClosedSelectorException if registering with closed selector
694 694
							if (!selector.isOpen()) {
695 695
								abortRegistration(reg, true, null);
@@ -715,7 +715,7 @@
Loading
715 715
			catch (ClosedSelectorException e) {
716 716
				break;
717 717
			}
718 -
			catch (Exception e) {
718 +
			catch (Throwable e) {
719 719
				elogger.error(logger, "Unexpected exception thrown in main loop: {}", e);
720 720
			}
721 721
		}
@@ -775,7 +775,7 @@
Loading
775 775
				handleSwitchings();
776 776
			}
777 777
		}
778 -
		catch (Exception e) {
778 +
		catch (Throwable e) {
779 779
			elogger.error(logger, "Unexpected exception thrown during execution of task {}: {}", task.task, e);
780 780
			if (future != null) {
781 781
				future.abort(e);
@@ -800,7 +800,7 @@
Loading
800 800
			try {
801 801
				ctx.close(reg.channel);
802 802
			}
803 -
			catch (IOException e) {
803 +
			catch (Throwable e) {
804 804
				elogger.warn(logger, "Closing of channel {} during aborting registration failed: {}", ctx.toString(reg.channel), e);
805 805
			}
806 806
		}
@@ -837,7 +837,7 @@
Loading
837 837
				if (isStopped()) {
838 838
					try {
839 839
						selector.close();
840 -
					} catch (IOException e) {
840 +
					} catch (Throwable e) {
841 841
						//Ignore
842 842
					}
843 843
				}
@@ -1268,7 +1268,7 @@
Loading
1268 1268
				fireEvent(newSession, DataEvent.RECEIVED, bytes);
1269 1269
				newSession.consumeInBuffer();
1270 1270
			}
1271 -
		} catch (Exception e) {
1271 +
		} catch (Throwable e) {
1272 1272
			elogger.error(logger, "Switching from {} to {} failed: {}", session, newSession, e);
1273 1273
			fireException(newSession, e);
1274 1274
		}

@@ -196,7 +196,7 @@
Loading
196 196
					super.quickClose();
197 197
				}
198 198
			}
199 -
			catch (Exception e) {
199 +
			catch (Throwable e) {
200 200
				elogger.error(logger, "Failed event {} for {}: {}", EventType.EXCEPTION_CAUGHT, this, e);
201 201
				futuresController.exception(t);
202 202
				super.quickClose();

@@ -1,7 +1,7 @@
Loading
1 1
/*
2 2
 * -------------------------------- MIT License --------------------------------
3 3
 * 
4 -
 * Copyright (c) 2019-2021 SNF4J contributors
4 +
 * Copyright (c) 2019-2022 SNF4J contributors
5 5
 * 
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
@@ -51,7 +51,8 @@
Loading
51 51
	/**
52 52
	 * A failure occurred while encoding data passed to write/send methods.
53 53
	 * <p>
54 -
	 * <b>Default action</b>: the default message is logged at the ERROR level. 
54 +
	 * <b>Default action</b>: the default message is logged at the ERROR level and
55 +
	 * an exception is reported.
55 56
	 */
56 57
	ENCODING_PIPELINE_FAILURE("Encoding pipeline failed for {}: {}"),
57 58
	
@@ -73,7 +74,39 @@
Loading
73 74
	 * <p>
74 75
	 * <b>Default action</b>: the default message is logged at the ERROR level. 
75 76
	 */
76 -
	SCTP_SENDING_FAILURE("Sending via SCTP channel failed for {}: {}");
77 +
	SCTP_SENDING_FAILURE("Sending via SCTP channel failed for {}: {}"),
78 +
	
79 +
	/**
80 +
	 * A failure occurred while processing a {@link SessionEvent} in a session's handler.
81 +
	 * <p>
82 +
	 * <b>Default action</b>: the default message is logged at the ERROR level and
83 +
	 * an exception is reported.
84 +
	 */
85 +
	SESSION_EVENT_FAILURE("Failed event {} for {}: {}"),
86 +
	
87 +
	/**
88 +
	 * A failure occurred while processing a {@link DataEvent} in a session's handler.
89 +
	 * <p>
90 +
	 * <b>Default action</b>: the default message is logged at the ERROR level and
91 +
	 * an exception is reported.
92 +
	 */
93 +
	DATA_EVENT_FAILURE("Failed event {} for {}: {}"),
94 +
	
95 +
	/**
96 +
	 * A failure occurred while processing a timer event in a session's handler.
97 +
	 * <p>
98 +
	 * <b>Default action</b>: the default message is logged at the ERROR level and
99 +
	 * an exception is reported.
100 +
	 */
101 +
	TIMER_EVENT_FAILURE("Failed timer event {} for {}: {}"),
102 +
	
103 +
	/**
104 +
	 * A failure occurred while processing a timer task in a session's handler.
105 +
	 * <p>
106 +
	 * <b>Default action</b>: the default message is logged at the ERROR level and
107 +
	 * an exception is reported.
108 +
	 */
109 +
	TIMER_TASK_FAILURE("Failed timer task {} for {}: {}");
77 110
	
78 111
	private String defaultMessage;
79 112
	

@@ -391,7 +391,7 @@
Loading
391 391
				logger.debug("Accepted channel {}", ctx.toString(channel));
392 392
			}
393 393
		}
394 -
		catch (Exception e) {
394 +
		catch (Throwable e) {
395 395
			elogWarnOrError(logger, "Accepting from channel {} failed: {}", ctx.toString(key.channel()), e);
396 396
			if (channel != null) {
397 397
				try {
@@ -420,7 +420,7 @@
Loading
420 420
				}
421 421
				acceptedKey = channel.register(getUnderlyingSelector(selector), SelectionKey.OP_READ, ctx.wrap(session));
422 422
			}
423 -
			catch (Exception e) {
423 +
			catch (Throwable e) {
424 424
				if (session == null) {
425 425
					elogger.error(logger, "Unable to create session for accepted channel {}: {}", ctx.toString(channel), e);
426 426
					try {
@@ -493,7 +493,7 @@
Loading
493 493
					key.channel().close();
494 494
				}
495 495
			}
496 -
			catch (Exception e) {
496 +
			catch (Throwable e) {
497 497
				elogWarnOrError(logger, "Finishing connection of channel {} failed: {}", ctx.toString(key.channel()), e);
498 498
				fireException(session, e);
499 499
			}
@@ -567,7 +567,7 @@
Loading
567 567
				} while (spinCount > 0);
568 568
			}
569 569
		}
570 -
		catch (Exception e) {
570 +
		catch (Throwable e) {
571 571
			if (totalBytes > 0) {
572 572
				fireEvent(session, DataEvent.SENT, totalBytes);
573 573
			}
@@ -593,7 +593,7 @@
Loading
593 593
		try {
594 594
			bytes = ((SocketChannel)key.channel()).read(session.getInBuffer());
595 595
		}
596 -
		catch (Exception e) {
596 +
		catch (Throwable e) {
597 597
			elogWarnOrError(logger, "Reading from channel in {} failed: {}", session, e);
598 598
			fireException(session, e);
599 599
			bytes = 0;
@@ -659,7 +659,7 @@
Loading
659 659
				}
660 660
			}
661 661
		} 
662 -
		catch (Exception e) {
662 +
		catch (Throwable e) {
663 663
			elogWarnOrError(logger, "Reading from channel in {} failed: {}", session, e);
664 664
			fireException(session, e);
665 665
			bytes = 0;
@@ -692,7 +692,7 @@
Loading
692 692
		long totalBytes = 0;
693 693
		long leftBytes = 0;
694 694
		long bytes;
695 -
		Exception exception = null;
695 +
		Throwable exception = null;
696 696
		
697 697
		if (traceEnabled) {
698 698
			logger.trace("Writting to channel in {}", session);
@@ -778,7 +778,7 @@
Loading
778 778
				}
779 779
			}
780 780
		}
781 -
		catch (Exception e) {
781 +
		catch (Throwable e) {
782 782
			exception = e;
783 783
		}
784 784
Files Coverage
snf4j-core-log4j2/src/main/java/org/snf4j/core/logger/impl 96.66%
snf4j-core-slf4j/src/main/java/org/snf4j/core/logger/impl 96.66%
snf4j-core/src/main/java/org/snf4j/core 98.05%
snf4j-sctp/src/main/java/org/snf4j/core 98.58%
snf4j-websocket/src/main/java/org/snf4j/websocket 99.37%
Project Totals (241 files) 98.28%
codecov-umbrella
Build #2287703294 -
1
coverage:
2
  range: "70...100"
3
  round: down
4
  precision: 2
5
  
6
  status:
7
    project:
8
      default:
9
        enabled: yes
10
        target: 94%
11
        threshold: 5%
12
        
13
    patch:
14
      default:
15
        enabled: yes
16
        target: 85%
17
        threshold: 5%
18
        
19
    changes: no
20
    
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading