Skip to content

Commit 8b671be

Browse files
committed
Use mini2Dx-lock-provider library. Update to Java 8
1 parent 6398110 commit 8b671be

File tree

6 files changed

+40
-113
lines changed

6 files changed

+40
-113
lines changed

CHANGES

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[1.7.0]
2+
- Changed to using mini2Dx-lock-provider library to support game consoles
3+
- Source/target compatability now Java 8
4+
15
[1.6.0]
26
- Add EntityMessageData for transportation of entities in an Entity-Component-System pattern
37
- Allow for cancellation of messages in the bus queue

build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ repositories {
3636
maven { url "https://mini2dx.org/maven/content/repositories/thirdparty" }
3737
}
3838

39-
sourceCompatibility = 1.7
40-
targetCompatibility = 1.7
39+
sourceCompatibility = 1.8
40+
targetCompatibility = 1.8
4141

4242
task javadocJar(type: Jar) {
4343
classifier = 'javadoc'
@@ -54,6 +54,8 @@ artifacts {
5454
}
5555

5656
dependencies {
57+
compile "org.mini2Dx:mini2Dx-lock-provider:1.1.0"
58+
5759
testCompile 'junit:junit:4.11'
5860
testCompile "org.jmock:jmock-junit4:2.5.1"
5961
testCompile "org.jmock:jmock-legacy:2.5.1"

src/main/java/org/mini2Dx/minibus/MessageBus.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
*/
2424
package org.mini2Dx.minibus;
2525

26-
import java.util.ArrayList;
27-
import java.util.Collections;
2826
import java.util.List;
29-
import java.util.concurrent.CopyOnWriteArrayList;
3027

28+
import org.mini2Dx.lockprovider.Locks;
29+
import org.mini2Dx.lockprovider.jvm.JvmLocks;
3130
import org.mini2Dx.minibus.exchange.ConcurrentMessageExchange;
3231
import org.mini2Dx.minibus.exchange.ImmediateMessageExchange;
3332
import org.mini2Dx.minibus.exchange.IntervalMessageExchange;
@@ -36,15 +35,13 @@
3635
import org.mini2Dx.minibus.exchange.query.QueryMessageExchangePool;
3736
import org.mini2Dx.minibus.transmission.MessageTransmission;
3837
import org.mini2Dx.minibus.transmission.MessageTransmissionPool;
39-
import org.mini2Dx.minibus.util.JvmLockProvider;
40-
import org.mini2Dx.minibus.util.LockProvider;
4138
import org.mini2Dx.minibus.util.SnapshotArrayList;
4239

4340
/**
4441
* A message bus to publishing {@link MessageData}s
4542
*/
4643
public class MessageBus {
47-
public static LockProvider LOCK_PROVIDER = new JvmLockProvider();
44+
public static Locks LOCK_PROVIDER = new JvmLocks();
4845

4946
final List<MessageExchange> exchangers = new SnapshotArrayList<MessageExchange>();
5047
final List<CancelledMessageHandler> cancelledMessageHandlers = new SnapshotArrayList<CancelledMessageHandler>();

src/main/java/org/mini2Dx/minibus/util/JvmLockProvider.java

-42
This file was deleted.

src/main/java/org/mini2Dx/minibus/util/LockProvider.java

-34
This file was deleted.

src/main/java/org/mini2Dx/minibus/util/SnapshotArrayList.java

+29-29
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
*/
2424
package org.mini2Dx.minibus.util;
2525

26+
import org.mini2Dx.lockprovider.ReadWriteLock;
2627
import org.mini2Dx.minibus.MessageBus;
2728

2829
import java.util.*;
29-
import java.util.concurrent.locks.ReadWriteLock;
3030

3131
public class SnapshotArrayList<T> implements List<T> {
3232
private final Object iteratorLock = new Object();
@@ -59,9 +59,9 @@ private void ensureCapacity(int capacity) {
5959
@Override
6060
public int size() {
6161
final int result;
62-
lock.readLock().lock();
62+
lock.lockRead();
6363
result = size;
64-
lock.readLock().unlock();
64+
lock.unlockRead();
6565
return result;
6666
}
6767

@@ -73,14 +73,14 @@ public boolean isEmpty() {
7373
@Override
7474
public boolean contains(Object o) {
7575
boolean result = false;
76-
lock.readLock().lock();
76+
lock.lockRead();
7777
for(int i = 0; i < size; i++) {
7878
if(array[i].equals(o)) {
7979
result = true;
8080
break;
8181
}
8282
}
83-
lock.readLock().unlock();
83+
lock.unlockRead();
8484
return result;
8585
}
8686

@@ -94,9 +94,9 @@ public Iterator<T> iterator() {
9494
result = iteratorPool.poll();
9595
}
9696
}
97-
lock.readLock().lock();
97+
lock.lockRead();
9898
result.init(array, size);
99-
lock.readLock().unlock();
99+
lock.unlockRead();
100100
return result;
101101
}
102102

@@ -112,19 +112,19 @@ public <T1> T1[] toArray(T1[] a) {
112112

113113
@Override
114114
public boolean add(T t) {
115-
lock.writeLock().lock();
115+
lock.lockWrite();
116116
ensureCapacity(size + 1);
117117
array[size] = t;
118118
size++;
119-
lock.writeLock().unlock();
119+
lock.unlockWrite();
120120
return true;
121121
}
122122

123123
@Override
124124
public boolean remove(Object o) {
125125
boolean result = false;
126126

127-
lock.writeLock().lock();
127+
lock.lockWrite();
128128
for(int i = 0; i < size; i++) {
129129
if(!array[i].equals(o)) {
130130
continue;
@@ -141,7 +141,7 @@ public boolean remove(Object o) {
141141
result = true;
142142
break;
143143
}
144-
lock.writeLock().unlock();
144+
lock.unlockWrite();
145145

146146
return result;
147147
}
@@ -158,9 +158,9 @@ public boolean containsAll(Collection<?> c) {
158158

159159
@Override
160160
public boolean addAll(Collection<? extends T> c) {
161-
lock.writeLock().lock();
161+
lock.lockWrite();
162162
ensureCapacity(size + c.size());
163-
lock.writeLock().unlock();
163+
lock.unlockWrite();
164164
for(T o : c) {
165165
add(o);
166166
}
@@ -188,28 +188,28 @@ public boolean retainAll(Collection<?> c) {
188188

189189
@Override
190190
public void clear() {
191-
lock.writeLock().lock();
191+
lock.lockWrite();
192192
for(int i = 0; i < array.length; i++) {
193193
array[i] = null;
194194
}
195195
size = 0;
196-
lock.writeLock().unlock();
196+
lock.unlockWrite();
197197
}
198198

199199
@Override
200200
public T get(int index) {
201201
T result = null;
202-
lock.readLock().lock();
202+
lock.lockRead();
203203
if(index < 0) {
204-
lock.readLock().unlock();
204+
lock.unlockRead();
205205
throw new IndexOutOfBoundsException();
206206
}
207207
if(index >= size) {
208-
lock.readLock().unlock();
208+
lock.unlockRead();
209209
throw new IndexOutOfBoundsException();
210210
}
211211
result = (T) array[index];
212-
lock.readLock().unlock();
212+
lock.unlockRead();
213213
return result;
214214
}
215215

@@ -225,16 +225,16 @@ public void add(int index, T element) {
225225

226226
private T remove(int index, boolean throwException) {
227227
Object result = null;
228-
lock.writeLock().lock();
228+
lock.lockWrite();
229229
if(index < 0) {
230-
lock.writeLock().unlock();
230+
lock.unlockWrite();
231231
if(throwException) {
232232
throw new IndexOutOfBoundsException();
233233
}
234234
return null;
235235
}
236236
if(index >= size) {
237-
lock.writeLock().unlock();
237+
lock.unlockWrite();
238238
if(throwException) {
239239
throw new IndexOutOfBoundsException();
240240
}
@@ -250,7 +250,7 @@ private T remove(int index, boolean throwException) {
250250
}
251251

252252
size--;
253-
lock.writeLock().unlock();
253+
lock.unlockWrite();
254254
return (T) result;
255255
}
256256

@@ -265,27 +265,27 @@ public T remove(int index) {
265265

266266
@Override
267267
public int indexOf(Object o) {
268-
lock.readLock().lock();
268+
lock.lockRead();
269269
for(int i = 0; i < size; i++) {
270270
if(array[i].equals(o)) {
271-
lock.readLock().unlock();
271+
lock.unlockRead();
272272
return i;
273273
}
274274
}
275-
lock.readLock().unlock();
275+
lock.unlockRead();
276276
return -1;
277277
}
278278

279279
@Override
280280
public int lastIndexOf(Object o) {
281-
lock.readLock().lock();
281+
lock.lockRead();
282282
for(int i = size - 1; i >= 0; i--) {
283283
if(array[i].equals(o)) {
284-
lock.readLock().unlock();
284+
lock.unlockRead();
285285
return i;
286286
}
287287
}
288-
lock.readLock().unlock();
288+
lock.unlockRead();
289289
return -1;
290290
}
291291

0 commit comments

Comments
 (0)