You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Barth <ch...@buerobarth.de> on 2006/01/15 12:18:19 UTC

How to make Generator cacheable?

Hi!

I want to cache a generator I just wrote. 
I thought I only have to implement the CacheableProcessingComponent.

Have a look at my code:


public class FBSGenerator extends ServiceableGenerator implements
CacheableProcessingComponent {
	
	private String bject;
	private String bject_ID;
	private String geb_ID;
	private String stock_ID;
	private String suchtyp;
	private String abweichungen;
	private BasicDocument ergebnis = new BasicDocument();
	protected Source inputSource;
	
	public void setup(SourceResolver resolver, Map objectModel, String
src, Parameters par)
	throws ProcessingException, SAXException, IOException 
	{
		super.setup(resolver, objectModel, src, par);
		try {
			bject = par.getParameter("bject");
			bject_ID = par.getParameter("bject_ID");
			suchtyp = par.getParameter("typ");
			geb_ID = par.getParameter("geb_ID");
			stock_ID = par.getParameter("stock_ID");
			abweichungen = par.getParameter("abweichungen");
			System.out.println("INPUTSOURCE");
			This.inputSource = super.resolver.resolveURI(src);
//This line throws an ERROR, see below
			System.out.println(inputSource.toString());
		
			
		} catch (ParameterException e) {
			e.printStackTrace();
		}
	}
	
	public void generate() throws IOException, SAXException,
ProcessingException
	{
		SAXParser parser = null;
		InputSource inputSource = new InputSource();
		System.out.println("Die ID: "+objekt_ID);
		System.out.println("Das Objekt: "+objekt);
		System.out.println("Der Typ: "+suchtyp);
		System.out.println("Die Geb_ID: "+geb_ID);
		System.out.println("Die Stock_ID: "+stock_ID);
		System.out.println("Abweichungen anzeigen: "+abweichungen);
		HashMap gewichte =
GewichtungsQuery.readGewichtung(DBConnection.COLLECTION, objekt, suchtyp);
		
		if (objekt.equals("gebTrennwand")) {
			ergebnis =
Gebaeudetrennwand.erzeugeErgebnisDoc(gewichte, geb_ID, objekt_ID, 
					suchtyp, abweichungen);
			System.out.println("BLUB: "+ergebnis.toString());
		}
		else if (objekt.equals("Trennwand")) {
			ergebnis =
Trennwand.erzeugeErgebnisDoc(gewichte, geb_ID, stock_ID, objekt_ID, 
					suchtyp, abweichungen);
			System.out.println("BLUB: "+ergebnis.toString());
		}
		else if (objekt.equals("Rettungsweg")) {
			ergebnis =
Rettungsweg.erzeugeErgebnisDoc(gewichte, geb_ID, stock_ID, objekt_ID, 
					suchtyp, abweichungen);
			System.out.println("BLUB: "+ergebnis.toString());
		}
	
		StringBufferInputStream anStream = new
StringBufferInputStream (ergebnis.toString()); 
		inputSource.setByteStream(anStream);
		try {
			parser =
(SAXParser)this.manager.lookup(SAXParser.ROLE);
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		parser.parse(inputSource, super.xmlConsumer);
		
	}

	public Serializable getKey() {
		 return this.inputSource.getURI();
	}

	public SourceValidity getValidity() {
		
		return this.inputSource.getValidity();
	}

}


When I call this generator, I get the following error:

org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
java.lang.RuntimeException: java.lang.RuntimeException:
org.apache.cocoon.ProcessingException: Could not setup pipeline.:
java.net.MalformedURLException: Invalid System ID

What's wrong with my generator?

Barthi


AW: AW: How to make Generator cacheable?

Posted by Christian Barth <ch...@buerobarth.de>.
Ok, I see. 

Here is my new code:
public Serializable getKey() {
	return objekt+objekt_ID+geb_ID+stock_ID+abweichungen+suchtyp;
	}

public SourceValidity getValidity() {
	try {
	TaminoClient tc = new
TaminoClient("http://localhost/tamino/BSDB30032005/Hessen");
	tc.setSAXimplementer("com.jclark.xml.sax.Driver");
	String query = "/Gebaeude[@ID="+geb_ID+"]";
	TaminoResult tr = tc.query(query);
	long lastModified = tr.getLastModified().getTime();
	System.out.println("Letzte Aenderung: "+lastModified);
	TimeStampValidity timeStamp = new TimeStampValidity(lastModified);
	return timeStamp;
	} catch (TaminoError e) {
		e.printStackTrace();
		return null;
	}
}


If this is he correct why, I have another problem: the line
tr.getLastModified().getTime(); always returns 0. But I don't know why.
Can anybody help?


Thanks,
Barthi


> -----Ursprüngliche Nachricht-----
> Von: g[R]eK [mailto:grek@bluebottle.com]
> Gesendet: Sonntag, 15. Januar 2006 22:01
> An: users@cocoon.apache.org
> Betreff: Re: AW: How to make Generator cacheable?
> 
> Christian Barth napisał(a):
> > The caching is working now with the following code
> > <snip/>
> > But as you can see, The Cache expires after 5 minutes. What I want is,
> that
> > is gets invalid, when the LastModificationDate of my DB has changed.
> >
> > In the getKey()-Method I have already searialized the timestamp of the
> last
> > modification, But now I don't know how to test, if the Cache is still
> valid
> > in the getValidity()-Method.
> >
> > Can anybody help?
> I think you confuse things about caching. The key of cache should not be
> a timestamp. The key is unique identifier of your particular
> configuration (e.g. your database url), and validity object contains
> information needed to check if entry with particular key is still valid.
> In your case, you can return whatever you want in your getKey() method
> (if you have only i configuration). The getValidity() should return
> TimeStampValidity[1].
> 
> Check [2] for further information. Hope this helps.
> 
> [1]
> http://excalibur.apache.org/apidocs/org/apache/excalibur/source/impl/valid
> ity/TimeStampValidity.html
> [2] http://cocoon.zones.apache.org/daisy/documentation/writing/690.html

Re: AW: How to make Generator cacheable?

Posted by "g[R]eK" <gr...@bluebottle.com>.
Christian Barth napisał(a):
> The caching is working now with the following code
> <snip/>
> But as you can see, The Cache expires after 5 minutes. What I want is, that
> is gets invalid, when the LastModificationDate of my DB has changed.
>
> In the getKey()-Method I have already searialized the timestamp of the last
> modification, But now I don't know how to test, if the Cache is still valid
> in the getValidity()-Method.
>
> Can anybody help?
I think you confuse things about caching. The key of cache should not be 
a timestamp. The key is unique identifier of your particular 
configuration (e.g. your database url), and validity object contains 
information needed to check if entry with particular key is still valid. 
In your case, you can return whatever you want in your getKey() method 
(if you have only i configuration). The getValidity() should return 
TimeStampValidity[1].

Check [2] for further information. Hope this helps.

[1] 
http://excalibur.apache.org/apidocs/org/apache/excalibur/source/impl/validity/TimeStampValidity.html
[2] http://cocoon.zones.apache.org/daisy/documentation/writing/690.html

AW: How to make Generator cacheable?

Posted by Christian Barth <ch...@buerobarth.de>.
The caching is working now with the following code:

 

public Serializable getKey() {

                        //LastModified aus XML-DB holen

                        try {

                                   TaminoClient tc = new
TaminoClient("http://localhost/tamino/BSDB30032005/Hessen");

 
tc.setSAXimplementer("com.jclark.xml.sax.Driver");

                                   String query =
"/Gebaeude[@ID="+geb_ID+"]";

                                   TaminoResult tr = tc.query(query);

                                   

                                   System.err.println("hier
"+tr.toXmlString());

                                   

                                   return
tr.getLastModified().toGMTString();

                        } catch (TaminoError e) {

                                   // TODO Auto-generated catch block

                                   e.printStackTrace();

                                   return null;

                        }

            }

 

            public SourceValidity getValidity() {

                        

                        return new ExpiresValidity(1000*600);

            }

 

 

But as you can see, The Cache expires after 5 minutes. What I want is, that
is gets invalid, when the LastModificationDate of my DB has changed.

In the getKey()-Method I have already searialized the timestamp of the last
modification, But now I don't know how to test, if the Cache is still valid
in the getValidity()-Method.

 

Can anybody help?

 

Thanks,

Barthi

 

 

 

 

 

 

Von: Christian Barth [mailto:christian@buerobarth.de] 
Gesendet: Sonntag, 15. Januar 2006 12:18
An: users@cocoon.apache.org
Betreff: How to make Generator cacheable?

 

Hi!

I want to cache a generator I just wrote. 

I thought I only have to implement the CacheableProcessingComponent.

Have a look at my code:

 

public class FBSGenerator extends ServiceableGenerator implements
CacheableProcessingComponent {

        

        private String bject;

        private String bject_ID;

        private String geb_ID;

        private String stock_ID;

        private String suchtyp;

        private String abweichungen;

        private BasicDocument ergebnis = new BasicDocument();

        protected Source inputSource;

        

        public void setup(SourceResolver resolver, Map objectModel, String
src, Parameters par)

        throws ProcessingException, SAXException, IOException 

        {

                super.setup(resolver, objectModel, src, par);

                try {

                        bject = par.getParameter("bject");

                        bject_ID = par.getParameter("bject_ID");

                        suchtyp = par.getParameter("typ");

                        geb_ID = par.getParameter("geb_ID");

                        stock_ID = par.getParameter("stock_ID");

                        abweichungen = par.getParameter("abweichungen");

                        System.out.println("INPUTSOURCE");

                        This.inputSource = super.resolver.resolveURI(src);
//This line throws an ERROR, see below

                        System.out.println(inputSource.toString());

                

                        

                } catch (ParameterException e) {

                        e.printStackTrace();

                }

        }

        

        public void generate() throws IOException, SAXException,
ProcessingException

        {

                SAXParser parser = null;

                InputSource inputSource = new InputSource();

                System.out.println("Die ID: "+objekt_ID);

                System.out.println("Das Objekt: "+objekt);

                System.out.println("Der Typ: "+suchtyp);

                System.out.println("Die Geb_ID: "+geb_ID);

                System.out.println("Die Stock_ID: "+stock_ID);

                System.out.println("Abweichungen anzeigen: "+abweichungen);

                HashMap gewichte =
GewichtungsQuery.readGewichtung(DBConnection.COLLECTION, objekt, suchtyp);

                

                if (objekt.equals("gebTrennwand")) {

                        ergebnis =
Gebaeudetrennwand.erzeugeErgebnisDoc(gewichte, geb_ID, objekt_ID, 

                                        suchtyp, abweichungen);

                        System.out.println("BLUB: "+ergebnis.toString());

                }

                else if (objekt.equals("Trennwand")) {

                        ergebnis =
Trennwand.erzeugeErgebnisDoc(gewichte, geb_ID, stock_ID, objekt_ID, 

                                        suchtyp, abweichungen);

                        System.out.println("BLUB: "+ergebnis.toString());

                }

                else if (objekt.equals("Rettungsweg")) {

                        ergebnis =
Rettungsweg.erzeugeErgebnisDoc(gewichte, geb_ID, stock_ID, objekt_ID, 

                                        suchtyp, abweichungen);

                        System.out.println("BLUB: "+ergebnis.toString());

                }

        

                StringBufferInputStream anStream = new
StringBufferInputStream (ergebnis.toString()); 

                inputSource.setByteStream(anStream);

                try {

                        parser =
(SAXParser)this.manager.lookup(SAXParser.ROLE);

                } catch (ServiceException e) {

                        e.printStackTrace();

                }

                parser.parse(inputSource, super.xmlConsumer);

                

        }

        public Serializable getKey() {

                 return this.inputSource.getURI();

        }

        public SourceValidity getValidity() {

                

                return this.inputSource.getValidity();

        }

}

 

When I call this generator, I get the following error:

org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
java.lang.RuntimeException: java.lang.RuntimeException:
org.apache.cocoon.ProcessingException: Could not setup pipeline.:
java.net.MalformedURLException: Invalid System ID

What's wrong with my generator?

Barthi