1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 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 ; 62 import java.util.logging.Level ; 63 import com.sun.logging.LogDomains; 64 import com.sun.jts.utils.LogFormatter; 65 66 74 80 public class Configuration extends Object { 81 private static String serverName = null; 82 private static byte[] serverNameByteArray = null; 83 private static org.omg.CORBA.ORB 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 dbLogResource = null; 92 private static boolean disableFileLogging = false; 93 94 private static Hashtable logPathToServernametable = new Hashtable(); 96 private static Hashtable logPathToFiletable = new Hashtable(); 97 98 private static int retries = -1; 99 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 110 111 114 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 115 116 public static boolean traceOn = false; 117 118 125 public final static String TRACE_DIRECTORY = "com.sun.jts.traceDirectory"; 126 127 135 public final static String LOG_DIRECTORY = "com.sun.jts.logDirectory"; 136 137 143 public final static String DB_LOG_RESOURCE = "com.sun.jts.logResource"; 144 145 150 public final static String ERR_LOGGING = "com.sun.jts.errorLogging"; 151 152 158 public final static String MANUAL_RECOVERY = "com.sun.jts.ManualRecovery"; 159 160 168 public final static String COMMIT_RETRY = "com.sun.jts.commitRetry"; 169 170 180 public final static String HEURISTIC_DIRECTION = "com.sun.jts.heuristicDirection"; 181 182 195 public final static String KEYPOINT_COUNT = "com.sun.jts.keypointCount"; 196 197 206 public final static String TIMEOUT_INTERVAL = "com.sun.jts.timeoutInterval" ; 207 208 210 public final static String JTS_SUBDIRECTORY = "jts"; 211 212 215 public final static int DIRECTORY_OK = 0; 216 217 221 public final static int DEFAULT_USED = 1; 222 223 228 public final static int DEFAULT_INVALID = 2; 229 230 232 public final static int EXPECTED_CONCURRENT_TRANSACTIONS = 10000; 233 234 236 public final static int EXPECTED_CONCURRENT_THREADS = 100; 237 238 253 public static String getDirectory( String envDir, 254 String defaultSubdirectory, 255 int[] result ) { 256 257 259 String envValue = null; 260 if( prop != null ) 261 envValue = prop.getProperty(envDir); 262 263 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 274 envValue = new String ("."+File.separator+defaultSubdirectory); 275 if( !new File(envValue).isDirectory() ) { 276 result[0] = DEFAULT_INVALID; 277 } 278 } 279 if(_logger.isLoggable(Level.FINE)) 280 { 281 String 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 311 public static final void setServerName( String name, boolean recoverableServer ) { 312 313 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 339 public static final String getServerName() { 340 341 343 String result = serverName; 344 345 return result; 346 } 347 348 359 public static final void setServerName(String logPath, String name) { 360 logPathToServernametable.put(logPath, name); 361 } 362 363 372 public static final String getServerName(String logPath) { 373 return (String )logPathToServernametable.get(logPath); 374 } 375 376 387 public static final byte [] getServerNameByteArray() { 388 389 391 byte [] result = serverNameByteArray; 392 393 return result; 394 } 395 396 404 public static final void setProperties( Properties newProp ) { 405 406 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 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 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 441 public static final String getPropertyValue( String envValue ) { 442 443 445 String 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 469 public static final void setORB( org.omg.CORBA.ORB newORB ) { 470 471 473 orb = newORB; 474 475 } 476 477 478 486 public static final org.omg.CORBA.ORB getORB() { 487 488 489 491 492 return orb; 493 } 494 495 496 507 public static final void setFactory( TransactionFactory newFactory, 508 boolean localTxFactory ) { 509 510 512 factory = newFactory; 513 localFactory = localTxFactory; 514 } 515 516 517 525 public static final TransactionFactory getFactory() { 526 527 529 return factory; 530 } 531 532 540 public static final boolean isLocalFactory() { 541 542 544 boolean result = localFactory; 545 546 return result; 547 } 548 549 557 public static final boolean isRecoverable() { 558 559 561 boolean result = recoverable; 562 563 return result; 564 } 565 573 public static final void setProxyChecker( ProxyChecker newChecker ) { 574 575 576 578 checker = newChecker; 579 580 } 581 582 590 public static final ProxyChecker getProxyChecker() { 591 return checker; 592 } 593 594 595 603 public static final void setLogFile( LogFile newLogFile ) { 604 605 606 608 logFile = newLogFile; 609 610 } 611 612 613 621 public static final LogFile getLogFile() { 622 return logFile; 623 } 624 625 635 public static final void setLogFile(String logPath, LogFile newLogFile) { 636 logPathToFiletable.put(logPath, newLogFile); 637 } 638 646 public static final LogFile getLogFile(String logPath) { 647 if (logPath == null) return null; 648 return (LogFile)logPathToFiletable.get(logPath); 649 } 650 651 652 661 public static final void setPOA( String type, POA poa ) { 662 664 poas.put(type,poa); 665 666 } 667 668 669 677 public static final POA getPOA( String 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 public static void setKeypointTrigger(int keypoint) 704 { 705 CoordinatorLogPool.getCoordinatorLog().setKeypointTrigger(keypoint); 706 } 707 public static void setCommitRetryVar(String commitRetryString) 708 { 709 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 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 |