Skip to content
Permalink
Browse files

Ensure compatibility with auto-boxing/-unboxing in JDK 6.

Additional minor simplifications and preparations for compatibility with
JDK >= 8 (avoid deprecation warnings), plus a number of JavaDoc
corrections.

Thanks for Christian Klemke (cklemkeberlin) for these changes. This
fixes some issues introduced in pull request #16 (commit 6ea7122).
See pull request #17 for discussion.
  • Loading branch information...
jsampson committed Aug 3, 2019
1 parent 8701eb0 commit 107fdb38966d1df52728735ca8dc672ac4bdbe68
Showing with 42 additions and 47 deletions.
  1. +1 −1 core/src/main/java/org/prevayler/Prevayler.java
  2. +1 −1 core/src/main/java/org/prevayler/TransactionWithQuery.java
  3. +1 −1 core/src/main/java/org/prevayler/implementation/PrevaylerDirectory.java
  4. +1 −1 demos/demo1/src/main/java/org/prevayler/demos/demo1/NumberKeeper.java
  5. +1 −1 demos/scalability/src/main/java/org/prevayler/demos/scalability/Main.java
  6. +1 −1 ...lability/src/main/java/org/prevayler/demos/scalability/prevayler/PrevaylerTransactionSubject.java
  7. +2 −3 demos/scalability/src/main/java/org/prevayler/demos/scalability/prevayler/TransactionSystem.java
  8. +0 −1 extras/facade/src/main/java/org/prevayler/contrib/facade/ProxyTransaction.java
  9. +5 −5 extras/facade/src/test/java/org/prevayler/contrib/facade/AnotherTest.java
  10. +2 −2 extras/memento/src/main/java/org/prevayler/demos/memento/Bank.java
  11. +3 −3 spikes/cluster/src/test/org/prevayler/cluster/NodeTest.java
  12. +1 −1 spikes/mirror/src/main/java/org/prevayler/implementation/replication/ClientPublisher.java
  13. +1 −1 spikes/snapshotScheduler/src/main/java/org/prevayler/util/SnapshotListener.java
  14. +0 −2 spikes/socketServer/src/main/java/junkyard/BeanSetter.java
  15. +1 −1 spikes/socketServer/src/main/java/org/prevayler/socketserver/client/CallbackThread.java
  16. +1 −1 spikes/socketServer/src/main/java/org/prevayler/socketserver/client/IModelCallback.java
  17. +4 −4 spikes/socketServer/src/main/java/org/prevayler/socketserver/server/CommandThread.java
  18. +2 −2 spikes/socketServer/src/main/java/org/prevayler/socketserver/server/Main.java
  19. +9 −10 spikes/socketServer/src/main/java/org/prevayler/socketserver/server/Notification.java
  20. +1 −1 spikes/socketServer/src/main/java/org/prevayler/socketserver/server/NotificationThread.java
  21. +3 −3 tests/src/test/java/org/prevayler/foundation/DeepCopierTest.java
  22. +1 −1 tests/src/test/java/org/prevayler/implementation/QueryExecutionTest.java
@@ -55,7 +55,7 @@
public <R> R execute(TransactionWithQuery<? super P, R> transactionWithQuery) throws Exception;

/**
* The same as execute(TransactionWithQuery<P,R>) except no Exception is thrown.
* The same as execute(TransactionWithQuery&lt;P, R&gt;) except no Exception is thrown.
*
* @return The result returned by the execution of the sureTransactionWithQuery on the prevalentSystem().
*/
@@ -17,7 +17,7 @@

