1 23 38 package com.sun.enterprise.web.connector.grizzly; 39 40 import java.net.InetAddress ; 41 import java.net.URLEncoder ; 42 import java.util.Enumeration ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 import javax.management.ObjectName ; 46 47 import com.sun.org.apache.commons.modeler.Registry; 48 import org.apache.coyote.http11.Http11Protocol; 49 import org.apache.tomcat.util.net.SSLImplementation; 50 import org.apache.tomcat.util.net.ServerSocketFactory; 51 52 60 public class GrizzlyHttpProtocol extends Http11Protocol { 61 62 private int socketBuffer = 9000; 63 64 67 private SelectorThread selectorThread; 68 69 72 private String noCompressionUserAgents = null; 73 private String restrictedUserAgents = null; 74 private String compressableMimeTypes = "text/html,text/xml,text/plain"; 75 private int compressionMinSize = 2048; 76 77 79 83 protected void create() { 84 85 selectorThread = new SelectorThread(); 87 88 setSoLinger(-1); 89 setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT); 90 setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT); 91 setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY); 92 } 93 94 95 99 public void init() throws Exception { 100 try { 101 checkSocketFactory(); 102 } catch( Exception ex ) { 103 SelectorThread.logger().log(Level.SEVERE, 104 "grizzlyHttpProtocol.socketfactory.initerror",ex); 105 throw ex; 106 } 107 108 if( socketFactory!=null ) { 109 Enumeration attE=attributes.keys(); 110 while( attE.hasMoreElements() ) { 111 String key=(String )attE.nextElement(); 112 Object v=attributes.get( key ); 113 socketFactory.setAttribute( key, v ); 114 } 115 } 116 117 try { 118 selectorThread.setAdapter(adapter); 119 selectorThread.initEndpoint(); 120 } catch (Exception ex) { 121 SelectorThread.logger().log(Level.SEVERE, 122 "grizzlyHttpProtocol.endpoint.initerror", ex); 123 throw ex; 124 } 125 } 126 127 128 public void start() throws Exception { 129 try { 130 if ( this.oname != null ) { 131 try { 132 Registry.getRegistry().registerComponent 133 (selectorThread, this.domain, "selectorThread", 134 "type=Selector,name=http" + selectorThread.getPort()); 135 } catch (Exception ex) { 136 SelectorThread.logger().log(Level.SEVERE, 137 "grizzlyHttpProtocol.selectorRegistrationFailed", ex); 138 } 139 } else { 140 SelectorThread.logger().log(Level.INFO, 141 "grizzlyHttpProtocol.selectorRegisterProtocol"); 142 } 143 144 selectorThread.start(); 145 } catch (Exception ex) { 146 SelectorThread.logger().log(Level.SEVERE, 147 "grizzlyHttpProtocol.endpoint.starterror", 148 ex); 149 throw ex; 150 } 151 152 SelectorThread.logger().log(Level.INFO, 153 "grizzlyHttpProtocol.start", String.valueOf(getPort())); 154 } 155 156 public void pause() throws Exception { 157 try { 158 selectorThread.pauseEndpoint(); 159 } catch (Exception ex) { 160 SelectorThread.logger().log(Level.SEVERE, 161 "grizzlyHttpProtocol.endpoint.pauseerror", 162 ex); 163 throw ex; 164 } 165 SelectorThread.logger().log(Level.INFO, 166 "grizzlyHttpProtocol.pause", String.valueOf(getPort())); 167 } 168 169 public void resume() throws Exception { 170 try { 171 selectorThread.resumeEndpoint(); 172 } catch (Exception ex) { 173 SelectorThread.logger().log(Level.SEVERE, 174 "grizzlyHttpProtocol.endpoint.resumeerror", 175 ex); 176 throw ex; 177 } 178 SelectorThread.logger().log(Level.INFO, 179 "grizzlyHttpProtocol.resume", 180 String.valueOf(getPort())); 181 } 182 183 public void destroy() throws Exception { 184 SelectorThread.logger().log(Level.INFO, 185 "grizzlyHttpProtocol.stop", 186 String.valueOf(getPort())); 187 188 if ( domain != null ){ 189 Registry.getRegistry(). 190 unregisterComponent(new ObjectName (domain,"type", "Selector")); 191 } 192 selectorThread.stopEndpoint(); 193 } 194 195 196 198 199 public int getMaxThreads() { 200 return selectorThread.getMaxThreads(); 201 } 202 203 public void setMaxThreads( int maxThreads ) { 204 selectorThread.setMaxThreads(maxThreads); 205 setAttribute("maxThreads", "" + maxThreads); 206 } 207 208 209 public int getProcessorThreadsIncrement() { 210 return selectorThread.threadsIncrement; 211 } 212 213 214 public void setProcessorThreadsIncrement( int threadsIncrement ) { 215 selectorThread.threadsIncrement = threadsIncrement; 216 setAttribute("threadsIncrement", "" + threadsIncrement); 217 } 218 219 220 public void setProcessorWorkerThreadsTimeout(int timeout){ 221 selectorThread.threadsTimeout = timeout; 222 setAttribute("threadsTimeout", "" + timeout); 223 } 224 225 226 public int getProcessorWorkerThreadsTimeout(){ 227 return selectorThread.threadsTimeout; 228 } 229 231 public int getBacklog() { 232 return selectorThread.ssBackLog; 233 } 234 235 public void setBacklog( int i ) { 236 ; 237 } 238 239 public int getPort() { 240 return selectorThread.getPort(); 241 } 242 243 public void setPort( int port ) { 244 selectorThread.setPort(port); 245 setAttribute("port", "" + port); 246 } 248 249 public InetAddress getAddress() { 250 return selectorThread.getAddress(); 251 } 252 253 public void setAddress(InetAddress ia) { 254 selectorThread.setAddress( ia ); 255 setAttribute("address", "" + ia); 256 } 257 258 public String getName() { 259 String encodedAddr = ""; 260 if (getAddress() != null) { 261 encodedAddr = "" + getAddress(); 262 if (encodedAddr.startsWith("/")) 263 encodedAddr = encodedAddr.substring(1); 264 encodedAddr = URLEncoder.encode(encodedAddr) + "-"; 265 } 266 return ("http-" + encodedAddr + selectorThread.getPort()); 267 } 268 269 public boolean getTcpNoDelay() { 270 return selectorThread.getTcpNoDelay(); 271 } 272 273 public void setTcpNoDelay( boolean b ) { 274 selectorThread.setTcpNoDelay( b ); 275 setAttribute("tcpNoDelay", "" + b); 276 } 277 278 public boolean getDisableUploadTimeout() { 279 return disableUploadTimeout; 280 } 281 282 public void setDisableUploadTimeout(boolean isDisabled) { 283 disableUploadTimeout = isDisabled; 284 } 285 286 public int getSocketBuffer() { 287 return socketBuffer; 288 } 289 290 public void setSocketBuffer(int valueI) { 291 socketBuffer = valueI; 292 } 293 294 public void setMaxHttpHeaderSize(int maxHttpHeaderSize) { 295 super.setMaxHttpHeaderSize(maxHttpHeaderSize); 296 selectorThread.setMaxHttpHeaderSize(maxHttpHeaderSize); 297 } 298 299 public String getRestrictedUserAgents() { 300 return restrictedUserAgents; 301 } 302 303 public void setRestrictedUserAgents(String valueS) { 304 restrictedUserAgents = valueS; 305 setAttribute("restrictedUserAgents", valueS); 306 } 307 308 public String getNoCompressionUserAgents() { 309 return noCompressionUserAgents; 310 } 311 312 public void setNoCompressionUserAgents(String valueS) { 313 noCompressionUserAgents = valueS; 314 setAttribute("noCompressionUserAgents", valueS); 315 } 316 317 public String getCompressableMimeType() { 318 return compressableMimeTypes; 319 } 320 321 public void setCompressableMimeType(String valueS) { 322 compressableMimeTypes = valueS; 323 setAttribute("compressableMimeTypes", valueS); 324 } 325 326 public int getCompressionMinSize() { 327 return compressionMinSize; 328 } 329 330 public void setCompressionMinSize(int valueI) { 331 compressionMinSize = valueI; 332 setAttribute("compressionMinSize", "" + valueI); 333 } 334 335 public int getSoLinger() { 336 return selectorThread.getSoLinger(); 337 } 338 339 public void setSoLinger( int i ) { 340 selectorThread.setSoLinger( i ); 341 setAttribute("soLinger", "" + i); 342 } 343 344 public int getSoTimeout() { 345 return selectorThread.getSoTimeout(); 346 } 347 348 public void setSoTimeout( int i ) { 349 selectorThread.setSoTimeout(i); 350 setAttribute("soTimeout", "" + i); 351 } 352 353 public int getServerSoTimeout() { 354 return selectorThread.getServerSoTimeout(); 355 } 356 357 public void setServerSoTimeout( int i ) { 358 selectorThread.setServerSoTimeout(i); 359 setAttribute("serverSoTimeout", "" + i); 360 } 361 362 public void setSecure( boolean b ) { 363 super.setSecure(b); 364 selectorThread.setSecure(b); 365 } 366 367 370 public void setMaxKeepAliveRequests(int mkar) { 371 selectorThread.setMaxKeepAliveRequests(mkar); 372 } 373 374 375 381 public void setKeepAliveTimeoutInSeconds(int timeout) { 382 selectorThread.setKeepAliveTimeoutInSeconds(timeout); 383 } 384 385 386 391 public void setKeepAliveThreadCount(int threadCount) { 392 selectorThread.setKeepAliveThreadCount(threadCount); 393 } 394 395 396 399 public void setMinThreads(int minThreads){ 400 selectorThread.setMinThreads(minThreads); 401 } 402 403 404 407 public void setBufferSize(int requestBufferSize){ 408 super.setBufferSize(requestBufferSize); 409 selectorThread.setBufferSize(requestBufferSize); 410 } 411 412 413 416 public void setSelectorTimeout(int selectorTimeout){ 417 selectorThread.selectorTimeout = selectorTimeout; 418 } 419 420 421 424 public int getSelectorTimeout(){ 425 return selectorThread.selectorTimeout; 426 } 427 428 429 432 public void setMaxReadWorkerThreads(int maxReadWorkerThreads){ 433 selectorThread.maxReadWorkerThreads = maxReadWorkerThreads; 434 } 435 436 437 440 public int getMaxReadWorkerThreads(){ 441 return selectorThread.maxReadWorkerThreads; 442 } 443 444 445 public void setDisplayConfiguration(boolean displayConfiguration){ 446 selectorThread.displayConfiguration = displayConfiguration; 447 } 448 449 450 public boolean getDisplayConfiguration(){ 451 return selectorThread.displayConfiguration; 452 } 453 454 455 458 public void setRecycleTasks(boolean recycleTasks){ 459 selectorThread.recycleTasks = recycleTasks; 460 } 461 462 463 467 public boolean getRecycleTasks(){ 468 return selectorThread.recycleTasks; 469 } 470 471 472 public void setUseByteBufferView(boolean useByteBufferView){ 473 selectorThread.useByteBufferView = useByteBufferView; 474 } 475 476 477 public boolean getUseByteBufferView(){ 478 return selectorThread.useByteBufferView ; 479 } 480 481 482 485 public void setMaxProcessorWorkerThreads(int maxProcessorWorkerThreads){ 486 selectorThread.maxProcessorWorkerThreads = maxProcessorWorkerThreads; 487 } 488 489 490 493 public int getMaxProcessorWorkerThreads(){ 494 return selectorThread.maxProcessorWorkerThreads; 495 } 496 497 498 502 public void setMinReadQueueLength(int minReadQueueLength){ 503 selectorThread.minReadQueueLength = minReadQueueLength; 504 } 505 506 507 511 public int getMinReadQueueLength(){ 512 return selectorThread.minReadQueueLength; 513 } 514 515 516 520 public void setMinProcessorQueueLength(int minProcessorQueueLength){ 521 selectorThread.minProcessorQueueLength = minProcessorQueueLength; 522 } 523 524 525 529 public int getMinProcessorQueueLength(){ 530 return selectorThread.minProcessorQueueLength; 531 } 532 533 534 537 public void setUseDirectByteBuffer(boolean useDirectByteBuffer){ 538 selectorThread.useDirectByteBuffer = useDirectByteBuffer; 539 } 540 541 542 546 public boolean getUseDirectByteBuffer(){ 547 return selectorThread.useDirectByteBuffer; 548 } 549 550 551 555 public void setQueueSizeInBytes(int maxQueueSizeInBytes){ 556 selectorThread.maxQueueSizeInBytes = maxQueueSizeInBytes; 557 } 558 559 560 563 public void setSocketServerBacklog(int ssBackLog){ 564 selectorThread.ssBackLog = ssBackLog; 565 } 566 567 570 public void setSelectorReadThreadsCount(int selectorReadThreadsCount){ 571 selectorThread.selectorReadThreadsCount = selectorReadThreadsCount; 572 } 573 574 575 580 public void setDefaultResponseType(String defaultResponseType){ 581 selectorThread.defaultResponseType = defaultResponseType; 582 } 583 584 585 588 public String getDefaultResponseType(){ 589 return selectorThread.defaultResponseType; 590 } 591 592 593 599 public void setForcedResponseType(String forcedResponseType){ 600 selectorThread.forcedResponseType = forcedResponseType; 601 } 602 603 604 607 public String getForcedResponseType(){ 608 return selectorThread.forcedResponseType; 609 } 610 611 612 614 615 619 public void setSecondsMaxAge(int sMaxAges){ 620 selectorThread.secondsMaxAge = sMaxAges; 621 } 622 623 624 627 public void setMaxCacheEntries(int mEntries){ 628 selectorThread.maxCacheEntries = mEntries; 629 } 630 631 632 635 public int getMaxCacheEntries(){ 636 return selectorThread.maxCacheEntries; 637 } 638 639 640 643 public void setMinEntrySize(long mSize){ 644 selectorThread.minEntrySize = mSize; 645 } 646 647 648 651 public long getMinEntrySize(){ 652 return selectorThread.minEntrySize; 653 } 654 655 656 659 public void setMaxEntrySize(long mEntrySize){ 660 selectorThread.maxEntrySize = mEntrySize; 661 } 662 663 664 667 public long getMaxEntrySize(){ 668 return selectorThread.maxEntrySize; 669 } 670 671 672 675 public void setMaxLargeCacheSize(long mCacheSize){ 676 selectorThread.maxLargeFileCacheSize = mCacheSize; 677 } 678 679 680 683 public long getMaxLargeCacheSize(){ 684 return selectorThread.maxLargeFileCacheSize; 685 } 686 687 688 691 public void setMaxSmallCacheSize(long mCacheSize){ 692 selectorThread.maxSmallFileCacheSize = mCacheSize; 693 } 694 695 696 699 public long getMaxSmallCacheSize(){ 700 return selectorThread.maxSmallFileCacheSize; 701 } 702 703 704 707 public boolean isFileCacheEnabled(){ 708 return selectorThread.isFileCacheEnabled; 709 } 710 711 712 715 public void setFileCacheEnabled(boolean isFileCacheEnabled){ 716 selectorThread.isFileCacheEnabled = isFileCacheEnabled; 717 } 718 719 720 723 public void setLargeFileCacheEnabled(boolean isLargeEnabled){ 724 selectorThread.isLargeFileCacheEnabled = isLargeEnabled; 725 } 726 727 728 731 public boolean getLargeFileCacheEnabled(){ 732 return selectorThread.isLargeFileCacheEnabled; 733 } 734 735 736 739 public void setWebAppRootPath(String rootFolder){ 740 selectorThread.rootFolder = rootFolder; 741 } 742 743 744 747 public String getWebAppRootPath(){ 748 return selectorThread.rootFolder; 749 } 750 751 752 755 public void setLogger(Logger logger){ 756 if ( logger != null ) 757 selectorThread.logger = logger; 758 } 759 760 761 764 public Logger getLogger(){ 765 return selectorThread.logger; 766 } 767 768 769 772 public SelectorThread selectorThread(){ 773 return selectorThread; 774 } 775 776 777 779 784 private void checkSocketFactory() throws Exception { 785 if (secure) { 786 sslImplementation = 790 SSLImplementation.getInstance(sslImplementationName); 791 socketFactory = sslImplementation.getServerSocketFactory(); 792 selectorThread.setSSLImplementation(sslImplementation); 793 } else if (socketFactoryName != null) { 794 socketFactory = string2SocketFactory(socketFactoryName); 795 } 796 if(socketFactory==null) 797 socketFactory=ServerSocketFactory.getDefault(); 798 selectorThread.setServerSocketFactory(socketFactory); 799 } 800 } 801 802 | Popular Tags |