source: trunk/java-client/org/nzdl/gsdl/service/NzdlLogWrapper.java@ 2220

Last change on this file since 2220 was 2220, checked in by say1, 23 years ago

change int-> long in a number of places, new createNzdlService method taking only an IOR, added the start of a hli (high level interface

  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/*
2 * NzdlWrapper.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20//the package we're in
21package org.nzdl.gsdl.service;
22
23import java.util.Map;
24import java.util.Set;
25import java.util.List;
26import java.util.Date;
27import java.io.Writer;
28import java.io.FileWriter;
29
30
31/**
32 * A Wrapper around an NzdlService object that adds logging functionality.
33 *
34 * @author Brett Sheeran ([email protected]) (comments)
35 * @author Stuart Yeates ([email protected])
36 * @version $Revision: 2220 $
37 */
38public class NzdlLogWrapper
39 extends NzdlWrapper {
40
41 Writer logFile = null;
42 String tag = "NzdlLogWrapper: ";
43 boolean calculateDiff = true;
44 boolean logBefore = false;
45 boolean logAfter = false;
46 Date whenCallStarted = null;
47
48
49 /**
50 * The bean constructor ...
51 */
52 public NzdlLogWrapper() {
53 }
54 /**
55 * The normal constructor
56 */
57 public NzdlLogWrapper(NzdlService nzdl, String logFilename,
58 String tag) {
59 super(nzdl);
60 this.tag = tag;
61 try {
62 Date date = new Date();
63 // the true is append ...
64 logFile = new FileWriter(logFilename, true);
65 logFile.write(tag + "Log started at:" + date + " == " +
66 date.getTime() + "\n");
67 logFile.write(tag + "timestamps in milliseconds since January 1, 1970, 00:00:00 GMT \n");
68 logFile.flush();
69 } catch (Exception exception) {
70 System.err.println("unable to create log file:" + exception);
71 }
72 }
73
74 protected void logBefore(String method) {
75 if (whenCallStarted != null)
76 throw new Error ("synchronisation required ! (whenCallStarted != null)");
77 whenCallStarted = new Date();
78 if (logBefore)
79 try {
80 logFile.write(this.tag + "before " + method + "() " +
81 whenCallStarted.getTime() + "\n");
82 logFile.flush();
83 } catch (Exception exception) {
84 System.err.println("unable to write log file:" + exception);
85 }
86 }
87
88 protected void logAfter(String method) {
89 if (whenCallStarted == null)
90 throw new Error ("synchronisation required ! (whenCallStarted == null)");
91 Date now = new Date();
92 try {
93 if (logAfter)
94 logFile.write(this.tag + "after " + method + "() " +
95 whenCallStarted.getTime() + "\n");
96 if (calculateDiff)
97 logFile.write(this.tag + "time for " + method + "() " +
98 (now.getTime() -whenCallStarted.getTime()) + "ms\n");
99 logFile.flush();
100 } catch (Exception exception) {
101 System.err.println("unable to write log file:" + exception);
102 }
103 whenCallStarted = null;
104 }
105
106 /**
107 * Allow the client to configure a CORBA server.
108 * @param key the parameter to be set.
109 * @param values what that parameter will be set to.
110 */
111 public void configure( String _key, Set _values ) {
112 logBefore("configure");
113 super.configure(_key, _values);
114 logAfter("configure");
115 }
116
117 /**
118 * Obtain the set of collection names for a Greenstone library.
119 * @return A set of collection names in string format.
120 */
121 public Set getCollectionSet( ) {
122 logBefore("getCollectionSet");
123 Set result = super.getCollectionSet();
124 logAfter("getCollectionSet");
125 return result;
126 }
127
128 /**
129 * Check if ORB knows of this collection.
130 * @param name the name of a collecion to be searched for.
131 * @return boolean <TT>true</TT> if collection is found, else <TT>false</TT>.
132 */
133 public boolean hasCollection( String _name ) {
134 logBefore("hasCollection");
135 boolean result = super.hasCollection(_name);
136 logAfter("hasCollection");
137 return result;
138 }
139
140
141 /**
142 * Check if ORB can communicate with of this collection.
143 * @param name the name of a collecion to be pinged.
144 * @return boolean <TT>true</TT> if collection returned ping, else
145 * <TT>false</TT>.
146 */
147 public boolean pingCollection( String _name ) {
148 logBefore("pingCollection");
149 boolean result = super.pingCollection(_name);
150 logAfter("pingCollection");
151 return result;
152 }
153
154 /**
155 * Extract information on this collection into a
156 * {@link NzdlCollectionInfo NzdlCollectionInfo} object
157 * @param name the collection to be retrieved.
158 * @return an instance of
159 * {@link NzdlCollectionInfo NzdlCollectionInfo} containing data on a
160 * collection
161 */
162 public NzdlCollectionInfo getCollectionInfo( String _name ) {
163 logBefore(" getCollectionInfo");
164 NzdlCollectionInfo result = super.getCollectionInfo(_name);
165 logAfter(" getCollectionInfo");
166 return result;
167 }
168
169 /**
170 * Returns the set of filters for the service object.
171 * @param name the collection name
172 * @return a set of strings that name the filters, for example
173 * BrowseFilter, QueryFilter and NullFilter.
174 */
175 public Set getFilterSet( String _name ) {
176 logBefore("getFilterSet");
177 Set result = super.getFilterSet(_name);
178 logAfter("getFilterSet");
179 return result;
180 }
181
182 /**
183 * @param name the collection name
184 * @return the Set of (name, value) value pairs for all metadata
185 * associated with a collection
186 */
187 public Set getMetaTagSet( String _name ) {
188 logBefore("getMetaTagSet");
189 Set result = super.getMetaTagSet(_name);
190 logAfter("getMetaTagSet");
191 return result;
192 }
193
194 /**
195 * Returns the Greenstone Markup Language (GML) text for a particular
196 * document from a collection.
197 * @param name the name of the collection.
198 * @param docID the document identity string
199 * @return the GML document in the form of a string.
200 */
201 public String getDocument( String _name, String _docID ) {
202 logBefore("getDocument");
203 String result = super.getDocument(_name, _docID);
204 logAfter("getDocument");
205 return result;
206 }
207
208 /**
209 * Returns the set of value(s) for a metatag from a particular document.
210 * @param name collection name
211 * @param docID the document identifier.
212 * @param metaTag the metatag name such as: Title, Author, Date and Images.
213 * @return The set of value(s) for the requested metatag and document. In
214 * cases such as Title, Author, Date there will probably be only one value
215 * per document.
216 */
217 public Set getMetaData( String _name, String _docID, String _metaTag ) {
218 logBefore("getMetaData");
219 Set result = super.getMetaData( _name, _docID, _metaTag );
220 logAfter("getMetaData");
221 return result;
222 }
223
224 /**
225 * Returns a map of value(s) for a metatag from a list of documents.
226 * @param name collection name
227 * @param docIDs a list of document identifier strings.
228 * @param metaTag the metatag name such as: Title, Author, Date and Images.
229 * @return The map of value(s) for the requested metatag and document. In
230 * cases such as Title, Author, Date there will probably be only one value
231 * per document.
232 */
233 public Map getMetaData( String _name, List _docIDs, String _metaTag ) {
234 logBefore("getMetaData");
235 Map result = super.getMetaData( _name, _docIDs, _metaTag );
236 logAfter("getMetaData");
237 return result;
238 }
239
240 /**
241 * Services a {@link NzdlRequest NzdlRequest} to a collection and places
242 * the results into a {@link NzdlResponse NzdlResponse} object. <br>
243 * Pre: Created instances of NzdlRequest and NzdlResponse. <br>
244 * Post: Placed the result data into NzdlResponse object.
245 * @param name the collection name.
246 * @param request an instance of NzdlRequest with query data to be serviced
247 * @param response an instance of NzdlResponse. where the results of
248 * sevciving the query will be placed
249 */
250 public void service( String _name, NzdlRequest _request,
251 NzdlResponse _response ) {
252 logBefore("service");
253 super.service(_name,_request,_response);
254 logAfter("service");
255 }
256
257}
Note: See TracBrowser for help on using the repository browser.