KickJava   Java API By Example, From Geeks To Geeks.

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


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: Configuration.java
31
//
32
// Description: JTS configuration management.
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.io.*;
55 import java.util.*;
56
57 import org.omg.CosTransactions.*;
58 import org.omg.PortableServer.*;
59
60 import com.sun.jts.trace.*;
61 import java.util.logging.Logger JavaDoc;
62 import java.util.logging.Level JavaDoc;
63 import com.sun.logging.LogDomains;
64 import com.sun.jts.utils.LogFormatter;
65
66 /**Provides interaction with the execution environment.
67  *
68  * @version 0.01
69  *
70  * @author Simon Holdsworth, IBM Corporation
71  *
72  * @see
73 */

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

80 public class Configuration extends Object JavaDoc {
81     private static String JavaDoc serverName = null;
82     private static byte[] serverNameByteArray = null;
83     private static org.omg.CORBA.ORB JavaDoc orb = null;
84     private static Properties prop = null;
85     private static TransactionFactory factory = null;
86     private static boolean localFactory = false;
87     private static boolean recoverable = false;
88     private static ProxyChecker checker = null;
89     private static LogFile logFile = null;
90     private static Hashtable poas = new Hashtable();
91     private static String JavaDoc dbLogResource = null;
92     private static boolean disableFileLogging = false;
93
94     // for delegated recovery support
95
private static Hashtable logPathToServernametable = new Hashtable();
96     private static Hashtable logPathToFiletable = new Hashtable();
97
98     private static int retries = -1;
99     // LAO_PREPARE_OK is a magic number. Assimung no valid XAResource.prepare returns
100
// 123456 as a return value. LAO resource'd prepare method returns this value
101
public static final int LAO_PREPARE_OK = 123456;
102     public final static long COMMIT_RETRY_WAIT = 60000;
103     private static boolean isAppClient = true;
104
105 /**
106    The traceOn would enable/disable JTS wide tracing;
107    (Related class: com.sun.jts.trace.TraceUtil)
108    - kannan.srinivasan@Sun.COM 27Nov2001
109 */

110     
111     /*
112         Logger to log transaction messages
113     */

114     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
115
116    public static boolean traceOn = false;
117
118    /**The property key used to specify the directory to which trace files and the
119      * error log should be written.
120      * <p>
121      * The value is <em><b>com.sun.jts.traceDirectory</b></em>.
122      * <p>
123      * The default value used for this property is the current directory.
124      */

125     public final static String JavaDoc TRACE_DIRECTORY = "com.sun.jts.traceDirectory"/*#Frozen*/;
126
127     /**The property key used to specify the directory to which transaction log files
128      * should be written.
129      * <p>
130      * The value is <em><b>com.sun.jts.logDirectory</b></em>.
131      * <p>
132      * The default value used for this property is the "jts" subdirectory from the
133      * current directory, if that exists, otherwise the current directory.
134      */

135     public final static String JavaDoc LOG_DIRECTORY = "com.sun.jts.logDirectory"/*#Frozen*/;
136
137     /**The property key used to specify the resource which will be used to wirte
138      * transaction logs.
139      * <p>
140      * The value is <em><b>com.sun.jts.logResource</b></em>.
141      * <p>
142      */

143     public final static String JavaDoc DB_LOG_RESOURCE = "com.sun.jts.logResource"/*#Frozen*/;
144
145     /**
146      * Whether to write warnings and errors to jts.log file
147      * if this property has any value, it is active, otherwise it is inactive
148      *
149      */

150     public final static String JavaDoc ERR_LOGGING = "com.sun.jts.errorLogging"/*#Frozen*/;
151
152     /**
153      * This property indicates that XA Resources would be passed in via
154      * the TM.recover() method, and that the recovery thread would have
155      * to wait until the resources are passed in. If not set, the recovery
156      * thread would not wait for the XA Resources to be passed in.
157      */

158     public final static String JavaDoc MANUAL_RECOVERY = "com.sun.jts.ManualRecovery"/*#Frozen*/;
159
160     /**The property key used to specify the number of times the JTS should retry
161      * a commit or resync operation before giving up.
162      * <p>
163      * The value is <em><b>com.sun.jts.commitRetry</b></em>.
164      * <p>
165      * If this property has no value, retries continue indefinitely. A value of
166      * zero indicates that no retries should be made.
167      */

168     public final static String JavaDoc COMMIT_RETRY = "com.sun.jts.commitRetry"/*#Frozen*/;
169
170     /**The property key used to specify whether the JTS should assume a transaction
171      * is to be committed or rolled back if an outcome cannot be obtained during
172      * recovery. It should also be used by Resource objects if they cannot obtain
173      * an outcome during recovery and cannot make a decision.
174      * <p>
175      * The value is <em><b>com.sun.jts.heuristicDirection</b></em>.
176      * <p>
177      * The default is to assume that the transaction should be rolled back. If the
178      * value is '1', the transaction should be committed.
179      */

180     public final static String JavaDoc HEURISTIC_DIRECTION = "com.sun.jts.heuristicDirection"/*#Frozen*/;
181
182     /**The property key used to specify the number of transactions between keypoint
183      * operations on the log. Keypoint operations reduce the size of the transaction
184      * log files. A larger value for this property (for example, 1000) will result
185      * in larger transaction log files, but less keypoint operations, and hence better
186      * performance. a smaller value (e.g. 20) results in smaller log files but
187      * slightly reduced performance due to the greater frequency of keypoint
188      * operations.
189      * <p>
190      * The value is <em><b>com.sun.jts.keypointCount</b></em>.
191      * <p>
192      * The default value for this property is 100. If the value is specified as
193      * zero, then no keypoints are taken.
194      */

195     public final static String JavaDoc KEYPOINT_COUNT = "com.sun.jts.keypointCount"/*#Frozen*/;
196
197     /**The property is used to specify the time interval in seconds for which the timeout
198      * manager would scan for timedout transactions. A higher value would mean better
199      * performance, but at the cost of closeness to which coordinator timeout is effected.
200      * <p>
201      * The value is <em><b>com.sun.jts.timeoutInterval"</b></em>
202      * <p>
203      * This needs to be a positive integer value greater than 10. If the value is less than
204      * 10, illegal or unspecified a default value of 10 seconds is assumed.
205      */

206     public final static String JavaDoc TIMEOUT_INTERVAL = "com.sun.jts.timeoutInterval" ;
207
208     /**The default subdirectory in which log and repository files are stored.
209      */

210     public final static String JavaDoc JTS_SUBDIRECTORY = "jts"/*#Frozen*/;
211
212     /**getDirectory return value which indicates that the required directory was
213      * specified and is OK.
214      */

215     public final static int DIRECTORY_OK = 0;
216
217     /**getDirectory return value which indicates that the required directory was
218      * either not specified or was specified and invalid, and that the default
219      * subdirectory exists. In this case the default subdirectory should be used.
220      */

221     public final static int DEFAULT_USED = 1;
222
223     /**getDirectory return value which indicates that the required directory was
224      * either not specified or was specified and invalid, and that the default
225      * subdirectory does not exist. In this case the current directory should be
226      * used.
227      */

228     public final static int DEFAULT_INVALID = 2;
229
230     /**The approximate concurrent transactions expected. This is used to set the capacity of Vectors etc.
231     */

232     public final static int EXPECTED_CONCURRENT_TRANSACTIONS = 10000;
233
234     /**The approximate concurrent transactions expected. This is used to set the capacity of Vectors etc.
235     */

236     public final static int EXPECTED_CONCURRENT_THREADS = 100;
237
238     /**Returns a valid directory for a particular purpose. If the required
239      * directory is not valid, then a default subdirectory of the current directory
240      * is tried. If that is not valid either, then the current directory is used.
241      *
242      * @param envDir The environment variable containing the directory.
243      * @param defaultSubdirectory The default subdirectory to use.
244      * @param result A single-element array which will hold a value
245      * indicating whether the requested directory,
246      * default subdirectory, or current directory
247      * had to be used.
248      *
249      * @return The directory name.
250      *
251      * @see
252      */

253     public static String JavaDoc getDirectory( String JavaDoc envDir,
254                                        String JavaDoc defaultSubdirectory,
255                                        int[/*1*/] result ) {
256
257         // Get the environment variable value.
258

259         String JavaDoc envValue = null;
260         if( prop != null )
261             envValue = prop.getProperty(envDir);
262
263         // If the environment variable is not set, or does not refer to a valid
264
// directory, then try to use a default.
265

266         result[0] = DIRECTORY_OK;
267
268         if( envValue == null || envValue.length() == 0 ||
269             !new File(envValue).isDirectory() ) {
270             result[0] = DEFAULT_USED;
271
272             // If the default subdirectory is not valid, then use the current directory.
273

274             envValue = new String JavaDoc("."+File.separator+defaultSubdirectory/*#Frozen*/);
275             if( !new File(envValue).isDirectory() ) {
276                 result[0] = DEFAULT_INVALID;
277             }
278         }
279     if(_logger.isLoggable(Level.FINE))
280     {
281         String JavaDoc dirType="";
282         switch(result[0]){
283         case DEFAULT_INVALID:
284             dirType="used default, but is invalid";
285             break;
286         case DEFAULT_USED :
287             dirType="used default";
288             break;
289         case DIRECTORY_OK:
290             dirType="provided in configuration";
291             break;
292         default:
293             dirType="invalid type";
294             break;
295         }
296         _logger.logp(Level.FINE,"Configuration","getDirectory()",
297                 "Using directory = " + envValue + " : "+dirType);
298     }
299
300         return envValue;
301     }
302
303     /**Sets the name of the server.
304      *
305      * @param name The server name. Non-recoverable servers have null.
306      *
307      * @return
308      *
309      * @see
310      */

311     public static final void setServerName( String JavaDoc name, boolean recoverableServer ) {
312
313         // Store the server name.
314

315         serverName = name;
316           serverNameByteArray = (name == null) ? null : serverName.getBytes();
317         recoverable = recoverableServer;
318         if(recoverable)
319             RecoveryManager.createRecoveryFile(serverName);
320         if(_logger.isLoggable(Level.FINE))
321         {
322             _logger.logp(Level.FINE,"Configuration" ,"setServerName()",
323                     " serverName = " +
324                      serverName + "; isRecoverable = " + recoverable);
325         }
326     }
327
328     /**Returns the name of the server.
329      * <p>
330      * Non-recoverable servers may not have a name, in which case the method returns
331      * null.
332      *
333      * @param
334      *
335      * @return The server name.
336      *
337      * @see
338      */

339     public static final String JavaDoc getServerName() {
340
341         // Determine the server name.
342

343         String JavaDoc result = serverName;
344
345         return result;
346     }
347
348     /**Sets the name of the server for the given log path. Added for delegated
349      * recovery support.
350      *
351      * @param logPath Location, where the logs are stored.
352      *
353      * @param name The server name.
354      *
355      * @return
356      *
357      * @see
358      */

359     public static final void setServerName(String JavaDoc logPath, String JavaDoc name) {
360         logPathToServernametable.put(logPath, name);
361     }
362
363     /**Returns the name of the server for the given log path. Added for delegated
364      *recovery support.
365      *
366      * @param logPath location of the log files.
367      *
368      * @return The server name.
369      *
370      * @see
371      */

372     public static final String JavaDoc getServerName(String JavaDoc logPath) {
373         return (String JavaDoc)logPathToServernametable.get(logPath);
374     }
375
376     /**Returns a byte array with the name of the server.
377      * <p>
378      * Non-recoverable servers may not have a name, in which case the method returns
379      * null.
380      *
381      * @param
382      *
383      * @return The server name (byte array).
384      *
385      * @see
386      */

387     public static final byte [] getServerNameByteArray() {
388
389         // Determine the server name.
390

391         byte [] result = serverNameByteArray;
392
393         return result;
394     }
395
396     /**Sets the Properties object to be used for this JTS instance.
397      *
398      * @param prop The Properties.
399      *
400      * @return
401      *
402      * @see
403      */

404     public static final void setProperties( Properties newProp ) {
405
406         // Store the Properties object.
407
if (prop == null)
408             prop = newProp;
409         else if (newProp != null)
410             prop.putAll(newProp);
411
412         if(_logger.isLoggable(Level.FINE))
413         {
414           String JavaDoc propertiesList = LogFormatter.convertPropsToString(prop);
415          _logger.logp(Level.FINE,"Configuration","setProperties()",
416                 " Properties set are :"+ propertiesList);
417         }
418         if (prop != null) {
419             dbLogResource = prop.getProperty(DB_LOG_RESOURCE);
420             String JavaDoc retryLimit = prop.getProperty(COMMIT_RETRY);
421             int retriesInMinutes;
422             if (retryLimit != null) {
423                retriesInMinutes = Integer.parseInt(retryLimit,10);
424                if ((retriesInMinutes % (COMMIT_RETRY_WAIT / 1000)) == 0)
425                    retries = (int)(retriesInMinutes / (COMMIT_RETRY_WAIT / 1000));
426                else
427                    retries = ((int)((retriesInMinutes / (COMMIT_RETRY_WAIT / 1000)))) + 1;
428             }
429         }
430
431     }
432
433     /**Returns the value of the given variable.
434      *
435      * @param envValue The environment variable required.
436      *
437      * @return The value.
438      *
439      * @see
440      */

441     public static final String JavaDoc getPropertyValue( String JavaDoc envValue ) {
442
443         // Get the environment variable value.
444

445         String JavaDoc result = null;
446         if( prop != null )
447         {
448             result = prop.getProperty(envValue);
449             if(_logger.isLoggable(Level.FINE))
450             {
451                 _logger.log(Level.FINE,"Property :"+ envValue +
452                         " has the value : " + result);
453
454             }
455         }
456
457         return result;
458     }
459
460
461     /**Sets the identity of the ORB.
462      *
463      * @param newORB The ORB.
464      *
465      * @return
466      *
467      * @see
468      */

469     public static final void setORB( org.omg.CORBA.ORB JavaDoc newORB ) {
470
471         // Store the ORB identity.
472

473         orb = newORB;
474
475     }
476
477
478     /**Returns the identity of the ORB.
479      *
480      * @param
481      *
482      * @return The ORB.
483      *
484      * @see
485      */

486     public static final org.omg.CORBA.ORB JavaDoc getORB() {
487
488
489         // Return the ORB identity.
490

491
492         return orb;
493     }
494
495
496     /**Sets the identity of the TransactionFactory and indicates if it is local
497      * or remote.
498      *
499      * @param newFactory The TransactionFactory.
500      *
501      * @param localFactory Indicates if the factory is local or remote.
502      *
503      * @return
504      *
505      * @see
506      */

507     public static final void setFactory( TransactionFactory newFactory,
508                                               boolean localTxFactory ) {
509
510         // Store the factory identity and if it is local or not.
511

512         factory = newFactory;
513         localFactory = localTxFactory;
514     }
515
516
517     /**Returns the identity of the TransactionFactory.
518      *
519      * @param
520      *
521      * @return The TransactionFactory.
522      *
523      * @see
524      */

525     public static final TransactionFactory getFactory() {
526
527         // Return the TransactionFactory identity.
528

529         return factory;
530     }
531
532     /**Determines whether we hava a local factory or a remote factory.
533      *
534      * @param
535      *
536      * @return Indicates whether we have a local factory.
537      *
538      * @see
539      */

540     public static final boolean isLocalFactory() {
541
542         // This is a local factory if localFactory is TRUE
543

544         boolean result = localFactory;
545
546         return result;
547     }
548
549      /**Determines whether the JTS instance is recoverable.
550      *
551      * @param
552      *
553      * @return Indicates whether the JTS is recoverable.
554      *
555      * @see
556      */

557     public static final boolean isRecoverable() {
558
559         // This JTS is recoverable if recoverable is set to TRUE.
560

561         boolean result = recoverable;
562
563         return result;
564     }
565     /**Sets the identity of the ProxyChecker.
566      *
567      * @param newChecker The new ProxyChecker.
568      *
569      * @return
570      *
571      * @see
572      */

573     public static final void setProxyChecker( ProxyChecker newChecker ) {
574
575
576         // Store the checker identity.
577

578         checker = newChecker;
579
580     }
581
582     /**Returns the identity of the ProxyChecker.
583      *
584      * @param
585      *
586      * @return The ProxyChecker.
587      *
588      * @see
589      */

590     public static final ProxyChecker getProxyChecker() {
591         return checker;
592     }
593
594
595     /**Sets the identity of the log file for the process.
596      *
597      * @param logFile The new LogFile object.
598      *
599      * @return
600      *
601      * @see
602      */

603     public static final void setLogFile( LogFile newLogFile ) {
604
605
606         // Store the logFile identity.
607

608         logFile = newLogFile;
609
610     }
611
612
613     /**Returns the identity of the LogFile for the process.
614      *
615      * @param
616      *
617      * @return The LogFile.
618      *
619      * @see
620      */

621     public static final LogFile getLogFile() {
622         return logFile;
623     }
624
625     /**Sets the log file for the given log path. For delegated recovery support.
626      *
627      * @param logPath The new LogFile object.
628      *
629      * @param newLogFile The new LogFile object.
630      *
631      * @return
632      *
633      * @see
634      */

635     public static final void setLogFile(String JavaDoc logPath, LogFile newLogFile) {
636         logPathToFiletable.put(logPath, newLogFile);
637     }
638     /**Returns the LogFile for the given log path. For delegated recovery support.
639      *
640      * @param logPath log location.
641      *
642      * @return The LogFile.
643      *
644      * @see
645      */

646     public static final LogFile getLogFile(String JavaDoc logPath) {
647         if (logPath == null) return null;
648         return (LogFile)logPathToFiletable.get(logPath);
649     }
650
651
652     /**Sets the identity of the POA to be used for the given types of object.
653      *
654      * @param type The type of objects to use the POA.
655      * @param POA The POA object.
656      *
657      * @return
658      *
659      * @see
660      */

661     public static final void setPOA( String JavaDoc type, POA poa ) {
662         // Store the mapping.
663

664         poas.put(type,poa);
665
666     }
667
668
669     /**Returns the identity of the POA to be used for the given type of objects.
670      *
671      * @param type The type of objects
672      *
673      * @return The POA.
674      *
675      * @see
676      */

677     public static final POA getPOA( String JavaDoc type ) {
678
679         POA result = (POA)poas.get(type);
680
681         return result;
682     }
683
684     public static final boolean isTraceEnabled() {
685
686         return traceOn;
687
688     }
689
690     public static final void enableTrace() {
691
692     traceOn = true;
693
694     }
695
696     public static final void disableTrace() {
697
698     traceOn = false;
699
700     }
701
702     // START IASRI 4662745
703
public static void setKeypointTrigger(int keypoint)
704     {
705         CoordinatorLogPool.getCoordinatorLog().setKeypointTrigger(keypoint);
706     }
707     public static void setCommitRetryVar(String JavaDoc commitRetryString)
708     {
709         // RegisteredResources.setCommitRetryVar(commitRetryString);
710
if (commitRetryString != null) {
711             int retriesInMinutes = Integer.parseInt(commitRetryString,10);
712             if ((retriesInMinutes % (COMMIT_RETRY_WAIT / 1000)) == 0)
713                    retries = (int)(retriesInMinutes / (COMMIT_RETRY_WAIT / 1000));
714             else
715                 retries = ((int)(retriesInMinutes / (COMMIT_RETRY_WAIT / 1000))) + 1;
716
717         }
718     }
719     // END IASRI 4662745
720
public static int getRetries() {
721        return retries;
722     }
723
724     public static void setAsAppClientConatiner(boolean value) {
725         isAppClient = value;
726     }
727
728     public static boolean isAppClientContainer() {
729         return isAppClient;
730     }
731
732    static boolean isDBLoggingEnabled() {
733        if (dbLogResource == null)
734            return false;
735        else
736            return true;
737    }
738    
739    public static void disableFileLogging() {
740        disableFileLogging = true;
741    }
742  
743    static boolean isFileLoggingDisabled() {
744        return disableFileLogging;
745    }
746
747 }
748
Popular Tags