Skip to content

Commit

Permalink
Merge pull request prevayler#3 from Navigateur/master
Browse files Browse the repository at this point in the history
Transaction filtering removed, pls review any changes, test
  • Loading branch information
klauswuestefeld committed Nov 9, 2011
2 parents f10ee59 + 63b3db6 commit feb1f3d
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 225 deletions.
23 changes: 15 additions & 8 deletions CHANGES.txt
Expand Up @@ -17,18 +17,25 @@ Updated demo code shows the type-safe usage.
-----------------------------------------
Transactions can now be executed directly

Transactions can now allow references passed in to be copied naturally,
allowing their contents to change, as with Java methods. Previous versions
allowed only a deserialized copy to be executed.
Transactions can now allow references passed in to be used naturally, allowing
their contents to change as with Java methods. Previous versions allowed only
a freshly deserialized copy to be executed.

Activated via:
It is activated via:

PrevaylerFactory#configureTransactionDeepCopy(false);

It preserves the same transaction filtering and writing to disk before
execution. However, unrecoverable changes and unrecoverable uses of reference
equality do not fail inside the transaction as they would upon recovery, as
they do when this is "true", which is still the default setting.
However, unrecoverable changes to the prevalent system and unrecoverable uses
of reference equality inside transactions will not fail fast as they would upon
recovery, and as they will when this is set to "true", which is still the default.

--------------------------------
Transaction filtering is no more

Transaction filtering is no longer a feature in Prevayler. Calls to
PrevaylerFactory#configureTransactionFiltering(boolean) will no longer compile.




===========================================
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/prevayler/Prevayler.java
Expand Up @@ -6,7 +6,6 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;


