/* * BioJava development code * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. If you do not have a copy, * see: * * http://www.gnu.org/copyleft/lesser.html * * Copyright for this code is held jointly by the individual * authors. These should be listed in @author doc comments. * * For more information on the BioJava project and its aims, * or to join the biojava-l mailing list, visit the home page * at: * * http://www.biojava.org/ * * * */ import java.util.List; import org.biojava.bio.structure.PDBHeader; import org.biojava.bio.structure.Structure; import org.biojava.bio.structure.io.HibernateInstallation; import org.biojava.bio.structure.server.PDBInstallation; import org.biojava.bio.structure.server.SimpleStructureServer; import org.biojava.bio.structure.server.StructureEvent; import org.biojava.bio.structure.server.StructureListener; import org.biojava.bio.structure.server.StructureServer; /** A simple client that implements the StructureListener interface. * It uses the SimpleStructureServer to request the loading of structures * in multiple threads and gets notifications via the newStructure class. * * @see org.biojava.bio.structure.server.StructureListener * @see org.biojava.bio.structure.server.SimpleStructureServer * @see #newStructure(StructureEvent) * * @author Andreas Prlic * */ public class DemoHibernateStructureClient implements StructureListener, Runnable { StructureServer server ; public static void main(String[] args){ SimpleStructureServer server = new SimpleStructureServer(); DemoHibernateStructureClient demo = new DemoHibernateStructureClient(); PDBInstallation installation = new HibernateInstallation(); // demo 1 - access individual files through the installation PDBHeader h1 = installation.getPDBHeader("5pti"); System.out.println(h1); if ( h1 == null) { System.out.println("could not find 5pti in your installation. Is everything ok. with it?"); } // get the structure for this header Structure s = installation.getStructure(h1.getIdCode()); System.out.println(s); // get all PDBHeaders List headers = installation.getAll(); System.out.println(headers.size()); System.out.println(headers.get(0)); // demo 2 - loop over structures and access them // using the multi-threaded speedup provided through the // StructureServer server.setPDBInstallation(installation); // preload this number of structures while the // structureListener thread is busy server.setCacheSize(2); // init the server server.initCache(); demo.setServer(server); // we hook hook the demo to the server. // every time the server is being requested to load a new // structure, it will tell us when the loading is finished server.addStructureListener(demo); // and we start our demo. Thread t = new Thread(demo); t.start(); } /** when the demo thread starts, we request the 1st structure from the server. * */ public void run(){ //System.out.println("starting new Thread in Demo"); server.requestNextStructure(this); } /** get the Server * * @return the server */ public StructureServer getServer() { return server; } /** set the server * * @param server */ public void setServer(StructureServer server) { this.server = server; } /** the server is sending us a new Structure * (we have requested one before using server.requestNextStructure) * @see org.biojava.bio.structure.server.StructureServer * */ public void newStructure(StructureEvent event) { System.out.println("got new structure from server"); Structure s = event.getStructure(); System.out.println(s); // this is the place where we would do some calculations. // now we are ready to work on the next structure. // request it from the server server.requestNextStructure(this); } public void obsoleteStructure(StructureEvent event) { // TODO Auto-generated method stub } public void modifiedStructure(StructureEvent event) { // TODO Auto-generated method stub } }