Project

General

Profile

1
package eu.dnetlib.enabling.is.sn;
2

    
3
import java.util.Collection;
4
import java.util.Date;
5

    
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7

    
8
/**
9
 * A notification logger maintains a log of sent notifications, and their status (succes or failure with exception etc).
10
 *
11
 * @author marko
12
 *
13
 */
14
public interface NotificationInvocationLogger {
15

    
16
	/**
17
	 * A log entry. Used to create log entries in two phases. First a log entry is created with "startLogging" and after
18
	 * the notification is sent the log entry is committed with success() of failure().
19
	 *
20
	 * @author marko
21
	 *
22
	 */
23
	interface Entry {
24
		/**
25
		 * log entry status.
26
		 *
27
		 * @author marko
28
		 *
29
		 */
30
		enum Status {
31
			/**
32
			 * notification is queued but not started to be sent.
33
			 */
34
			Queued,
35
			/**
36
			 * notification is ongoing.
37
			 */
38
			Ongoing,
39
			/**
40
			 * notification succeeded.
41
			 */
42
			Succeeded,
43
			/**
44
			 * notification failed.
45
			 */
46
			Failed
47
		};
48

    
49
		/**
50
		 * sets the status to ongoing.
51
		 */
52
		void ongoing();
53

    
54
		/**
55
		 * commits the log entry tagging it as succeeded.
56
		 */
57
		void success();
58

    
59
		/**
60
		 * commits the log entry tagging it as failed.
61
		 *
62
		 * @param exception
63
		 *            throwable, cause of failure
64
		 */
65
		void failure(Throwable exception);
66

    
67
		/**
68
		 * get start date time.
69
		 *
70
		 * @return date
71
		 */
72
		Date getStart();
73

    
74
		/**
75
		 * get finish date time.
76
		 *
77
		 * @return date
78
		 */
79
		Date getFinish();
80

    
81
		/**
82
		 * get log status.
83
		 *
84
		 * @return log status
85
		 */
86
		Status getStatus();
87

    
88
		/**
89
		 * get log message.
90
		 *
91
		 * @return log message
92
		 */
93
		NotificationMessage getMessage();
94

    
95
		/**
96
		 * get destination.
97
		 *
98
		 * @return destination url
99
		 */
100
		String getDestination();
101

    
102
		/**
103
		 * get exception.
104
		 *
105
		 * @return exception
106
		 */
107
		Throwable getException();
108

    
109
		/**
110
		 * Get exception error message or empty string if succeded.
111
		 *
112
		 * @return error message
113
		 */
114
		String getErrorMessage();
115

    
116
		/**
117
		 * Human readable duration.
118
		 *
119
		 * @return human readable duration
120
		 */
121
		String getDuration();
122
	}
123

    
124
	/**
125
	 * Start logging a notification invocation.
126
	 *
127
	 * @param destination
128
	 *            destination
129
	 * @param message
130
	 *            message to be logged.
131
	 * @return an entry object which has to be committed.
132
	 *
133
	 */
134
	Entry startLogging(W3CEndpointReference destination, NotificationMessage message);
135

    
136
	/**
137
	 * get all entries.
138
	 *
139
	 * @return all entries
140
	 */
141
	Collection<Entry> getEntries();
142
}
(12-12/23)