[infinispan-commits] Infinispan SVN: r1055 - in trunk/demos/ec2: src and 5 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Oct 29 00:15:52 EDT 2009
Author: noelo
Date: 2009-10-29 00:15:51 -0400 (Thu, 29 Oct 2009)
New Revision: 1055
Added:
trunk/demos/ec2/src/
trunk/demos/ec2/src/main/
trunk/demos/ec2/src/main/java/
trunk/demos/ec2/src/main/java/org/
trunk/demos/ec2/src/main/java/org/infinispan/
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/CacheBuilder.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfinispanFluDemo.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaVirusCache.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_N_P_CR_Element.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_Parser.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/NucleotideCache.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Element.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Parser.java
trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/ProteinCache.java
Log:
Initial addition to SVN
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/CacheBuilder.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/CacheBuilder.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/CacheBuilder.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.log4j.*;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class CacheBuilder {
+ Logger myLogger = Logger.getLogger(CacheBuilder.class);
+ private CacheManager cache_manager;
+
+ public CacheBuilder(String configFile) throws IOException {
+ String jGroupsFile = System.getProperty("EC2Demo-jgroups-config");
+ if (jGroupsFile==null)
+ throw new RuntimeException("Need to set system property EC2Demo-jgroups-config to point to the jgroups configuration file");
+
+ GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
+ gc.setClusterName("infinispan-demo-cluster");
+ gc.setTransportClass(JGroupsTransport.class.getName());
+ Properties p = new Properties();
+ p.setProperty("configurationFile",jGroupsFile);
+ gc.setTransportProperties(p);
+
+ Configuration c = new Configuration();
+ c.setCacheMode(Configuration.CacheMode.DIST_SYNC);
+ c.setExposeJmxStatistics(true);
+ c.setUnsafeUnreliableReturnValues(true);
+ c.setNumOwners(3);
+ c.setL1CacheEnabled(true);
+ c.setInvocationBatchingEnabled(true);
+ c.setUseReplQueue(true);
+ c.setL1Lifespan(6000000);
+ cache_manager = new DefaultCacheManager(gc, c,false);
+ }
+
+ public CacheManager getCacheManager() {
+ return this.cache_manager;
+ }
+
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/CacheBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfinispanFluDemo.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfinispanFluDemo.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfinispanFluDemo.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,109 @@
+package org.infinispan.ec2demo;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+import java.util.Map;
+import org.apache.log4j.*;
+import org.jboss.logging.Logger;
+import org.xml.sax.SAXException;
+import com.martiansoftware.jsap.FlaggedOption;
+import com.martiansoftware.jsap.JSAP;
+import com.martiansoftware.jsap.JSAPException;
+import com.martiansoftware.jsap.JSAPResult;
+import com.martiansoftware.jsap.Parameter;
+import com.martiansoftware.jsap.SimpleJSAP;
+import com.martiansoftware.jsap.Switch;
+
+/**
+ *
+ */
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class InfinispanFluDemo {
+
+ /**
+ * @param args
+ * @throws InterruptedException
+ * @throws ParseException
+ * @throws JSAPException
+ * @throws SAXException
+ */
+ public static void main(String[] args) throws JSAPException {
+ SimpleJSAP jsap = new SimpleJSAP("InfinispanFluDemo", "Parse the Influenze data and store in cache ",
+ new Parameter[] {
+ new FlaggedOption("InfinispanCfg", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'c',
+ JSAP.NO_LONGFLAG, "Location of Infinispan config file"),
+ new FlaggedOption("ifile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'i', JSAP.NO_LONGFLAG,
+ "Location of influenza.dat"),
+ new FlaggedOption("pfile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'p', JSAP.NO_LONGFLAG,
+ "location of influenza_aa.dat."),
+ new Switch("query", 'q', "true", "Enable query cli"),
+ new FlaggedOption("nfile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'n', JSAP.NO_LONGFLAG,
+ "Location of influenza_na.dat") });
+ if (jsap.messagePrinted())
+ System.exit(1);
+
+
+ JSAPResult config = jsap.parse(args);
+ InfluenzaDataLoader fluDemo = new InfluenzaDataLoader();
+ try {
+ fluDemo.populateCache(config);
+ } catch (SAXException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ System.exit(1);
+ }
+
+ while (true) {
+
+ if (config.getBoolean("query")) {
+ System.out.print("Enter Virus Genbank Accession Number: ");
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String GBAN = null;
+ try {
+ GBAN = br.readLine();
+ } catch (IOException ioe) {
+ System.out.println("IO error trying to read Genbank Accession Number!");
+ System.exit(1);
+ }
+ System.out.println("Searching cache...");
+
+ // Find the virus details
+ Influenza_N_P_CR_Element myRec = fluDemo.influenzaCache.get(GBAN);
+
+ if (myRec != null) {
+ System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ System.out.println("Virus Details->" + myRec);
+ Nucleotide_Protein_Element nucldet = fluDemo.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()) {
+ Nucleotide_Protein_Element myProtdet = fluDemo.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
+ System.out.println("No virus found");
+ } else {
+ try {
+ Thread.currentThread().sleep(2000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ System.out.println("Protein Cache Size-->" + fluDemo.proteinCache.size());
+ System.out.println("Influenza Cache Size-->" + fluDemo.influenzaCache.size());
+ System.out.println("Nucleotide Cache Size-->" + fluDemo.nucleiodCache.size());
+ }
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfinispanFluDemo.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,118 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.IOException;
+import java.util.List;
+import org.infinispan.Cache;
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.statetransfer.StateTransferException;
+import org.apache.log4j.*;
+import org.xml.sax.SAXException;
+import com.martiansoftware.jsap.JSAPResult;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class InfluenzaDataLoader {
+ public CacheBuilder cbuilder;
+ public Cache<String, Influenza_N_P_CR_Element> influenzaCache;
+ public Cache<String, Nucleotide_Protein_Element> proteinCache;
+ public Cache<String, Nucleotide_Protein_Element> nucleiodCache;
+ private Nucleotide_Protein_Parser npParser;
+ private Influenza_Parser iParser;
+
+ Logger myLogger = Logger.getLogger(InfluenzaDataLoader.class);
+
+ public void populateCache(JSAPResult config) throws SAXException {
+ String cfgFileName = System.getProperty("infinispan.demo.cfg");
+ if (cfgFileName == null)
+ cfgFileName = config.getString("InfinispanCfg");
+
+ try {
+ cbuilder = new CacheBuilder(cfgFileName);
+ 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();
+
+ 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();
+ }
+ }
+ influenzaCache.endBatch(true);
+ System.out.println("Loaded " + influenzaCache.size() + " influenza elements into influenzaCache");
+ }
+
+ if (config.getString("pfile") != null) {
+ myLogger.info("Parsing Protein data");
+ List<Nucleotide_Protein_Element> npList = npParser.parseFile(config.getString("pfile"));
+ System.out.println("About to load " + npList.size() + " protein elements into ProteinCache");
+ int loopCount = 0;
+ proteinCache.startBatch();
+ for (Nucleotide_Protein_Element x : npList) {
+ proteinCache.put(x.getGenbankAccessionNumber(),x);
+ loopCount++;
+ if ((loopCount % 5000) == 0) {
+ System.out.println("Added " + loopCount + " protein records");
+ proteinCache.endBatch(true);
+ proteinCache.startBatch();
+ }
+ }
+ proteinCache.endBatch(true);
+ System.out.println("Loaded " + proteinCache.size() + " protein elements into ProteinCache");
+ }
+
+ if (config.getString("nfile") != null) {
+ myLogger.info("Parsing Nucleotide data");
+ List<Nucleotide_Protein_Element> npList = npParser.parseFile(config.getString("nfile"));
+ System.out.println("About to load " + npList.size() + " nucleotide elements into NucleiodCache");
+ int loopCount = 0;
+ nucleiodCache.startBatch();
+ for (Nucleotide_Protein_Element x : npList) {
+ nucleiodCache.put(x.getGenbankAccessionNumber(),x);
+ loopCount++;
+ if ((loopCount % 5000) == 0) {
+ System.out.println("Added " + loopCount + " Nucleotide records");
+ nucleiodCache.endBatch(true);
+ nucleiodCache.startBatch();
+ }
+ }
+ nucleiodCache.endBatch(true);
+ System.out
+ .println("Loaded " + nucleiodCache.size() + " nucleotide elements into NucleiodCache");
+ }
+ System.out.println("Parsing files....Done");
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaDataLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaVirusCache.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaVirusCache.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaVirusCache.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.IOException;
+import java.net.URL;
+import org.apache.log4j.Logger;
+import org.infinispan.Cache;
+import org.infinispan.manager.DefaultCacheManager;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class InfluenzaVirusCache {
+ Logger myLogger = Logger.getLogger(InfluenzaVirusCache.class);
+ private Cache<String, Influenza_N_P_CR_Element> myCache;
+
+ public InfluenzaVirusCache(CacheBuilder cacheManger) throws IOException {
+ myCache = cacheManger.getCacheManager().getCache("InfluenzaCache");
+ }
+
+ public void addToCache(Influenza_N_P_CR_Element value) {
+ if (value == null)
+ return;
+ String myKey = value.getGanNucleoid();
+ if ((myKey == null) || (myKey.isEmpty())) {
+ myLogger.error("Invalid record " + value);
+ } else {
+ myCache.put(myKey, value);
+ }
+ }
+
+ public int getCacheSize() {
+ return myCache.size();
+ }
+
+ public Influenza_N_P_CR_Element getVirusDetails(String GBAN) {
+ Influenza_N_P_CR_Element myVR = myCache.get(GBAN);
+ return myVR;
+ }
+
+ public Cache getCache(){
+ return myCache;
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/InfluenzaVirusCache.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_N_P_CR_Element.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_N_P_CR_Element.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_N_P_CR_Element.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,86 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class Influenza_N_P_CR_Element implements Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8703474569822388524L;
+ private String ganNucleoid;
+ private Map<String, String> proteinMap;
+
+ /**
+ * @param proteinMap
+ */
+ public Influenza_N_P_CR_Element() {
+ super();
+ this.proteinMap = new HashMap<String, String>();
+ }
+
+ public String getGanNucleoid() {
+ return ganNucleoid;
+ }
+
+ public void setGanNucleoid(String ganNucleoid) {
+ this.ganNucleoid = ganNucleoid;
+ }
+
+ public void setProtein_Data(String proteinGAN, String proteinCR) {
+ if ((proteinGAN==null)||(proteinGAN.isEmpty()))
+ return;
+
+ if ((proteinCR==null)||(proteinCR.isEmpty()))
+ return;
+
+ proteinMap.put(proteinGAN, proteinCR);
+ }
+
+ public Map<String,String> getProtein_Data(){
+ return this.proteinMap;
+ }
+
+ public String toString(){
+ return "GAN="+this.ganNucleoid+" protein count="+this.proteinMap.size();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((ganNucleoid == null) ? 0 : ganNucleoid.hashCode());
+ result = prime * result + ((proteinMap == null) ? 0 : proteinMap.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Influenza_N_P_CR_Element other = (Influenza_N_P_CR_Element) obj;
+ if (ganNucleoid == null) {
+ if (other.ganNucleoid != null)
+ return false;
+ } else if (!ganNucleoid.equals(other.ganNucleoid))
+ return false;
+ if (proteinMap == null) {
+ if (other.proteinMap != null)
+ return false;
+ } else if (!proteinMap.equals(other.proteinMap))
+ return false;
+ return true;
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_N_P_CR_Element.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_Parser.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_Parser.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_Parser.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,65 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Scanner;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class Influenza_Parser {
+
+ public List<Influenza_N_P_CR_Element> parseFile(String fileName) {
+ return this.processFile(fileName, null);
+ }
+
+ public List<Influenza_N_P_CR_Element> processFile(String fileName, ProteinCache cacheImpl) {
+ List<Influenza_N_P_CR_Element> outList = new ArrayList<Influenza_N_P_CR_Element>();
+ System.out.println("Processing Influenza file " + fileName);
+ try {
+ Scanner scanner = new Scanner(new File(fileName.trim()));
+ scanner.useDelimiter(System.getProperty("line.separator"));
+ while (scanner.hasNext()) {
+
+ Influenza_N_P_CR_Element x = parseLine(scanner.next());
+ outList.add(x);
+ }
+ scanner.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Processed " + outList.size() + " records from file");
+ return outList;
+ }
+
+ private static Influenza_N_P_CR_Element parseLine(String line) {
+ Influenza_N_P_CR_Element currRec = new Influenza_N_P_CR_Element();
+
+ Scanner lineScanner = new Scanner(line);
+ lineScanner.useDelimiter("\t");
+ while (lineScanner.hasNext()) {
+ try {
+ currRec.setGanNucleoid(lineScanner.next());
+ try {
+ while (true) {
+ String protein_GAN = lineScanner.next();
+ String protein_CR = lineScanner.next();
+ currRec.setProtein_Data(protein_GAN, protein_CR);
+ }
+ } catch (NoSuchElementException ex) {
+ // ignore exception
+ }
+ } catch (Exception ex) {
+ System.out.println("Exception while processing line " + line);
+ }
+ }
+ return currRec;
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Influenza_Parser.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/NucleotideCache.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/NucleotideCache.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/NucleotideCache.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.IOException;
+import org.apache.log4j.*;
+import org.infinispan.Cache;
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class NucleotideCache {
+ Logger myLogger = Logger.getLogger(NucleotideCache.class);
+ private Cache<String, Nucleotide_Protein_Element> myCache;
+
+ public NucleotideCache(CacheBuilder cacheManger) throws IOException {
+ myCache = cacheManger.getCacheManager().getCache("NucleotideCache");
+ }
+
+ public void addToCache(Nucleotide_Protein_Element value) {
+ if (value == null)
+ return;
+ String myKey = value.getGenbankAccessionNumber();
+ if ((myKey == null) || (myKey.isEmpty())) {
+ myLogger.error("Invalid record " + value);
+ } else {
+ myCache.put(value.getGenbankAccessionNumber(), value);
+ }
+ }
+
+ public int getCacheSize() {
+ return myCache.size();
+ }
+
+ public Nucleotide_Protein_Element getNucleotideDetails(String GBAN) {
+ Nucleotide_Protein_Element myVR = myCache.get(GBAN);
+ return myVR;
+ }
+
+ public Cache getCache(){
+ return myCache;
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/NucleotideCache.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Element.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Element.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Element.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,220 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.Serializable;
+
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class Nucleotide_Protein_Element implements Serializable {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2870569691958410447L;
+
+ public String getGenbankAccessionNumber() {
+ return GenbankAccessionNumber;
+ }
+
+ public void setGenbankAccessionNumber(String genbankAccessionNumber) {
+ GenbankAccessionNumber = genbankAccessionNumber;
+ }
+
+ public String getHost() {
+ return Host;
+ }
+
+ public void setHost(String host) {
+ Host = host;
+ }
+
+ public String getGenomeSequenceNumber() {
+ return GenomeSequenceNumber;
+ }
+
+ public void setGenomeSequenceNumber(String genomeSequenceNumber) {
+ GenomeSequenceNumber = genomeSequenceNumber;
+ }
+
+ public String getSubType() {
+ return SubType;
+ }
+
+ public void setSubType(String subType) {
+ SubType = subType;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String Country) {
+ country = Country;
+ }
+
+ public int getYearFound() {
+ return YearFound;
+ }
+
+ public void setYearFound(String yearFound) {
+ try {
+ YearFound = new Integer(yearFound);
+ } catch (Exception ex) {
+ YearFound = 1900;
+ }
+ }
+
+ public int getSequenceLength() {
+ return SequenceLength;
+ }
+
+ public void setSequenceLength(int sequenceLength) {
+ SequenceLength = sequenceLength;
+ }
+
+ public String getVirusName() {
+ return VirusName;
+ }
+
+ public void setVirusName(String virusName) {
+ VirusName = virusName;
+ }
+
+ public String getHostAge() {
+ return HostAge;
+ }
+
+ public void setHostAge(String hostAge) {
+ HostAge = hostAge;
+ }
+
+ public String getHostGender() {
+ return HostGender;
+ }
+
+ public void setHostGender(String hostGender) {
+ HostGender = hostGender;
+ }
+
+ public Boolean getFullLengthSequence() {
+ return FullLengthSequence;
+ }
+
+ public void setFullLengthSequence(String fullLengthSequence) {
+ if ((fullLengthSequence.isEmpty()) || (fullLengthSequence.equalsIgnoreCase("F")))
+ FullLengthSequence = false;
+ else
+ FullLengthSequence = true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((country == null) ? 0 : country.hashCode());
+ result = prime * result + ((FullLengthSequence == null) ? 0 : FullLengthSequence.hashCode());
+ result = prime * result + ((GenbankAccessionNumber == null) ? 0 : GenbankAccessionNumber.hashCode());
+ result = prime * result + GenomeSequenceNumber.hashCode();
+ result = prime * result + ((Host == null) ? 0 : Host.hashCode());
+ result = prime * result + ((HostAge == null) ? 0 : HostAge.hashCode());
+ result = prime * result + ((HostGender == null) ? 0 : HostGender.hashCode());
+ result = prime * result + SequenceLength;
+ result = prime * result + ((SubType == null) ? 0 : SubType.hashCode());
+ result = prime * result + ((VirusName == null) ? 0 : VirusName.hashCode());
+ result = prime * result + YearFound;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Nucleotide_Protein_Element other = (Nucleotide_Protein_Element) obj;
+ if (country == null) {
+ if (other.country != null)
+ return false;
+ } else if (!country.equals(other.country))
+ return false;
+ if (FullLengthSequence == null) {
+ if (other.FullLengthSequence != null)
+ return false;
+ } else if (!FullLengthSequence.equals(other.FullLengthSequence))
+ return false;
+ if (GenbankAccessionNumber == null) {
+ if (other.GenbankAccessionNumber != null)
+ return false;
+ } else if (!GenbankAccessionNumber.equals(other.GenbankAccessionNumber))
+ return false;
+ if (GenomeSequenceNumber != other.GenomeSequenceNumber)
+ return false;
+ if (Host == null) {
+ if (other.Host != null)
+ return false;
+ } else if (!Host.equals(other.Host))
+ return false;
+ if (HostAge == null) {
+ if (other.HostAge != null)
+ return false;
+ } else if (!HostAge.equals(other.HostAge))
+ return false;
+ if (HostGender == null) {
+ if (other.HostGender != null)
+ return false;
+ } else if (!HostGender.equals(other.HostGender))
+ return false;
+ if (SequenceLength != other.SequenceLength)
+ return false;
+ if (SubType == null) {
+ if (other.SubType != null)
+ return false;
+ } else if (!SubType.equals(other.SubType))
+ return false;
+ if (VirusName == null) {
+ if (other.VirusName != null)
+ return false;
+ } else if (!VirusName.equals(other.VirusName))
+ return false;
+ if (YearFound != other.YearFound)
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("GenbankAccessionNumber=" + GenbankAccessionNumber);
+ sb.append("\nHost=" + Host);
+ sb.append("\nSubType=" + SubType);
+ sb.append("\ncountry=" + country);
+ sb.append("\nGenomeSequenceNumber=" + GenomeSequenceNumber);
+ sb.append("\nYearFound=" + YearFound);
+ sb.append("\nSequenceLength=" + SequenceLength);
+ sb.append("\nVirusName=" + VirusName);
+ sb.append("\nHostAge=" + HostAge);
+ sb.append("\nHostGender=" + HostGender);
+ return sb.toString();
+ }
+
+
+ String GenbankAccessionNumber;
+ String Host;
+ String SubType;
+ String country;
+
+ private String GenomeSequenceNumber;
+ private int YearFound;
+ private int SequenceLength;
+ private String VirusName;
+ private String HostAge;
+ private String HostGender;
+ private Boolean FullLengthSequence;
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Element.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Parser.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Parser.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Parser.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,62 @@
+package org.infinispan.ec2demo;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import org.milyn.Smooks;
+import org.milyn.payload.JavaResult;
+import org.xml.sax.SAXException;
+import org.apache.log4j.*;
+
+/**
+ *
+ */
+
+/**
+ * @author noconnor at redhat.com
+ *
+ */
+public class Nucleotide_Protein_Parser {
+
+ public Nucleotide_Protein_Parser(){
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Nucleotide_Protein_Element> parseFile(String fileName) throws IOException, SAXException{
+ System.out.println("Parsing ["+fileName+"]");
+ Smooks smooks = new Smooks("smooks-config.xml");
+
+ try {
+ JavaResult result = new JavaResult();
+ smooks.filterSource(new StreamSource(new FileInputStream(fileName.trim())), result);
+ return (List<Nucleotide_Protein_Element>) result.getBean("customerList");
+ } finally {
+ smooks.close();
+ }
+ }
+
+ public void processFile(String fileName,ProteinCache cacheImpl) {
+ if (fileName==null){
+ System.out.println("No file to process...");
+ return;
+ }
+ System.out.println("Processing file " + fileName);
+
+ try {
+ List<Nucleotide_Protein_Element> myData = parseFile(fileName);
+ for (Nucleotide_Protein_Element x:myData){
+ cacheImpl.addToCache(x);
+ }
+ System.out.println("Processed " + myData.size() + " records from file...");
+ System.out.println("Number stored in cache="+cacheImpl.getCacheSize());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/Nucleotide_Protein_Parser.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/ProteinCache.java
===================================================================
--- trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/ProteinCache.java (rev 0)
+++ trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/ProteinCache.java 2009-10-29 04:15:51 UTC (rev 1055)
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.infinispan.ec2demo;
+
+import java.io.IOException;
+import org.apache.log4j.*;
+import org.infinispan.Cache;
+
+/**
+ * @author noelo
+ *
+ */
+public class ProteinCache {
+ Logger myLogger = Logger.getLogger(ProteinCache.class);
+ private Cache<String, Nucleotide_Protein_Element> myCache;
+
+ public ProteinCache(CacheBuilder cacheManger) throws IOException {
+ myCache = cacheManger.getCacheManager().getCache("ProteinCache");
+ }
+
+ public void addToCache(Nucleotide_Protein_Element value) {
+ if (value == null)
+ return;
+ String myKey = value.getGenbankAccessionNumber();
+ if ((myKey == null) || (myKey.isEmpty())) {
+ myLogger.error("Invalid record " + value);
+ } else {
+ myCache.put(value.getGenbankAccessionNumber(), value);
+ }
+ }
+
+ public int getCacheSize() {
+ return myCache.size();
+ }
+
+ public Nucleotide_Protein_Element getProteinDetails(String GBAN) {
+ Nucleotide_Protein_Element myVR = myCache.get(GBAN);
+ return myVR;
+ }
+
+ public Cache getCache() {
+ return myCache;
+ }
+
+}
Property changes on: trunk/demos/ec2/src/main/java/org/infinispan/ec2demo/ProteinCache.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the infinispan-commits
mailing list