Last active
August 29, 2015 14:08
-
-
Save sormuras/3f596c5c2d76a2869ce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package databench.prevayler; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.prevayler.Prevayler; | |
import org.prevayler.contrib.p8.P8; | |
import org.prevayler.contrib.p8.SynchronizedPrevayler; | |
import databench.AccountStatus; | |
import databench.Bank; | |
import databench.SingleVMBank; | |
import databench.database.FolderDatabase; | |
public class P8Subject implements Bank<Integer>, SingleVMBank { | |
private static final long serialVersionUID = 1L; | |
private final Prevayler<Map<Integer, PrevaylerAccount>> prevayler; | |
public P8Subject() { | |
try { | |
Map<Integer, PrevaylerAccount> prevalentSystem = new HashMap<>(); | |
File baseFolder = new File(FolderDatabase.path()); | |
String snapshot = "snap.shot"; | |
String journalName = "slice.journal"; | |
long journalSize = 100 * 1024 * 1024; // increase if not enough | |
P8<Map<Integer, PrevaylerAccount>> p8 = new P8<>(prevalentSystem, baseFolder, snapshot, journalName, journalSize); | |
prevayler = "multi thread".isEmpty() ? new SynchronizedPrevayler<>(p8) : p8; | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public Integer[] setUp(Integer numberOfAccounts) { | |
return prevayler | |
.execute(new CreateAccountsTransaction(numberOfAccounts)); | |
} | |
@Override | |
public void warmUp() { | |
} | |
@Override | |
public String additionalVMParameters(boolean forMultipleVMs) { | |
return ""; | |
} | |
public void transfer(Integer from, Integer to, int amount) { | |
prevayler.execute(new TransferTransaction(from, to, amount)); | |
} | |
public AccountStatus getAccountStatus(Integer id) { | |
try { | |
return prevayler.execute(new GetAccountStatusQuery(id)); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public void tearDown() { | |
try { | |
prevayler.close(); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment