18
18
19
19
package org .audit4j .core .util ;
20
20
21
+ import java .io .Serializable ;
21
22
import java .util .AbstractList ;
22
23
import java .util .ArrayList ;
23
24
import java .util .List ;
24
25
import java .util .RandomAccess ;
25
26
import java .util .Timer ;
26
27
import java .util .TimerTask ;
28
+ import java .util .concurrent .CopyOnWriteArrayList ;
27
29
28
30
/**
29
31
* The Class CircularTimelyBufferedArrayList.
30
- *
31
- * @param <E> the element type
32
+ *
33
+ * @param <E>
34
+ * the element type
32
35
* @author <a href="mailto:[email protected] ">Janith Bandara</a>
33
36
*/
34
- public class TimelyBufferedArrayList <E > extends AbstractList <E > implements RandomAccess {
37
+ public class ConcurrentTimelyBufferedArrayList <E > extends AbstractList <E > implements RandomAccess , Serializable ,
38
+ Cloneable {
39
+
40
+ /**
41
+ * asdas
42
+ */
43
+ private static final long serialVersionUID = 8870953621895891238L ;
35
44
36
45
/** The buff. */
37
- private final List <E > buff = new ArrayList <E >();
38
-
46
+ private final List <E > buff = new CopyOnWriteArrayList <E >();
47
+
39
48
/** The listener. */
40
49
private final BufferedListener <E > listener ;
41
50
42
51
/**
43
52
* Instantiates a new circular timely buffered array list.
44
- *
45
- * @param timeInMills the time in mills
46
- * @param listener the listener
53
+ *
54
+ * @param timeInMills
55
+ * the time in mills
56
+ * @param listener
57
+ * the listener
47
58
*/
48
- public TimelyBufferedArrayList (final int timeInMills , final BufferedListener <E > listener ) {
59
+ public ConcurrentTimelyBufferedArrayList (final int timeInMills , final BufferedListener <E > listener ) {
49
60
this .listener = listener ;
50
61
Timer time = new Timer ();
51
62
ScheduleConsumer consumer = new ScheduleConsumer ();
52
63
time .schedule (consumer , 0 , timeInMills );
53
64
}
54
65
55
- /* (non-Javadoc)
66
+ /*
67
+ * (non-Javadoc)
68
+ *
56
69
* @see java.util.AbstractList#get(int)
57
70
*/
58
71
@ Override
59
72
public E get (int index ) {
60
73
return buff .get (index );
61
74
}
62
75
63
- /* (non-Javadoc)
76
+ /*
77
+ * (non-Javadoc)
78
+ *
64
79
* @see java.util.AbstractList#add(java.lang.Object)
65
80
*/
66
81
@ Override
67
82
public boolean add (E e ) {
68
83
return buff .add (e );
69
84
}
70
85
71
- /* (non-Javadoc)
86
+ /*
87
+ * (non-Javadoc)
88
+ *
72
89
* @see java.util.AbstractCollection#size()
73
90
*/
74
91
@ Override
75
92
public int size () {
76
93
return buff .size ();
77
94
}
78
95
79
- /* (non-Javadoc)
96
+ /*
97
+ * (non-Javadoc)
98
+ *
80
99
* @see java.util.AbstractCollection#isEmpty()
81
100
*/
82
101
@ Override
83
102
public boolean isEmpty () {
84
103
return buff .isEmpty ();
85
104
}
86
-
105
+
87
106
@ Override
88
107
public void clear () {
89
108
buff .clear ();
90
109
}
91
110
92
111
/**
93
112
* Gets the buffered.
94
- *
113
+ *
95
114
* @return the buffered
96
115
*/
97
116
public List <E > getBuffered () {
@@ -102,40 +121,42 @@ public List<E> getBuffered() {
102
121
103
122
/**
104
123
* The Class ScheduleConsumer.
105
- *
124
+ *
106
125
* @author <a href="mailto:[email protected] ">Janith Bandara</a>
107
126
*/
108
127
public class ScheduleConsumer extends TimerTask {
109
128
110
- /* (non-Javadoc)
129
+ /*
130
+ * (non-Javadoc)
131
+ *
111
132
* @see java.util.TimerTask#run()
112
133
*/
113
134
@ Override
114
135
public void run () {
115
136
if (!isEmpty ()) {
116
137
listener .accept (getBuffered ());
117
- }
138
+ }
118
139
}
119
140
120
141
}
121
142
122
143
/**
123
- * The listener interface for receiving buffered events.
124
- * The class that is interested in processing a buffered
125
- * event implements this interface, and the object created
126
- * with that class is registered with a component using the
127
- * component's addBufferedListener method. When
128
- * the buffered event occurs, that object's appropriate
129
- * method is invoked.
130
- *
131
- * @param <E> the element type
144
+ * The listener interface for receiving buffered events. The class that is
145
+ * interested in processing a buffered event implements this interface, and
146
+ * the object created with that class is registered with a component using
147
+ * the component's addBufferedListener method. When the buffered event
148
+ * occurs, that object's appropriate method is invoked.
149
+ *
150
+ * @param <E>
151
+ * the element type
132
152
*/
133
153
public interface BufferedListener <E > {
134
-
154
+
135
155
/**
136
156
* Accept.
137
- *
138
- * @param buffered list
157
+ *
158
+ * @param buffered
159
+ * list
139
160
*/
140
161
void accept (List <E > buffered );
141
162
}
0 commit comments