KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > CosTransactions > Log


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28 //----------------------------------------------------------------------------
29
//
30
// Module: Log.java
31
//
32
// Description: Transaction state logger.
33
//
34
// Product: com.sun.jts.CosTransactions
35
//
36
// Author: Simon Holdsworth
37
//
38
// Date: March, 1997
39
//
40
// Copyright (c): 1995-1997 IBM Corp.
41
//
42
// The source code for this program is not published or otherwise divested
43
// of its trade secrets, irrespective of what has been deposited with the
44
// U.S. Copyright Office.
45
//
46
// This software contains confidential and proprietary information of
47
// IBM Corp.
48
//----------------------------------------------------------------------------
49

50 package com.sun.jts.CosTransactions;
51
52 // Import required classes.
53

54 import java.util.logging.Logger JavaDoc;
55 import java.util.logging.Level JavaDoc;
56 import com.sun.logging.LogDomains;
57 import com.sun.jts.utils.LogFormatter;
58
59
60 /**The Log class provides operations that control the physical log
61  * as an entity versus the individual LogFiles that form the log. It supports
62  * the initialisation, opening and termination of the log. Different physical
63  * logs can be placed on the system with only minor changes to the methods
64  * contained in this class.
65  *
66  * @version 0.01
67  *
68  * @author Simon Holdsworth, IBM Corporation
69  *
70  * @see
71 */

72 //----------------------------------------------------------------------------
73
// CHANGE HISTORY
74
//
75
// Version By Change Description
76
// 0.01 SAJH Initial implementation.
77
//-----------------------------------------------------------------------------
78

79 class Log {
80
81     /**A reference to the LogControl object.
82      * @seecom.ibm.jts.logger.LogControl
83      */

84     private LogControl logControl = null;
85
86     /**The log path.
87      */

88     // private static String logPath = null;
89
private String JavaDoc logPath = null;
90     /*
91         Logger to log transaction messages
92     */

93     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
94
95     /**Default Log constructor.
96      *
97      * @param
98      *
99      * @return
100      *
101      * @see
102      */

103     Log() {
104         // We need to ensure that messaging is initialised as this may be called
105
// prior to SOMTR_Init.
106

107         // Initialise the instance variables.
108

109         logControl = null;
110
111         // Get the log path. If it is not set, or blank, then set it to the current
112
// directory.
113

114         if( logPath == null ) {
115             int[] result = new int[1];
116             logPath = Configuration.getDirectory(Configuration.LOG_DIRECTORY,
117                                                  Configuration.JTS_SUBDIRECTORY,
118                                                  result);
119
120             // If a default was used, display a message.
121

122             if( result[0] == Configuration.DEFAULT_USED ||
123                 result[0] == Configuration.DEFAULT_INVALID ) {
124
125                 // In the case where the SOMBASE default is used, only display a message
126
// if an invalid value was specified in the environment value.
127

128                 if( logPath.length() > 0 ) {
129                         _logger.log(Level.WARNING,"jts.invalid_log_path",logPath);
130                 }
131
132                 // In the case where the SOMBASE default is invalid, the value returned is
133
// the invalid default. We then default to the current directory.
134

135                 if( result[0] == Configuration.DEFAULT_INVALID ) {
136                         _logger.log(Level.WARNING,"jts.invalid_default_log_path");
137                     logPath = "."/*#Frozen*/;
138                 }
139             }
140         }
141
142     }
143
144
145     Log(String JavaDoc logPath) {
146         logControl = null;
147         this.logPath = logPath;
148     }
149
150     /**Default Log destructor.
151      *
152      * @param
153      *
154      * @return
155      *
156      * @see
157      */

158     public void finalize() {
159
160         logControl = null;
161         logPath = null;
162
163     }
164
165     /**Initialises the log.
166      *
167      * @param
168      *
169      * @return
170      *
171      * @see
172      */

173     boolean initialise() {
174         boolean result = true;
175
176         // Call the initialize operation for the log
177

178         logControl = new LogControl();
179         logControl.initLog(false,false,logPath);
180
181         return result;
182     }
183
184
185     /**Opens the log for the given server.
186      * <p>
187      * The given LogSOS object, if any, will be called in the event of the log
188      * going short-on-storage. A LogFile object reference is returned that is used
189      * for operations on the specific portion of the log.
190      *
191      * @param serverName The name of the server whose log file is being opened.
192      * @param upcall The object which will handle upcalls from the log.
193      *
194      * @return The object representing the physical log file.
195      *
196      * @see
197      */

198     LogFile open( String JavaDoc serverName,
199                   LogUpcallTarget upcall ) {
200
201         LogFile logFile = null;
202
203         boolean[] newLog = new boolean[1]; newLog[0] = true;
204
205         // Open the log using the server name.
206

207         try {
208             LogHandle handle = logControl.openFile(serverName,upcall,null,newLog);
209
210             // Create a new LogFile object with the handle to represent the open log.
211

212             logFile = new LogFile(handle);
213         }
214
215         // If the log open failed, report the error.
216

217         catch( LogException le ) {
218             _logger.log(Level.SEVERE,"jts.log_error",le.toString());
219              String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,"jts.log_error",
220                                         new java.lang.Object JavaDoc[] {le.toString()});
221               throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
222         }
223
224         return logFile;
225     }
226
227     /**Terminates the log.
228      *
229      * @param
230      *
231      * @return
232      *
233      * @see
234      */

235     boolean terminate() {
236
237         boolean result = true;
238
239         // No special action needed after the close for the logger
240

241         return result;
242     }
243
244     /**Determines whether a log file exists for the given server.
245      * <p>
246      * This method may be used without initialising the Log object to determine
247      * whether recovery should be performed, without initialising the log or the OTS.
248      *
249      * @param String
250      *
251      * @return
252      *
253      * @see
254      */

255     static boolean checkFileExists( String JavaDoc serverName ) {
256         boolean exists = false;
257
258         // Check whether the file exists.
259

260         if( serverName != null ) {
261             String JavaDoc logPath = null;
262             int[] result = new int[1];
263             logPath = Configuration.getDirectory(Configuration.LOG_DIRECTORY,
264                                                  Configuration.JTS_SUBDIRECTORY,
265                                                  result);
266
267             // If a default was used, display a message.
268

269             if( result[0] == Configuration.DEFAULT_USED ||
270                 result[0] == Configuration.DEFAULT_INVALID ) {
271
272                 // In the case where the SOMBASE default is used, only display a message
273
// if an invalid value was specified in the environment value.
274

275                 if( logPath.length() > 0 ) {
276                      _logger.log(Level.WARNING,"jts.invalid_log_path",logPath);
277                 }
278
279                 // In the case where the SOMBASE default is invalid, the value returned is
280
// the invalid default. We then default to the current directory.
281

282                 if( result[0] == Configuration.DEFAULT_INVALID ) {
283                                                 _logger.log(Level.WARNING,"jts.invalid_default_log_path");
284                     logPath = "."/*#Frozen*/;
285                 }
286             }
287             exists = LogControl.checkFileExists(serverName,logPath);
288         }
289
290
291         return exists;
292     }
293
294     /**Dumps the state of the object.
295      *
296      * @param
297      *
298      * @return
299      *
300      * @see
301      */

302     void dump() {
303         //! somtrDUMP_OBJECT_HEADER;
304

305         // Dump all of the instance variables in the LogFile object, without going
306
// any further down object references.
307

308         logControl.dump();
309     }
310 }
311
Popular Tags