<commit_before>package org.prevayler.implementation;

import org.prevayler.Clock;
import org.prevayler.Query;
import org.prevayler.foundation.Cool;
import org.prevayler.foundation.DeepCopier;
import org.prevayler.foundation.serialization.Serializer;
import org.prevayler.implementation.publishing.TransactionPublisher;
import org.prevayler.implementation.publishing.TransactionSubscriber;
import org.prevayler.implementation.snapshot.GenericSnapshotManager;

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

public class PrevalentSystemGuard<P> implements TransactionSubscriber {

	private P _prevalentSystem; // All access to field is synchronized on "this", and all access to object is synchronized on itself; "this" is always locked before the object
	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;
	
	public PrevalentSystemGuard(P prevalentSystem, long systemVersion, Serializer journalSerializer) {
		_prevalentSystem = prevalentSystem;
		_systemVersion = systemVersion;
		_ignoreRuntimeExceptions = false;
		_journalSerializer = journalSerializer;
	}

	public P prevalentSystem() {
        synchronized (this) {
            if (_prevalentSystem == null) {
                throw new Error("Prevayler is no longer allowing access to the prevalent system due to an Error thrown from an earlier transaction.");
            }
            return _prevalentSystem;
        }
	}

	public void guaranteeTransactionDeepCopy(){
		_guaranteeTransactionDeepCopy=true;
	}
	
	public void subscribeTo(TransactionPublisher publisher) throws IOException, ClassNotFoundException {
		long initialTransaction;
		synchronized (this) {
			_ignoreRuntimeExceptions = true;     //During pending transaction recovery (rolling forward), RuntimeExceptions are ignored because they were already thrown and handled during the first transaction execution.
			initialTransaction = _systemVersion + 1;
		}

		publisher.subscribe(this, initialTransaction);

		synchronized (this) {
			_ignoreRuntimeExceptions = false;
		}
	}

	public void receive(TransactionTimestamp transactionTimestamp) {
		Capsule capsule = transactionTimestamp.capsule();
		long systemVersion = transactionTimestamp.systemVersion();
		Date executionTime = transactionTimestamp.executionTime();

		synchronized (this) {
            if (_prevalentSystem == null) {
                throw new Error("Prevayler is no longer processing transactions due to an Error thrown from an earlier transaction.");
            }<commit_msg>Direct transactions option<commit_after>package org.prevayler.implementation;

import org.prevayler.Clock;
import org.prevayler.Query;
import org.prevayler.foundation.Cool;
import org.prevayler.foundation.DeepCopier;
import org.prevayler.foundation.serialization.Serializer;
import org.prevayler.implementation.publishing.TransactionPublisher;
import org.prevayler.implementation.publishing.TransactionSubscriber;
import org.prevayler.implementation.snapshot.GenericSnapshotManager;

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

public class PrevalentSystemGuard<P> implements TransactionSubscriber {

	private P _prevalentSystem; // All access to field is synchronized on "this", and all access to object is synchronized on itself; "this" is always locked before the object
	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;
		_systemVersion = systemVersion;
		_ignoreRuntimeExceptions = false;
		_journalSerializer = journalSerializer;
	}

	public P prevalentSystem() {
        synchronized (this) {
            if (_prevalentSystem == null) {
                throw new Error("Prevayler is no longer allowing access to the prevalent system due to an Error thrown from an earlier transaction.");
            }
            return _prevalentSystem;
        }
	}

	public void guaranteeTransactionDeepCopy(){
		_guaranteeTransactionDeepCopy = true;
	}
	
	public void subscribeTo(TransactionPublisher publisher) throws IOException, ClassNotFoundException {
		long initialTransaction;
		synchronized (this) {
			_ignoreRuntimeExceptions = true;     //During pending transaction recovery (rolling forward), RuntimeExceptions are ignored because they were already thrown and handled during the first transaction execution.
			initialTransaction = _systemVersion + 1;
		}

		publisher.subscribe(this, initialTransaction);

		synchronized (this) {
			_ignoreRuntimeExceptions = false;
		}
	}

	public void receive(TransactionTimestamp transactionTimestamp) {
		Capsule capsule = transactionTimestamp.capsule();
		long systemVersion = transactionTimestamp.systemVersion();
		Date executionTime = transactionTimestamp.executionTime();

		synchronized (this) {
            if (_prevalentSystem == null) {
                throw new Error("Prevayler is no longer processing transactions due to an Error thrown from an earlier transaction.");
            }
{'fraction_non_alphanumeric': 0.06681310635182135, 'fraction_numerical': 0.0003660992128866923, 'mean_word_length': 4.697601668404588, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2372276', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1331, 'n_words': 426}