Skip to content

Commit 9f94049

Browse files
committed
added changes
1 parent ce3dd79 commit 9f94049

File tree

4 files changed

+78
-33
lines changed

4 files changed

+78
-33
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<organizationUrl>http://audit4j.org</organizationUrl>
3838
<email>[email protected]</email>
3939
<roles>
40-
<role>owner</role>
41-
<role>developer</role>
40+
<role>Architect</role>
41+
<role>Developer</role>
4242
</roles>
4343
<timezone>+05:30</timezone>
4444
</developer>

src/main/java/org/audit4j/core/TroubleshootManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void troubleshootEvent(AuditEvent event) {
4949
throw new TroubleshootException(
5050
"Invalid Audit event type,\n Audit4j: Audit Event should not null, This event will not be logged by the Audit4j.");
5151
} else if (event.getActor() == null) {
52-
if (Context.getConfigContext().getMetaData().getClass().equals(DummyMetaData.class)) {
52+
if (Context.getConfigContext().getMetaData() == null || Context.getConfigContext().getMetaData().getClass().equals(DummyMetaData.class)) {
5353
event.setActor(CoreConstants.DEFAULT_ACTOR);
5454
Log.warn("Audit4j:WARN If you are not parsing the actor to the AuditEvent,\n"
5555
+ "Audit4j:WARN you should make a your own AuditMetaData implementation. \n"

src/main/java/org/audit4j/core/util/TimelyBufferedArrayList.java renamed to src/main/java/org/audit4j/core/util/ConcurrentTimelyBufferedArrayList.java

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,99 @@
1818

1919
package org.audit4j.core.util;
2020

21+
import java.io.Serializable;
2122
import java.util.AbstractList;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425
import java.util.RandomAccess;
2526
import java.util.Timer;
2627
import java.util.TimerTask;
28+
import java.util.concurrent.CopyOnWriteArrayList;
2729

2830
/**
2931
* The Class CircularTimelyBufferedArrayList.
30-
*
31-
* @param <E> the element type
32+
*
33+
* @param <E>
34+
* the element type
3235
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3336
*/
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;
3544

3645
/** The buff. */
37-
private final List<E> buff = new ArrayList<E>();
38-
46+
private final List<E> buff = new CopyOnWriteArrayList<E>();
47+
3948
/** The listener. */
4049
private final BufferedListener<E> listener;
4150

4251
/**
4352
* 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
4758
*/
48-
public TimelyBufferedArrayList(final int timeInMills, final BufferedListener<E> listener) {
59+
public ConcurrentTimelyBufferedArrayList(final int timeInMills, final BufferedListener<E> listener) {
4960
this.listener = listener;
5061
Timer time = new Timer();
5162
ScheduleConsumer consumer = new ScheduleConsumer();
5263
time.schedule(consumer, 0, timeInMills);
5364
}
5465

55-
/* (non-Javadoc)
66+
/*
67+
* (non-Javadoc)
68+
*
5669
* @see java.util.AbstractList#get(int)
5770
*/
5871
@Override
5972
public E get(int index) {
6073
return buff.get(index);
6174
}
6275

63-
/* (non-Javadoc)
76+
/*
77+
* (non-Javadoc)
78+
*
6479
* @see java.util.AbstractList#add(java.lang.Object)
6580
*/
6681
@Override
6782
public boolean add(E e) {
6883
return buff.add(e);
6984
}
7085

71-
/* (non-Javadoc)
86+
/*
87+
* (non-Javadoc)
88+
*
7289
* @see java.util.AbstractCollection#size()
7390
*/
7491
@Override
7592
public int size() {
7693
return buff.size();
7794
}
7895

79-
/* (non-Javadoc)
96+
/*
97+
* (non-Javadoc)
98+
*
8099
* @see java.util.AbstractCollection#isEmpty()
81100
*/
82101
@Override
83102
public boolean isEmpty() {
84103
return buff.isEmpty();
85104
}
86-
105+
87106
@Override
88107
public void clear() {
89108
buff.clear();
90109
}
91110

92111
/**
93112
* Gets the buffered.
94-
*
113+
*
95114
* @return the buffered
96115
*/
97116
public List<E> getBuffered() {
@@ -102,40 +121,42 @@ public List<E> getBuffered() {
102121

103122
/**
104123
* The Class ScheduleConsumer.
105-
*
124+
*
106125
* @author <a href="mailto:[email protected]">Janith Bandara</a>
107126
*/
108127
public class ScheduleConsumer extends TimerTask {
109128

110-
/* (non-Javadoc)
129+
/*
130+
* (non-Javadoc)
131+
*
111132
* @see java.util.TimerTask#run()
112133
*/
113134
@Override
114135
public void run() {
115136
if (!isEmpty()) {
116137
listener.accept(getBuffered());
117-
}
138+
}
118139
}
119140

120141
}
121142

122143
/**
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
132152
*/
133153
public interface BufferedListener<E> {
134-
154+
135155
/**
136156
* Accept.
137-
*
138-
* @param buffered list
157+
*
158+
* @param buffered
159+
* list
139160
*/
140161
void accept(List<E> buffered);
141162
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.audit4j.core.util;
2+
3+
import java.util.List;
4+
5+
import org.audit4j.core.util.ConcurrentTimelyBufferedArrayList.BufferedListener;
6+
import org.junit.Test;
7+
8+
public class ConcurrentTimelyBufferedArrayListTest {
9+
10+
@Test
11+
public void testList() {
12+
ConcurrentTimelyBufferedArrayList<String> list = new ConcurrentTimelyBufferedArrayList<>(10,
13+
new BufferedListener<String>() {
14+
@Override
15+
public void accept(List<String> buffered) {
16+
System.out.println(buffered.toString());
17+
}
18+
});
19+
20+
list.add("1");
21+
list.add("2");
22+
list.add("3");
23+
}
24+
}

0 commit comments

Comments
 (0)