1 23 24 package com.sun.enterprise.web.connector.coyote; 25 26 import com.sun.enterprise.web.connector.extension.GrizzlyConfig; 27 import java.lang.reflect.Method ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 import org.apache.catalina.Request; 31 import org.apache.catalina.Response; 32 import org.apache.coyote.tomcat5.CoyoteConnector; 33 import org.apache.coyote.tomcat5.CoyoteResponse; 34 import org.apache.coyote.tomcat5.Constants; 35 36 import org.apache.catalina.LifecycleException; 37 38 public class PECoyoteConnector extends CoyoteConnector{ 39 40 private static final String USE_COYOTE_CONNECTOR = 41 "com.sun.enterprise.web.connector.useCoyoteConnector"; 42 43 private static final String GRIZZLY_CONNECTOR = 44 "com.sun.enterprise.web.connector.grizzly.GrizzlyHttpProtocol"; 45 46 47 50 protected boolean recycleObjects; 51 52 53 56 protected int maxAcceptWorkerThreads; 57 58 59 62 protected int maxReadWorkerThreads; 63 64 65 68 protected int processorWorkerThreadsTimeout; 69 70 71 74 protected int minProcessorWorkerThreadsIncrement; 75 76 77 80 protected int minAcceptQueueLength; 81 82 83 86 protected int minReadQueueLength; 87 88 89 92 protected int minProcessorQueueLength; 93 94 95 98 protected boolean useDirectByteBuffer; 99 100 101 private boolean coyoteOn = false; 103 104 107 private int keepAliveTimeoutInSeconds; 108 109 112 private int keepAliveThreadCount; 113 114 117 private boolean chunkingDisabled; 118 119 122 private int queueSizeInBytes = 4096; 123 124 127 protected int ssBackLog = 4096; 128 129 130 133 public int selectorReadThreadsCount = 0; 134 135 136 139 protected String defaultResponseType = Constants.DEFAULT_RESPONSE_TYPE; 140 141 142 145 protected String forcedResponseType = Constants.DEFAULT_RESPONSE_TYPE; 146 147 150 private GrizzlyConfig grizzlyMonitor; 151 152 153 156 private String domain; 157 158 159 162 private String rootFolder = ""; 163 164 165 168 private String name; 169 171 174 private int secondsMaxAge = -1; 175 176 177 180 private int maxCacheEntries = 1024; 181 182 183 186 private long minEntrySize = 2048; 187 188 189 192 private long maxEntrySize = 537600; 193 194 195 198 private long maxLargeFileCacheSize = 10485760; 199 200 201 204 private long maxSmallFileCacheSize = 1048576; 205 206 207 210 private boolean fileCacheEnabled = true; 211 212 213 216 private boolean isLargeFileCacheEnabled = true; 217 218 219 222 private Logger logger; 223 224 226 227 public PECoyoteConnector() { 228 boolean coyoteOn = false; 229 if (System.getProperty(USE_COYOTE_CONNECTOR) != null){ 230 coyoteOn = 231 Boolean.valueOf(System.getProperty(USE_COYOTE_CONNECTOR)) 232 .booleanValue(); 233 } 234 235 if (!coyoteOn) 237 setProtocolHandlerClassName(GRIZZLY_CONNECTOR); 238 } 239 240 241 248 public void setChunkingDisabled(boolean chunkingDisabled) { 249 this.chunkingDisabled = chunkingDisabled; 250 } 251 252 253 257 public boolean isChunkingDisabled() { 258 return this.chunkingDisabled; 259 } 260 261 262 266 public Request createRequest() { 267 268 PwcCoyoteRequest request = new PwcCoyoteRequest(); 269 request.setConnector(this); 270 return (request); 271 272 } 273 274 275 280 public Response createResponse() { 281 282 CoyoteResponse response = new CoyoteResponse(isChunkingDisabled()); 283 response.setConnector(this); 284 return (response); 285 286 } 287 288 289 295 public int getKeepAliveTimeoutInSeconds() { 296 return keepAliveTimeoutInSeconds; 297 } 298 299 300 306 public void setKeepAliveTimeoutInSeconds(int timeout) { 307 keepAliveTimeoutInSeconds = timeout; 308 setProperty("keepAliveTimeoutInSeconds", String.valueOf(timeout)); 309 } 310 311 312 317 public int getKeepAliveThreadCount() { 318 return keepAliveThreadCount; 319 } 320 321 322 327 public void setKeepAliveThreadCount(int threadCount) { 328 keepAliveThreadCount = threadCount; 329 setProperty("keepAliveThreadCount", String.valueOf(threadCount)); 330 } 331 332 333 337 public void setQueueSizeInBytes(int queueSizeInBytes){ 338 this.queueSizeInBytes = queueSizeInBytes; 339 setProperty("queueSizeInBytes", queueSizeInBytes); 340 } 341 342 343 346 public int getQueueSizeInBytes(){ 347 return queueSizeInBytes; 348 } 349 350 351 354 public void setSocketServerBacklog(int ssBackLog){ 355 this.ssBackLog = ssBackLog; 356 setProperty("socketServerBacklog", ssBackLog); 357 } 358 359 360 363 public int getSocketServerBacklog(){ 364 return ssBackLog; 365 } 366 367 368 371 public void setRecycleObjects(boolean recycleObjects){ 372 this.recycleObjects= recycleObjects; 373 setProperty("recycleObjects", 374 String.valueOf(recycleObjects)); 375 } 376 377 378 382 public boolean getRecycleObjects(){ 383 return recycleObjects; 384 } 385 386 387 390 public void setMaxReadWorkerThreads(int maxReadWorkerThreads){ 391 this.maxReadWorkerThreads = maxReadWorkerThreads; 392 setProperty("maxReadWorkerThreads", 393 String.valueOf(maxReadWorkerThreads)); 394 } 395 396 397 400 public int getMaxReadWorkerThreads(){ 401 return maxReadWorkerThreads; 402 } 403 404 405 408 public void setMaxAcceptWorkerThreads(int maxAcceptWorkerThreads){ 409 this.maxAcceptWorkerThreads = maxAcceptWorkerThreads; 410 setProperty("maxAcceptWorkerThreads", 411 String.valueOf(maxAcceptWorkerThreads)); 412 } 413 414 415 418 public int getMaxAcceptWorkerThreads(){ 419 return maxAcceptWorkerThreads; 420 } 421 422 423 427 public void setMinAcceptQueueLength(int minAcceptQueueLength){ 428 this.minAcceptQueueLength = minAcceptQueueLength; 429 setProperty("minAcceptQueueLength", 430 String.valueOf(minAcceptQueueLength)); 431 } 432 433 434 438 public int getMinAcceptQueueLength(){ 439 return minAcceptQueueLength; 440 } 441 442 443 447 public void setMinReadQueueLength(int minReadQueueLength){ 448 this.minReadQueueLength = minReadQueueLength; 449 setProperty("minReadQueueLength", 450 String.valueOf(minReadQueueLength)); 451 } 452 453 454 458 public int getMinReadQueueLength(){ 459 return minReadQueueLength; 460 } 461 462 463 467 public void setMinProcessorQueueLength(int minProcessorQueueLength){ 468 this.minProcessorQueueLength = minProcessorQueueLength; 469 setProperty("minProcessorQueueLength", 470 String.valueOf(minProcessorQueueLength)); 471 } 472 473 474 478 public int getMinProcessorQueueLength(){ 479 return minProcessorQueueLength; 480 } 481 482 483 486 public void setUseDirectByteBuffer(boolean useDirectByteBuffer){ 487 this.useDirectByteBuffer = useDirectByteBuffer; 488 setProperty("useDirectByteBuffer", 489 String.valueOf(useDirectByteBuffer)); 490 } 491 492 493 497 public boolean getUseDirectByteBuffer(){ 498 return useDirectByteBuffer; 499 } 500 501 502 public void setProcessorWorkerThreadsTimeout(int timeout){ 503 this.processorWorkerThreadsTimeout = timeout; 504 setProperty("processorWorkerThreadsTimeout", 505 String.valueOf(timeout)); 506 } 507 508 509 public int getProcessorWorkerThreadsTimeout(){ 510 return processorWorkerThreadsTimeout; 511 } 512 513 514 public void setProcessorWorkerThreadsIncrement(int increment){ 515 this.minProcessorWorkerThreadsIncrement = increment; 516 setProperty("processorThreadsIncrement", 517 String.valueOf(increment)); 518 } 519 520 521 public int getMinProcessorWorkerThreadsIncrement(){ 522 return minProcessorWorkerThreadsIncrement; 523 } 524 525 public void setSelectorReadThreadsCount(int selectorReadThreadsCount){ 526 setProperty("selectorReadThreadsCount", 527 String.valueOf(selectorReadThreadsCount)); 528 } 529 530 531 536 public void setDefaultResponseType(String defaultResponseType){ 537 this.defaultResponseType = defaultResponseType; 538 setProperty("defaultResponseType", defaultResponseType); 539 } 540 541 542 545 public String getDefaultResponseType(){ 546 return defaultResponseType; 547 } 548 549 550 556 public void setForcedResponseType(String forcedResponseType){ 557 this.forcedResponseType = forcedResponseType; 558 setProperty("forcedResponseType", forcedResponseType); 559 } 560 561 562 565 public String getForcedResponseType(){ 566 return forcedResponseType; 567 } 568 569 570 573 public void setDomain(String domain){ 574 this.domain = domain; 575 } 576 577 578 public void start() throws LifecycleException { 579 super.start(); 580 if ( grizzlyMonitor != null ) { 581 grizzlyMonitor.initConfig(); 582 grizzlyMonitor.registerMonitoringLevelEvents(); 583 } 584 } 585 586 587 public void stop() throws LifecycleException { 588 super.stop(); 589 if ( grizzlyMonitor != null ) { 590 grizzlyMonitor.unregisterMonitoringLevelEvents(); 591 } 592 } 593 595 596 600 public void setSecondsMaxAge(int sMaxAges){ 601 secondsMaxAge = sMaxAges; 602 setProperty("secondsMaxAge", String.valueOf(secondsMaxAge)); 603 } 604 605 606 609 public void setMaxCacheEntries(int mEntries){ 610 maxCacheEntries = mEntries; 611 setProperty("maxCacheEntries", String.valueOf(maxCacheEntries)); 612 } 613 614 615 618 public int getMaxCacheEntries(){ 619 return maxCacheEntries; 620 } 621 622 623 626 public void setMinEntrySize(long mSize){ 627 minEntrySize = mSize; 628 setProperty("minEntrySize", String.valueOf(minEntrySize)); 629 } 630 631 632 635 public long getMinEntrySize(){ 636 return minEntrySize; 637 } 638 639 640 643 public void setMaxEntrySize(long mEntrySize){ 644 maxEntrySize = mEntrySize; 645 setProperty("maxEntrySize", String.valueOf(maxEntrySize)); 646 } 647 648 649 652 public long getMaxEntrySize(){ 653 return maxEntrySize; 654 } 655 656 657 660 public void setMaxLargeCacheSize(long mCacheSize){ 661 maxLargeFileCacheSize = mCacheSize; 662 setProperty("maxLargeFileCacheSize", 663 String.valueOf(maxLargeFileCacheSize)); 664 } 665 666 667 670 public long getMaxLargeCacheSize(){ 671 return maxLargeFileCacheSize; 672 } 673 674 675 678 public void setMaxSmallCacheSize(long mCacheSize){ 679 maxSmallFileCacheSize = mCacheSize; 680 setProperty("maxSmallFileCacheSize", 681 String.valueOf(maxSmallFileCacheSize)); 682 } 683 684 685 688 public long getMaxSmallCacheSize(){ 689 return maxSmallFileCacheSize; 690 } 691 692 693 696 public boolean isFileCacheEnabled(){ 697 return fileCacheEnabled; 698 } 699 700 701 704 public void setFileCacheEnabled(boolean fileCacheEnabled){ 705 this.fileCacheEnabled = fileCacheEnabled; 706 setProperty("fileCacheEnabled",String.valueOf(fileCacheEnabled)); 707 } 708 709 710 713 public void setLargeFileCacheEnabled(boolean isLargeEnabled){ 714 this.isLargeFileCacheEnabled = isLargeEnabled; 715 setProperty("largeFileCacheEnabled", 716 String.valueOf(isLargeFileCacheEnabled)); 717 } 718 719 720 723 public boolean getLargeFileCacheEnabled(){ 724 return isLargeFileCacheEnabled; 725 } 726 727 729 730 733 public void setWebAppRootPath(String rootFolder){ 734 this.rootFolder = rootFolder; 735 setProperty("webAppRootPath",rootFolder); 736 } 737 738 739 742 public String getWebAppRootPath(){ 743 return rootFolder; 744 } 745 746 747 751 public void setLogger(Logger logger){ 752 this.logger = logger; 753 } 754 755 756 759 public void initialize() throws LifecycleException{ 760 super.initialize(); 761 762 if ( !getProtocolHandler().getClass() 763 .getName().equals(GRIZZLY_CONNECTOR)){ 764 return; 765 } 766 767 grizzlyMonitor = new GrizzlyConfig(domain,getPort()); 769 770 try{ 772 Method loggerMethod = getProtocolHandler().getClass().getMethod 773 ("setLogger", new Class []{java.util.logging.Logger .class}); 774 loggerMethod.invoke(getProtocolHandler(), new Object []{logger}); 775 } catch(Exception ex) { 776 logger.log(Level.WARNING, 777 "Unable to set logger on " + getProtocolHandler(), ex); 778 } 779 } 780 781 782 785 public void setName(String name){ 786 this.name = name; 787 } 788 789 790 793 public String getName(){ 794 return name; 795 } 796 } 797 798 | Popular Tags |