1 24 package org.objectweb.jalisto.se.test.threads; 25 26 import org.objectweb.jalisto.se.JalistoFactory; 27 import org.objectweb.jalisto.se.api.Session; 28 import org.objectweb.jalisto.se.api.Transaction; 29 import org.objectweb.jalisto.se.test.data.Book; 30 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 public abstract class BookClientThread extends Thread { 36 37 public BookClientThread(String jalistoPropertiesFilename, int numClient, 38 int nbrBook, int nbrAction, int nbrIteration) { 39 this.jalistoPropertiesFilename = jalistoPropertiesFilename; 40 this.nbrBook = nbrBook; 41 this.numClient = numClient; 42 this.nbrCreate = nbrAction; 43 this.nbrRead = nbrAction; 44 this.nbrUpdate = nbrAction; 45 this.nbrDelete = nbrAction; 46 this.nbrIteration = nbrIteration; 47 this.continueWorking = true; 48 this.withExtent = false; 49 oids = new ArrayList (); 50 } 51 52 public void define(boolean withDefineClass) { 53 System.out.println("JalistoClientThread " + numClient + " : define"); 54 session = JalistoFactory.getSession(jalistoPropertiesFilename); 55 session.openSession(); 56 tx = session.currentTransaction(); 57 if (withDefineClass) { 58 session.defineClass(Book.getMetaDescription()); 59 } 60 } 61 62 public void cleanUp() { 63 tx.begin(); 64 Iterator extent = session.getExtent(Book.class).readFully().iterator(); 65 while (extent.hasNext()) { 66 session.deleteObjectByOid(extent.next()); 67 } 68 tx.commit(); 69 } 70 71 public void populate() { 72 System.out.println("JalistoClientThread " + numClient + " : populateJalisto"); 73 tx.begin(); 74 oids.clear(); 75 if (nbrBook > 0) { 76 for (int i = 0; i < nbrBook; i++) { 77 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 78 } 79 } else { 80 oids.addAll(session.getExtent(Book.class).readFully().collection()); 81 } 82 tx.commit(); 83 } 84 85 public void run() { 86 try { 87 stabilityTest(); 88 } catch (Exception e) { 89 e.printStackTrace(); 90 } 91 if ((tx != null) && tx.isActive()) { 92 tx.rollback(); 93 } 94 if (session != null) { 95 session.closeSession(); 96 } 97 } 98 99 public void stopWorking() { 100 continueWorking = false; 101 } 102 103 public Session getSession() { 104 return session; 105 } 106 107 public abstract void stabilityTest(); 108 109 112 113 public List getOids() { 114 return oids; 115 } 116 117 public void setOids(List oids) { 118 this.oids = oids; 119 } 120 121 public void setWithTimer(boolean withTimer) { 122 this.withTimer = withTimer; 123 } 124 125 public void setWithRead(boolean withRead) { 126 this.withRead = withRead; 127 } 128 129 public void setNbrCreate(int nbrCreate) { 130 this.nbrCreate = nbrCreate; 131 } 132 133 public void setNbrDelete(int nbrDelete) { 134 this.nbrDelete = nbrDelete; 135 } 136 137 public void setNbrRead(int nbrRead) { 138 this.nbrRead = nbrRead; 139 } 140 141 public void setNbrUpdate(int nbrUpdate) { 142 this.nbrUpdate = nbrUpdate; 143 } 144 145 public boolean isWithExtent() { 146 return withExtent; 147 } 148 149 public void setWithExtent(boolean withExtent) { 150 this.withExtent = withExtent; 151 } 152 153 154 protected String jalistoPropertiesFilename; 155 protected int numClient; 156 157 protected int nbrBook; 158 protected int nbrIteration; 159 protected int nbrCreate; 160 protected int nbrRead; 161 protected int nbrUpdate; 162 protected int nbrDelete; 163 protected boolean withExtent; 164 165 protected boolean withTimer = true; 166 protected boolean withRead = false; 167 168 protected boolean continueWorking; 169 170 protected Session session; 171 protected Transaction tx; 172 173 protected List oids; 174 } 175 | Popular Tags |