[infinispan-commits] Infinispan SVN: r1113 - trunk/demos/ec2/src/main/java/org/infinispan/ec2demo.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Sun Nov 8 06:34:51 EST 2009
Author: noelo
Date: 2009-11-08 06:34:50 -0500 (Sun, 08 Nov 2009)
New Revision: 1113
Modified:
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java
Log:
Added random query functionality
Modified: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java 2009-11-08 11:33:36 UTC (rev 1112)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java 2009-11-08 11:34:50 UTC (rev 1113)
@@ -12,6 +12,8 @@
import java.io.IOException;
import java.util.List;
+import java.util.Map;
+import java.util.Random;
/**
* @author noconnor at redhat.com
@@ -37,37 +39,66 @@
influenzaCache = cbuilder.getCacheManager().getCache("InfluenzaCache");
proteinCache = cbuilder.getCacheManager().getCache("ProteinCache");
nucleiodCache = cbuilder.getCacheManager().getCache("NucleotideCache");
-
+
npParser = new Nucleotide_Protein_Parser();
iParser = new Influenza_Parser();
System.out.println("Caches created....Starting CacheManager");
cbuilder.getCacheManager().start();
+ int loadLimit = config.getInt("count");
+
+ // Dump the cluster list
List<Address> z = cbuilder.getCacheManager().getMembers();
for (Address k : z)
if (k != null)
System.out.println("Cache Address=" + k.toString());
System.out.println("Parsing files....");
-
+
if (config.getString("ifile") != null) {
myLogger.info("Parsing Influenza data");
List<Influenza_N_P_CR_Element> iList = iParser.parseFile(config.getString("ifile"));
- System.out.println("About to load " + iList.size() + " influenza elements into influenzaCache");
- int loopCount = 0;
- influenzaCache.startBatch();
- for (Influenza_N_P_CR_Element x : iList) {
- influenzaCache.put(x.getGanNucleoid(), x);
- loopCount++;
- if ((loopCount % 5000) == 0) {
- System.out.println("Added " + loopCount + " Influenza records");
- influenzaCache.endBatch(true);
- influenzaCache.startBatch();
+
+ boolean rQuery = config.getBoolean("randomquery");
+ int lSize = iList.size() - 1;
+
+ if (rQuery) {
+ System.out.println("Performing random queries");
+ Random randomGenerator = new Random();
+ while (true) {
+ int currRec = randomGenerator.nextInt(lSize);
+ Influenza_N_P_CR_Element curreElem = iList.get(currRec);
+
+ this.searchCache(curreElem.getGanNucleoid());
+
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException ex) {
+ // do nothing, yea I know its naughty...
+ }
}
+
+ } else {
+ System.out.println("About to load " + iList.size() + " influenza elements into influenzaCache");
+ int loopCount = 0;
+ influenzaCache.startBatch();
+ for (Influenza_N_P_CR_Element x : iList) {
+ influenzaCache.put(x.getGanNucleoid(), x);
+ loopCount++;
+ if ((loopCount % 5000) == 0) {
+ System.out.println("Added " + loopCount + " Influenza records");
+ influenzaCache.endBatch(true);
+ influenzaCache.startBatch();
+ }
+ if (loopCount == loadLimit) {
+ System.out.println("Limited to " + loadLimit + " records");
+ break;
+ }
+ }
+ influenzaCache.endBatch(true);
+ System.out.println("Loaded " + influenzaCache.size() + " influenza elements into influenzaCache");
}
- influenzaCache.endBatch(true);
- System.out.println("Loaded " + influenzaCache.size() + " influenza elements into influenzaCache");
}
if (config.getString("pfile") != null) {
@@ -77,13 +108,17 @@
int loopCount = 0;
proteinCache.startBatch();
for (Nucleotide_Protein_Element x : npList) {
- proteinCache.put(x.getGenbankAccessionNumber(),x);
+ proteinCache.put(x.getGenbankAccessionNumber(), x);
loopCount++;
if ((loopCount % 5000) == 0) {
System.out.println("Added " + loopCount + " protein records");
proteinCache.endBatch(true);
proteinCache.startBatch();
}
+ if (loopCount == loadLimit) {
+ System.out.println("Limited to " + loadLimit + " records");
+ break;
+ }
}
proteinCache.endBatch(true);
System.out.println("Loaded " + proteinCache.size() + " protein elements into ProteinCache");
@@ -96,17 +131,20 @@
int loopCount = 0;
nucleiodCache.startBatch();
for (Nucleotide_Protein_Element x : npList) {
- nucleiodCache.put(x.getGenbankAccessionNumber(),x);
+ nucleiodCache.put(x.getGenbankAccessionNumber(), x);
loopCount++;
if ((loopCount % 5000) == 0) {
System.out.println("Added " + loopCount + " Nucleotide records");
nucleiodCache.endBatch(true);
nucleiodCache.startBatch();
}
+ if (loopCount == loadLimit) {
+ System.out.println("Limited to " + loadLimit + " records");
+ break;
+ }
}
nucleiodCache.endBatch(true);
- System.out
- .println("Loaded " + nucleiodCache.size() + " nucleotide elements into NucleiodCache");
+ System.out.println("Loaded " + nucleiodCache.size() + " nucleotide elements into NucleiodCache");
}
System.out.println("Parsing files....Done");
@@ -116,4 +154,31 @@
}
}
+ public void searchCache(String inGBAN) {
+ myLogger.trace("Searching influenzaCache for "+inGBAN);
+ // Find the virus details
+ Influenza_N_P_CR_Element myRec = influenzaCache.get(inGBAN);
+
+ if (myRec != null) {
+ System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ System.out.println("Virus Details->" + myRec);
+ myLogger.trace("Searching nucleiodCache for "+myRec.getGanNucleoid());
+ Nucleotide_Protein_Element nucldet = nucleiodCache.get(myRec.getGanNucleoid());
+ System.out.println("Nucleotide detils->" + nucldet);
+
+ // Display the protein details
+ Map<String, String> myProt = myRec.getProtein_Data();
+ for (String x : myProt.keySet()) {
+ myLogger.trace("Searching proteinCache for "+x);
+ Nucleotide_Protein_Element myProtdet = proteinCache.get(x);
+ System.out.println("Protein->" + myProtdet);
+ String protein_CR = myProt.get(x);
+ System.out.println("Protein coding region->" + protein_CR);
+ }
+ System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ } else{
+ myLogger.trace("No virus data found for "+inGBAN);
+ System.out.println("No virus data found for "+inGBAN);
+ }
+ }
}
More information about the infinispan-commits
mailing list