All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atomikos.recovery.imp.OltpLogImp Maven / Gradle / Ivy

package com.atomikos.recovery.imp;

import com.atomikos.icatch.CoordinatorLogEntry;
import com.atomikos.recovery.Repository;
import com.atomikos.recovery.LogException;
import com.atomikos.recovery.LogReadException;
import com.atomikos.recovery.OltpLog;

public class OltpLogImp implements OltpLog {


	private Repository repository;

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	
	@Override
	public void write(CoordinatorLogEntry coordinatorLogEntry)
			throws IllegalStateException, LogException {
		assertEntryIsAllowedInCurrentState(coordinatorLogEntry);
		repository.put(coordinatorLogEntry.id, coordinatorLogEntry);
	}

	private void assertEntryIsAllowedInCurrentState(CoordinatorLogEntry coordinatorLogEntry) throws IllegalStateException, LogReadException {
		CoordinatorLogEntry existing = repository
				.get(coordinatorLogEntry.id);
		
		if (!coordinatorLogEntry.transitionAllowedFrom(existing)) {
			String existingState = "NONE";
			if (existing != null) {
				existingState = existing.getResultingState().toString();
			}
			throw new IllegalStateException("Existing entry: " + existingState + 
					" incompatible with new entry: " + coordinatorLogEntry.getResultingState());
		}
	}


	@Override
	public void close() {
		repository.close();
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy