1 24 package org.objectweb.jalisto.test.core.single; 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 import org.objectweb.jalisto.se.test.threads.BookClientBasic; 31 32 import java.util.ArrayList ; 33 import java.util.Collections ; 34 import java.util.List ; 35 36 public class MultiUsersTestReadDatas { 37 public static void main(String [] args) { 38 String jalistoPropertiesFilename = args[0]; 39 boolean sameDatas = args[1].equalsIgnoreCase("same"); 40 int nbrClient = Integer.parseInt(args[2]); 41 int nbrBook = Integer.parseInt(args[3]); 42 int nbrAction = Integer.parseInt(args[4]); 43 int nbrIteration = Integer.parseInt(args[5]); 44 45 ArrayList threads = new ArrayList (); 46 List oids = null; 47 if (sameDatas) { 48 oids = populate(jalistoPropertiesFilename, nbrBook); 49 oids = Collections.synchronizedList(oids); 50 } 51 52 for (int i = 0; i < nbrClient; i++) { 53 BookClientBasic c = new BookClientBasic(jalistoPropertiesFilename, i, nbrBook, nbrAction, nbrIteration); 54 threads.add(c); 55 c.define(true); 56 if (sameDatas) { 57 c.setNbrCreate(5); 59 c.setNbrUpdate(5); 60 c.setNbrDelete(5); 61 c.setOids(oids); 63 } else { 64 c.setNbrCreate(nbrAction); 65 c.setNbrUpdate(nbrAction); 66 c.setNbrDelete(nbrAction); 67 c.define(true); 68 c.populate(); 69 } 70 } 71 72 try { 73 for (int i = 0; i < nbrClient; i++) { 74 ((BookClientBasic) threads.get(i)).start(); 75 Thread.sleep(500); 76 } 77 } catch (Exception e) { 78 e.printStackTrace(); 79 } 80 } 81 82 public static List populate(String jalistoPropertiesFilename, int nbrBook) { 83 Session session = JalistoFactory.getSession(jalistoPropertiesFilename); 84 session.openSession(); 85 Transaction tx = session.currentTransaction(); 86 session.defineClass(Book.getMetaDescription()); 87 List oids = new ArrayList (); 88 tx.begin(); 89 for (int i = 0; i < nbrBook; i++) { 90 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 91 } 92 tx.commit(); 93 session.closeSession(); 94 return oids; 95 } 96 } 97 | Popular Tags |