[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Very slow printing.
Hi ,
I have "merged" the XML examples from the samples.
to a "Command prompt" application
i use xalan to print.
Now the printing can take about 60 seconds for a quite simple document.
I think the document I am printing is already converted to a memory doc
has anyone ideas why i take so long?
i have included the code
DocServer:>store doc.xml doc.xml
DocServer:>show doc.xml
***printing time:82577 ms
***execution time:83449 ms
DocServer:>query doc.xml /backslash/story/title
Kees Jongenburger
/**
* This class provides a Timer<BR>
* it alows to start and stop the timer multiple times<BR>
* also it insn't nececary to stop the timer to read the current elapsed time;
**/
public class Timer{
long startTime;
long total;
public Timer(){
total = 0;
startTime = 0;
}
/**
* starts the timer<BR>
* wil start the timer if i wasn't started
**/
public void start(){
// if the timer wasn't started start it
// else leave the timer alone
if (startTime == 0)
startTime = System.currentTimeMillis();
}
/**
* reset the timer note this does stop the timer<BR>
**/
public void reset(){
total = 0;
startTime = 0;
}
/**
* stops the timer<BR>
**/
public void stop(){
if (startTime != 0){
total += System.currentTimeMillis()-startTime;
startTime =0;
}
}
/**
* @return the elapsed Time in MilliSeconds
**/
public long getTime(){
long retVal;
if (startTime != 0){
retVal = total + System.currentTimeMillis()-startTime;
} else {
retVal = total;
}
return retVal;
}
}
<?xml version="1.0"?>
<backslash>
<story>
<title>Bell Labs Achieves 3.28Tbps Over Fiber</title>
<url>http://slashdot.org/articles/00/03/17/129258.shtml</url>
<time>2000-03-18 09:05:13</time>
<author>timothy</author>
<department>please-don't-tell-the-spammers</department>
<topic>tech</topic>
<comments>21</comments>
<section>articles</section>
<image>topictech2.jpg</image>
</story>
<story>
<title>Apple's New Trackpad?</title>
<url>http://slashdot.org/articles/00/03/16/1355200.shtml</url>
<time>2000-03-18 04:55:24</time>
<author>timothy</author>
<department>smarter-and-smarter</department>
<topic>tech</topic>
<comments>72</comments>
<section>articles</section>
<image>topictech2.jpg</image>
</story>
<story>
<title>NASA Will Have to Wait for Mars</title>
<url>http://slashdot.org/science/00/03/17/1625217.shtml</url>
<time>2000-03-18 01:28:07</time>
<author>CmdrTaco</author>
<department>now-where-did-we-put-that-lander</department>
<topic>space</topic>
<comments>127</comments>
<section>science</section>
<image>topicspace.gif</image>
</story>
<story>
<title>Donnie Barnes On LinuxExpo</title>
<url>http://slashdot.org/articles/00/03/16/1640248.shtml</url>
<time>2000-03-18 01:23:45</time>
<author>timothy</author>
<department>clearing-up-the-situation</department>
<topic>news</topic>
<comments>27</comments>
<section>articles</section>
<image>topicnews.gif</image>
</story>
<story>
<title>Prepare for Kylix: The Compiler and RTL</title>
<url>http://slashdot.org/articles/00/03/17/1933251.shtml</url>
<time>2000-03-18 00:31:52</time>
<author>HeUnique</author>
<department>coming-soon</department>
<topic>programming</topic>
<comments>81</comments>
<section>articles</section>
<image>topicprogramming.gif</image>
</story>
<story>
<title>Diablo II Beta Sign-Up Monday</title>
<url>http://slashdot.org/articles/00/03/16/084211.shtml</url>
<time>2000-03-17 21:15:00</time>
<author>jamie</author>
<department>single-file-no-pushing</department>
<topic>games</topic>
<comments>161</comments>
<section>articles</section>
<image>topicgames.jpg</image>
</story>
<story>
<title>IBM's Nanotech Drive Research</title>
<url>http://slashdot.org/science/00/03/17/1046232.shtml</url>
<time>2000-03-17 19:48:54</time>
<author>Hemos</author>
<department>tomorrow-today</department>
<topic>ibm</topic>
<comments>122</comments>
<section>science</section>
<image>topicibm.gif</image>
</story>
<story>
<title>Legos Meets Myth II</title>
<url>http://slashdot.org/articles/00/03/17/1314226.shtml</url>
<time>2000-03-17 18:14:30</time>
<author>Hemos</author>
<department>super-super-cool</department>
<topic>toys</topic>
<comments>96</comments>
<section>articles</section>
<image>topictoys.gif</image>
</story>
<story>
<title>Unix: Which One to Choose?</title>
<url>http://slashdot.org/articles/00/03/17/1225248.shtml</url>
<time>2000-03-17 17:23:17</time>
<author>HeUnique</author>
<department>very-interesting-question</department>
<topic>unix</topic>
<comments>251</comments>
<section>articles</section>
<image>topicunix.jpg</image>
</story>
<story>
<title>Replies from Slackware Founder Patrick Volkerding</title>
<url>http://slashdot.org/interviews/00/03/17/1120205.shtml</url>
<time>2000-03-17 17:00:29</time>
<author>Roblimo</author>
<department>we-all-need-a-little-more-slack</department>
<topic>linux</topic>
<comments>159</comments>
<section>interviews</section>
<image>topiclinux.gif</image>
</story>
</backslash>
import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import org.ozoneDB.*;
import org.ozoneDB.xml.*;
import org.ozoneDB.xml.dom.*;
import org.ozoneDB.xml.util.*;
import org.w3c.dom.*;
import org.apache.xalan.xpath.xml.TreeWalker;
import org.apache.xalan.xpath.xml.FormatterToXML;
import org.ozoneDB.xml.util.XPathQuery;
import org.ozoneDB.xml.util.XPathQueryImpl;
import org.apache.xalan.xpath.XObject;
public class DocServer {
private final static String hostname = "localhost";
private final static int port = 3333;
private final static String username = "ozone";
private final static String password = "111";
/** XML Converter used to convert the OzoneXML Documents to Documents */
DOMConverterUtil converter;
PersistentDOMParser persistentDOMParser;
private RemoteDatabase database = null;
public DocServer() throws Exception {
database = new RemoteDatabase();
database.open(hostname, port, username, password);
database.reloadClasses();
// Create the converter
converter = new DOMConverterUtil(database);
persistentDOMParser = (PersistentDOMParser)new OzoneDOMParser(database);
}
public void save(Document document, String documentName) throws Exception {
persistentDOMParser.storeDocument(document, documentName);
}
public Document load(String documentName) throws Exception{
Timer timer = new Timer();
timer.start();
Node document = (Document)database.objectForName(documentName);
timer.stop();
System.out.println("handle to document execution time:" + timer.getTime() + " ms ");
timer.reset();
timer.start();
Document retVal = (Document)converter.convertDOM(document);
timer.stop();
System.out.println("convert execution time:" + timer.getTime() + " ms ");
return retVal;
}
public boolean store(String fileName , String documentName) throws Exception{
if ((Document)database.objectForName (documentName) == null){
persistentDOMParser.storeDocument(fileName ,documentName);
} else {
return false;
}
return true;
};
public boolean remove(String documentName) throws Exception{
Document pDoc = (Document) database.objectForName (documentName);
if (pDoc != null) {
// delete this document from database
System.out.println ("Remove Document from DataBase!");
database.deleteObject ((OzoneRemote)pDoc);
return true;
}
return false;
}
public XObject query(String documentName , String queryString) throws Exception{
Timer timer = new Timer();
timer.start();
Document pDoc = (Document) database.objectForName (documentName);
System.out.println("handle to document execution time:" + timer.getTime() + " ms ");
if (pDoc == null)
throw new Exception(" Document not found");
timer.reset();
timer.start();
XPathQuery xPQuery = (XPathQuery) database.createObject (XPathQueryImpl.class.getName(), 0, null);
XObject xObject = xPQuery.execute (queryString, pDoc.getDocumentElement ());
timer.stop();
System.out.println("query time :" + timer.getTime() + " ms ");
return xObject;
}
public static void main(String [] argv) throws Exception{
boolean stop = false;
boolean doTime = false;
// create a new DocServer
DocServer docServer = new DocServer();
// create a input stream to read from the command line
DataInputStream dis = new DataInputStream(System.in);
String line="";
Timer timer = new Timer();
// do .. while the command line is not NULL like control-d under U*NIX
do {
if (line != null){
StringTokenizer st = new StringTokenizer(line , " ");
if (st.hasMoreTokens()){
String command = (String)st.nextElement();
if (command.equals("time")){
doTime = true;
timer.reset();
timer.start();
if (st.hasMoreTokens())
command = (String)st.nextElement();
} else {
doTime = false;
}
// show
if (command.equals("show")){
if (st.hasMoreTokens()){
String file = (String)st.nextElement();
try {
Document doc = docServer.load(file);
System.out.println("start print");
Timer timer2 = new Timer();
timer2.start();
FormatterToXML fl = new FormatterToXML (System.out);
TreeWalker tw = new TreeWalker (fl);
tw.traverse (doc);
fl.flush ();
fl.flushWriter ();
System.out.println();
timer2.stop();
System.out.println("printing time:" + timer2.getTime() + " ms ");
} catch (Exception e){
System.out.println("File Not in database");
}
} else {
System.out.println("Usage: show <file>");
}
}
if (command.equals("remove")){
if (st.hasMoreTokens()){
String file = (String)st.nextElement();
if(docServer.remove(file)){
System.out.println("Document removed");
} else {
System.out.println("Document NOT removed");
}
} else {
System.out.println("Usage: remove <file>");
}
}
if (command.equals("store")){
if (st.hasMoreTokens()){
String localfile = (String)st.nextElement();
if (st.hasMoreTokens()){
String databaseFile = (String)st.nextElement();
if(docServer.store(localfile,databaseFile)){
System.out.println("Document stored");
} else {
System.out.println("Document NOT stored");
}
} else {
System.out.println("Usage: store <localfile> <FileName in database>");
}
} else {
System.out.println("Usage: store <localfile> <FileName in database>");
}
}
if (command.equals("query")){
if (st.hasMoreTokens()){
String file = (String)st.nextElement();
if (st.hasMoreTokens()){
String query = (String)st.nextElement();
XObject xObject = docServer.query(file,query);
if (xObject.getType() == XObject.CLASS_NODESET){
NodeList nodeList = xObject.nodeset();
if (nodeList != null){
FormatterToXML fl = new FormatterToXML (System.out);
TreeWalker tw = new TreeWalker (fl);
for (int i= 0; i< nodeList.getLength(); i ++){
tw.traverse (nodeList.item(i));
}
fl.flush ();
fl.flushWriter ();
System.out.println();
} else {
System.out.println("Nothing returned");
}
} else {
System.out.println("Query result not of type nodeset");
}
} else {
System.out.println("Usage: query <file> query");
}
} else {
System.out.println("Usage: query <file> query");
}
}
if (command.equals("exit") || command.equals("quit")){
stop = true;
}
if (doTime){
System.out.println("execution time:" + timer.getTime() + " ms ");
}
} else {
System.out.println("Available commands:");
System.out.println("\t:[time] show <file>");
System.out.println("\t:[time] store <localfile> <FileName in database>");
System.out.println("\t:[time] remove <file>");
System.out.println("\t:[time] query <file> query");
System.out.println("\t:quit");
}
}
System.out.print("DocServer:>");
} while(! stop && (line = dis.readLine()) != null );
System.out.println();
System.out.println("exit DocServer");
}
}