KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > client > http > HTTPInstrumentSampleData


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.client.http;
21
22 import org.apache.excalibur.instrument.client.InstrumentSampleData;
23 import org.apache.excalibur.instrument.client.InstrumentSampleSnapshotData;
24
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27
28 class HTTPInstrumentSampleData
29     extends AbstractHTTPInstrumentSampleElementData
30     implements InstrumentSampleData
31 {
32     /*---------------------------------------------------------------
33      * Constructors
34      *-------------------------------------------------------------*/

35     /**
36      * Creates a new HTTPInstrumentSampleData.
37      */

38     HTTPInstrumentSampleData( HTTPInstrumentData parent,
39                               String JavaDoc name )
40     {
41         super( (HTTPInstrumentManagerConnection)parent.getConnection(), parent, name );
42     }
43     
44     /*---------------------------------------------------------------
45      * AbstractHTTPElementData Methods
46      *-------------------------------------------------------------*/

47     /**
48      * Update the contents of the object using values from the Configuration object.
49      *
50      * @param configuration Configuration object to load from.
51      *
52      * @throws ConfigurationException If there are any problems.
53      */

54     protected void update( Configuration configuration )
55         throws ConfigurationException
56     {
57         super.update( configuration );
58         
59         if ( getLogger().isDebugEnabled() )
60         {
61             getLogger().debug(
62                 "Updated Instrument Sample '" + getName() + "' to version " + getStateVersion() );
63         }
64     }
65     
66     /**
67      * Causes the InstrumentSampleData to update itself with the latest data
68      * from the server.
69      *
70      * @return true if successful.
71      */

72     public boolean update()
73     {
74         HTTPInstrumentManagerConnection connection =
75             (HTTPInstrumentManagerConnection)getConnection();
76         
77         Configuration configuration = connection.getState(
78             "sample.xml?packed=true&name=" + urlEncode( getName() ) );
79         if ( configuration != null )
80         {
81             try
82             {
83                 update( configuration );
84                 return true;
85             }
86             catch ( ConfigurationException e )
87             {
88                 getLogger().debug( "Unable to update.", e );
89             }
90         }
91         
92         return false;
93     }
94     
95     /*---------------------------------------------------------------
96      * InstrumentSampleData Methods
97      *-------------------------------------------------------------*/

98     /**
99      * Requests that the sample's lease be updated.
100      */

101     public void updateLease()
102     {
103         HTTPInstrumentManagerConnection connection =
104             (HTTPInstrumentManagerConnection)getConnection();
105         
106         connection.getState( "sample-lease.xml?name=" + urlEncode( getName() ) );
107     }
108     
109     /**
110      * Returns a snapshot of the data in the sample.
111      *
112      * @return A snapshot of the sample.
113      */

114     public InstrumentSampleSnapshotData getSnapshot()
115     {
116         HTTPInstrumentManagerConnection connection =
117             (HTTPInstrumentManagerConnection)getConnection();
118         
119         HTTPInstrumentSampleSnapshotData snapshot =
120             new HTTPInstrumentSampleSnapshotData( connection, getName() );
121         snapshot.enableLogging( getLogger() );
122         if ( snapshot.update() )
123         {
124             return snapshot;
125         }
126         else
127         {
128             return null;
129         }
130     }
131     
132     /*---------------------------------------------------------------
133      * Methods
134      *-------------------------------------------------------------*/

135 }
Popular Tags