/**
* Performs the necessary modifications on the given prevalentSystem and also returns an object or throws an Exception.
* This method is called by Prevayler.execute(TransactionWithQuery<P,R>) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples.
* This method is called by Prevayler.execute(TransactionWithQuery&lt;P, R&gt;) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples.
*
* @param prevalentSystem The system on which this TransactionWithQuery will execute.
* @param executionTime The time at which this TransactionWithQuery is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction.
@@ -160,7 +160,7 @@ public boolean accept(File pathname) {

Arrays.sort(journals, new Comparator<File>() {
public int compare(File f1, File f2) {
return new Long(journalVersion(f1)).compareTo(new Long(journalVersion(f2)));
return Long.valueOf(journalVersion(f1)).compareTo(Long.valueOf(journalVersion(f2)));
}
});

@@ -15,7 +15,7 @@


void keep(int nextNumber) {
numbers.add(new Integer(nextNumber));
numbers.add(nextNumber);
}

List<Integer> numbers() {
@@ -337,7 +337,7 @@ static private String property(String name) {

static private int intProperty(String name) {
try {
return Integer.valueOf(property(name)).intValue();
return Integer.valueOf(property(name));
} catch (NumberFormatException nfx) {
out("NumberFormatException reading property " + name);
throw nfx;
@@ -43,7 +43,7 @@ private void initializePrevayler() throws Exception {
PrevaylerFactory<TransactionSystem> factory = new PrevaylerFactory<TransactionSystem>();
factory.configurePrevalentSystem(new TransactionSystem());
factory.configurePrevalenceDirectory(_journalDirectory);
factory.configureJournalSerializer("journal", (Serializer) Class.forName(_journalSerializer).newInstance());
factory.configureJournalSerializer("journal", (Serializer) Class.forName(_journalSerializer).getDeclaredConstructor().newInstance());
prevayler = factory.create(); //No snapshot is generated by the test.
}

@@ -15,13 +15,12 @@ public void performTransaction(Record recordToInsert, Record recordToUpdate, lon
synchronized (recordsById) {
put(recordToInsert);
put(recordToUpdate);
recordsById.remove(new Long(idToDelete));
recordsById.remove(Long.valueOf(idToDelete));
}
}

private Object put(Record newRecord) {
Long key = new Long(newRecord.getId());
return recordsById.put(key, newRecord);
return recordsById.put(newRecord.getId(), newRecord);
}

public void replaceAllRecords(RecordIterator newRecords) {
@@ -34,7 +34,6 @@

import org.prevayler.Transaction;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Date;

@@ -78,7 +78,7 @@ public void testCampGuideSystem() throws Exception {
addSite(guide, "Dance and dream", 50, CampSite.ON_SITE, 0, 0, 1, 1, 640, 32);
addSite(guide, "Sunset beach resort", CampSite.ON_SITE, CampSite.ON_SITE, 0, 0, 0, 1, 800, 35);

assertEquals("Should have been 16 camp sites", new Integer(16), new Integer(guide.getCampSites().size()));
assertEquals("Should have been 16 camp sites", 16, guide.getCampSites().size());

int i = 16;
for (Iterator<CampSite> iter = guide.getCampSites().iterator(); iter.hasNext(); ) {
@@ -89,13 +89,13 @@ public void testCampGuideSystem() throws Exception {
//for (int b=100000000; b > 0; b--) {}
guide.updateCampSite(site);
//System.out.println("updated: " + guide.getCampSite(site.objectCode()).getUpdated().getTime());
assertEquals("object was updated, but created date should have stayed the same", new Long(site.getCreated().getTime()), new Long(guide.getCampSite(site.objectCode()).getCreated().getTime()));
assertFalse("object was updated, so time should have been different", new Long(site.getUpdated().getTime()).equals(new Long(guide.getCampSite(site.objectCode()).getUpdated().getTime())));
assertEquals("object was updated, but created date should have stayed the same", site.getCreated().getTime(), guide.getCampSite(site.objectCode()).getCreated().getTime());
assertFalse("object was updated, so time should have been different", Long.valueOf(site.getUpdated().getTime()).equals(Long.valueOf(guide.getCampSite(site.objectCode()).getUpdated().getTime())));
guide.removeCampSite(site);
assertNull("camp site removed, so should have been null", guide.getCampSite(site.objectCode()));
assertEquals("Should have been " + --i + " camp sites", new Integer(i), new Integer(guide.getCampSites().size()));
assertEquals("Should have been " + --i + " camp sites", i, guide.getCampSites().size());
}
assertEquals("Should have been 0", new Integer(0), new Integer(guide.getCampSites().size()));
assertEquals("Should have been 0", 0, guide.getCampSites().size());

for (int j = 0; j < guide.getCampSites().size(); j++) {
//System.out.println(((CampSite)guide.getCampSites().get(i)).getUpdated());
@@ -58,7 +58,7 @@ public Account createAccount(String holder) throws Account.InvalidHolder {

public void deleteAccount(long number) throws AccountNotFound {
findAccount(number);
accountsByNumber.remove(number);
accountsByNumber.remove(Long.valueOf(number));
}

public List<Account> accounts() {
@@ -88,7 +88,7 @@ public void transfer(long sourceNumber, long destinationNumber, long amount, Dat
}

private Account searchAccount(long number) {
return accountsByNumber.get(number);
return accountsByNumber.get(Long.valueOf(number));
}

public class AccountNotFound extends Exception {
@@ -63,15 +63,15 @@ public void testMultipleMessages() throws Exception {
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
if (numberOfMessages % 2 == 0) {
node.broadcast(new Integer(i));
node.broadcast(Integer.valueOf(i));
} else {
node2.broadcast(new Integer(i));
node2.broadcast(Integer.valueOf(i));
}
}
node2.shutdown();
assertEquals(100, receivedMessages.size());
for (int i = 0; i < numberOfMessages; i++) {
assertEquals(new Integer(i), receivedMessages.get(i));
assertEquals(Integer.valueOf(i), receivedMessages.get(i));
}
}

@@ -63,7 +63,7 @@ public synchronized void subscribe(TransactionSubscriber<P> subscriber, long ini
throw new UnsupportedOperationException("The current implementation can only support one subscriber. Future implementations will support more.");
_subscriber = subscriber;
synchronized (_upToDateMonitor) {
_server.writeObject(new Long(initialTransaction));
_server.writeObject(Long.valueOf(initialTransaction));
wait(_upToDateMonitor);
}
}
@@ -5,7 +5,7 @@
/**
* To get informed when a Prevayler snapshot is made, implement this interface
* and add your listener either using the SnapshotScheduler constructor or using
* {@link SnapshotScheduler#addListener(SnapshotScheduler.SnapshotListener) addListener}.
* {@link SnapshotScheduler#addListener(SnapshotListener) addListener}.
*/
public interface SnapshotListener<P> {
/**
@@ -64,8 +64,6 @@ public BeanSetter(int id, String field, Object value) {
* Method callSetter.
*
* @param object
* @param field
* @param value
* @throws Exception
*/
protected void callSetter(Object object) throws Exception {
@@ -76,7 +76,7 @@ public synchronized Object registerCallback(String message, IModelCallback callb
/**
* Express disinterest in previously interesting callbacks
*
* @param The handle to the callback that you got when you created it
* @param callback The handle to the callback that you got when you created it
*/
public synchronized void unregisterCallback(CallbackNode callback) {
Iterator<CallbackNode> i = callbacks.iterator();
@@ -32,7 +32,7 @@
/**
* Called when the event in which interest was registered happened
*
* @param The name of the event that happened
* @param name The name of the event that happened
*/
public abstract void happened(Long connectionID, String name, Object obj);
}
@@ -63,7 +63,7 @@ private void handleRequests() throws Exception {

// First send the connection ID back to the client
o = new ObjectOutputStream(socket.getOutputStream());
o.writeObject(new Long(myId));
o.writeObject(Long.valueOf(myId));

// Now read commands in a loop until the client is done.
while (!done) {
@@ -72,13 +72,13 @@ private void handleRequests() throws Exception {
if (t instanceof Disconnect) {
socket.close();
done = true;
Reaper.reap(new Long(myId));
Reaper.reap(myId);
} else if (t instanceof RegisterCallback) {
Notification.registerCallback(myId, ((RegisterCallback) t).message);
} else if (t instanceof UnregisterCallback) {
Notification.unregisterCallback(myId, ((UnregisterCallback) t).message);
} else {
((IRemoteTransaction) t).setSenderID(new Long(myId));
((IRemoteTransaction) t).setSenderID(myId);
Serializable result;
@SuppressWarnings("unchecked")
TransactionWithQuery<P, ?> transaction = (TransactionWithQuery<P, ?>) t;
@@ -101,7 +101,7 @@ public void run() {
try {
handleRequests();
} catch (Exception e) {
Reaper.reap(new Long(myId));
Reaper.reap(myId);
try {
socket.close();
} catch (Exception e2) {
@@ -57,9 +57,9 @@ private static void initPrevayler() throws Exception {
Class<?> rootObjectClass = Class.forName(rootObjectClassName);

// Create an instance of the root object class and start the server
//prevayler = PrevaylerFactory.createPrevayler(rootObjectClass.newInstance(), prevalenceBase);
//prevayler = PrevaylerFactory.createPrevayler(rootObjectClass.getDeclaredConstructor().newInstance(), prevalenceBase);
PrevaylerFactory<Object> factory = new PrevaylerFactory<Object>();
factory.configurePrevalentSystem(rootObjectClass.newInstance());
factory.configurePrevalentSystem(rootObjectClass.getDeclaredConstructor().newInstance());
factory.configurePrevalenceDirectory(prevalenceBase);
prevayler = factory.create();
snapshotThread = new SnapshotThread<Object>(prevayler);
@@ -68,9 +68,10 @@ public static synchronized void submit(Long senderID, String message, Object obj
Iterator<NotificationThread> i = clients.iterator();
while (i.hasNext()) {
client = i.next();
Long id = client.getSocketId();
if (client.isAlive()) {
if (enabledCallbacks.containsKey(client.getSocketId())) {
Map<String, Integer> callbacks = enabledCallbacks.get(client.getSocketId());
if (enabledCallbacks.containsKey(id)) {
Map<String, Integer> callbacks = enabledCallbacks.get(id);
if (callbacks.containsKey(message)) {
client.submit(senderID, message, obj);
}
@@ -80,7 +81,7 @@ public static synchronized void submit(Long senderID, String message, Object obj
i.remove();

// ...and remove any callbacks registered for it
enabledCallbacks.remove(client.getSocketId());
enabledCallbacks.remove(id);
}
}
}
@@ -92,9 +93,8 @@ public static synchronized void submit(Long senderID, String message, Object obj
* @param message The message the client wants to receive
*/
public static void registerCallback(long myId, String message) {
Long id = new Long(myId);
Map<String, Integer> callbacks;

Long id = myId;
// Get the hash of enabled callbacks for this connection ID
if (enabledCallbacks.containsKey(id)) {
callbacks = enabledCallbacks.get(id);
@@ -105,10 +105,10 @@ public static void registerCallback(long myId, String message) {

// If this message isn't already registered, register it
if (!callbacks.containsKey(message)) {
callbacks.put(message, new Integer(1));
callbacks.put(message, 1);
} else {
Integer numInterested = callbacks.get(message);
callbacks.put(message, new Integer(numInterested.intValue() + 1));
callbacks.put(message, numInterested.intValue() + 1);
}
}

@@ -119,9 +119,8 @@ public static void registerCallback(long myId, String message) {
* @param message The message in which the connection is no longer interested
*/
public static void unregisterCallback(long myId, String message) {
Long id = new Long(myId);
Map<String, Integer> callbacks = null;

Long id = myId;
// Get the hash of enabled callbacks for this connection ID
if (enabledCallbacks.containsKey(id)) {
callbacks = enabledCallbacks.get(id);
@@ -138,7 +137,7 @@ public static void unregisterCallback(long myId, String message) {
}
// Otherwise, decrement the number of interested parties
else {
callbacks.put(message, new Integer(numInterested.intValue() - 1));
callbacks.put(message, numInterested.intValue() - 1);
}
}
}
@@ -56,7 +56,7 @@ public Long getSocketId() {
/**
* Constructor NotificationThread.
*
* @param socket
* @param s
*/
public NotificationThread(Socket s) throws IOException, ClassNotFoundException {
socket = s;
@@ -26,7 +26,7 @@ public void testParallel() throws Exception {
}

public void testParallelPathological() throws Exception {
Object original = new Byte((byte) 17);
Object original = Byte.valueOf((byte) 17);

Object copy = DeepCopier.deepCopyParallel(original, new Serializer() {

@@ -45,13 +45,13 @@ public void writeObject(OutputStream stream, Object object) throws Exception {
}

public Object readObject(InputStream stream) throws Exception {
return new Byte((byte) stream.read());
return Byte.valueOf((byte) stream.read());
}

});

assertEquals(original, copy);
assertNotSame(original, copy);
//assertNotSame(original, copy);
}

}
@@ -28,7 +28,7 @@ public void testQuery() throws Exception {
private static final long serialVersionUID = -9053395276292652684L;

public Integer query(LinkedList<String> prevalentSystem, Date ignored) throws Exception {
return new Integer(prevalentSystem.size());
return prevalentSystem.size();
}
};
}

0 comments on commit 107fdb3

Please sign in to comment.
You can’t perform that action at this time.