/** Implementations of this interface can provide transparent persistence and replication to all Business Objects in a Prevalent System. ALL operations that alter the observable state of the Prevalent System must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute(...) methods.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/prevayler/Query.java
Expand Up @@ -8,7 +8,7 @@
import java.util.Date;

/** Represents a query that can be executed on a Prevalent System.
* @see org.prevayler.Prevayler#execute(Query<P,R>)
* @see org.prevayler.Prevayler#execute(Query)
*/
public interface Query<P,R> extends Serializable{

Expand Down
Expand Up @@ -4,7 +4,6 @@

package org.prevayler;

import java.io.Serializable;
import java.util.Date;

/** The same as TransactionWithQuery except it does not throw Exception when executed.
Expand All @@ -13,7 +12,7 @@
public interface SureTransactionWithQuery<P,R> extends TransactionWithQuery<P,R>{

/** The same as TransactionWithQuery.executeAndQuery(P, Date) except it does not throw Exception when executed.
* @see TransactionWithQuery#executeAndQuery(P, Date)
* @see TransactionWithQuery#executeAndQuery(Object, Date)
*/
public R executeAndQuery(P prevalentSystem, Date executionTime);

Expand Down
Expand Up @@ -2,7 +2,6 @@

import java.io.OutputStream;
import java.io.InputStream;
import java.io.Serializable;

/**
* A strategy for writing objects to and reading objects from streams. Implementations <b>must</b> be safe for
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/java/org/prevayler/implementation/Capsule.java
@@ -1,6 +1,5 @@
package org.prevayler.implementation;

import org.prevayler.Transaction;
import org.prevayler.foundation.Chunk;
import org.prevayler.foundation.serialization.Serializer;

Expand Down Expand Up @@ -50,15 +49,15 @@ public Object deserialize(Serializer journalSerializer) {
}

/**
* Executes a freshly deserialized copy of the transaction if this is being called via the royal food taster or if <code>configureTransactionDeepCopy</code> wasn't set to <code>false</code> on your <code>PrevaylerFactory</code>. Otherwise, this will execute the transaction directly. The execution will synchronize on the prevalentSystem.
* Executes a freshly deserialized copy of the transaction by default. If <code>configureTransactionDeepCopy</code> was set to <code>true</code> on your <code>PrevaylerFactory</code>, this will execute the transaction directly. The execution will synchronize on the prevalentSystem.
*/
public void executeOn(Object prevalentSystem, Date executionTime, Serializer journalSerializer, boolean guaranteeTransactionDeepCopy) {
public void executeOn(Object prevalentSystem, Date executionTime, Serializer journalSerializer) {
Object transaction;
if(guaranteeTransactionDeepCopy || _transaction == null){
transaction = deserialize(journalSerializer);
if(_transaction != null){
transaction = _transaction;
}
else{
transaction = _transaction;
transaction = deserialize(journalSerializer);
}

synchronized (prevalentSystem) {
Expand Down
Expand Up @@ -11,7 +11,6 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;

public class PrevalentSystemGuard<P> implements TransactionSubscriber {
Expand All @@ -20,7 +19,6 @@ public class PrevalentSystemGuard<P> implements TransactionSubscriber {
private long _systemVersion; // All access is synchronized on "this"
private boolean _ignoreRuntimeExceptions; // All access is synchronized on "this"
private final Serializer _journalSerializer;
private boolean _guaranteeTransactionDeepCopy = false;

public PrevalentSystemGuard(P prevalentSystem, long systemVersion, Serializer journalSerializer) {
_prevalentSystem = prevalentSystem;
Expand All @@ -37,10 +35,6 @@ public P prevalentSystem() {
return _prevalentSystem;
}
}

public void guaranteeTransactionDeepCopy(){
_guaranteeTransactionDeepCopy = true;
}

public void subscribeTo(TransactionPublisher publisher) throws IOException, ClassNotFoundException {
long initialTransaction;
Expand Down Expand Up @@ -76,7 +70,7 @@ public void receive(TransactionTimestamp transactionTimestamp) {
try {
// Don't synchronize on _prevalentSystem here so that the capsule can deserialize a fresh
// copy of the transaction without blocking queries.
capsule.executeOn(_prevalentSystem, executionTime, _journalSerializer, _guaranteeTransactionDeepCopy);
capsule.executeOn(_prevalentSystem, executionTime, _journalSerializer);
} catch (RuntimeException rx) {
if (!_ignoreRuntimeExceptions) throw rx; //TODO Guarantee that transactions received from pending transaction recovery don't ever throw RuntimeExceptions. Maybe use a wrapper for that.
} catch (Error error) {
Expand Down
Expand Up @@ -16,7 +16,6 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

public class PrevaylerImpl<P> implements Prevayler<P>{

Expand Down
Expand Up @@ -3,7 +3,6 @@
import org.prevayler.Transaction;
import org.prevayler.foundation.serialization.Serializer;

import java.io.Serializable;
import java.util.Date;

class TransactionCapsule<P> extends Capsule{
Expand Down
Expand Up @@ -3,7 +3,6 @@
import org.prevayler.TransactionWithQuery;
import org.prevayler.foundation.serialization.Serializer;

import java.io.Serializable;
import java.util.Date;

class TransactionWithQueryCapsule<P,R> extends Capsule{
Expand Down
Expand Up @@ -12,14 +12,12 @@
import org.prevayler.implementation.TransactionTimestamp;
import org.prevayler.implementation.clock.PausableClock;
import org.prevayler.implementation.journal.Journal;
import org.prevayler.implementation.publishing.censorship.TransactionCensor;

import java.io.IOException;

public class CentralPublisher extends AbstractPublisher {

private final PausableClock _pausableClock;
private final TransactionCensor _censor;
private final Journal _journal;

private volatile int _pendingPublications = 0;
Expand All @@ -30,11 +28,10 @@ public class CentralPublisher extends AbstractPublisher {
private final Object _nextTurnMonitor = new Object();


public CentralPublisher(Clock clock, TransactionCensor censor, Journal journal) {
public CentralPublisher(Clock clock, Journal journal) {
super(new PausableClock(clock));
_pausableClock = (PausableClock) _clock; //This is just to avoid casting the inherited _clock every time.

_censor = censor;
_journal = journal;
}

Expand All @@ -60,18 +57,16 @@ public void publish(Capsule capsule) {


private void publishWithoutWorryingAboutNewSubscriptions(Capsule capsule) {
TransactionGuide guide = approve(capsule);
TransactionGuide guide = guideFor(capsule);
_journal.append(guide);
notifySubscribers(guide);
}

private TransactionGuide approve(Capsule capsule) {
private TransactionGuide guideFor(Capsule capsule) {
synchronized (_nextTurnMonitor) {
TransactionTimestamp timestamp = new TransactionTimestamp(capsule, _nextTransaction, _pausableClock.realTime());

_censor.approve(timestamp);

// Only count this transaction once approved.
// Count this transaction
Turn turn = _nextTurn;
_nextTurn = _nextTurn.next();
_nextTransaction++;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -10,7 +10,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
Expand Down
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

public class NullSnapshotManager<P> extends GenericSnapshotManager<P>{

Expand Down
Expand Up @@ -14,7 +14,6 @@ public PrevaylerQuerySubject() throws Exception {
PrevaylerFactory<QuerySystem> factory = new PrevaylerFactory<QuerySystem>();
factory.configurePrevalentSystem(new QuerySystem());
factory.configurePrevalenceDirectory(PREVALENCE_BASE);
factory.configureTransactionFiltering(false);
prevayler = factory.create();
}

Expand Down
Expand Up @@ -43,7 +43,6 @@ private void initializePrevayler() throws Exception {
factory.configurePrevalentSystem(new TransactionSystem());
factory.configurePrevalenceDirectory(_journalDirectory);
factory.configureJournalSerializer("journal", (Serializer) Class.forName(_journalSerializer).newInstance());
factory.configureTransactionFiltering(false);
prevayler = factory.create(); //No snapshot is generated by the test.
}

Expand Down

0 comments on commit feb1f3d

Please sign in to comment.