KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > demo > graph > LazyDemoOpener


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.demo.graph;
26
27 import org.jrobin.core.RrdOpener;
28 import org.jrobin.core.RrdDb;
29 import org.jrobin.core.RrdBackendFactory;
30 import org.jrobin.core.RrdException;
31
32 import java.io.IOException JavaDoc;
33
34 /**
35  * <p>Basic implementation showing the use of RrdOpener. This demo
36  * class simply logs an attempt to retrieve an RrdDb and diverts all
37  * actual RrdDb retrieval to the basic RrdOpener.</p>
38  *
39  * @author Arne Vandamme (cobralord@jrobin.org)
40  */

41 public class LazyDemoOpener extends RrdOpener
42 {
43     /**
44      * Custom constructor.
45      */

46     LazyDemoOpener()
47     {
48         // Our custom RrdOpener does not use the pool, to better illustrate
49
super( false, true );
50
51         System.out.println( "LOG: RrdOpener object created." );
52     }
53
54     /**
55      * Retrieves an RrdDb instance.
56      */

57     public RrdDb getRrd( String JavaDoc name, RrdBackendFactory backendFactory ) throws RrdException, IOException JavaDoc
58     {
59         RrdDb db = null;
60
61         System.out.println( "LOG: Access request for RRD with name " + name + " (backend: " + backendFactory.getFactoryName() + ")" );
62         db = super.getRrd( name, backendFactory );
63
64         if ( db == null )
65             System.out.println( "LOG: FAILURE locating RRD with name " + name );
66         else
67             System.out.println( "LOG: SUCCESS locating RRD with name " + name );
68
69         return db;
70     }
71
72     /**
73      * Releases RrdDb instance.
74      */

75     public void releaseRrd( RrdDb rrdDb ) throws IOException JavaDoc, RrdException
76     {
77         System.out.println( "LOG: Releasing RRD " + rrdDb.getPath() );
78
79         super.releaseRrd( rrdDb );
80     }
81 }
82
Popular Tags