| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
package com.sun.grizzly; |
| 39 | |
|
| 40 | |
import com.sun.grizzly.async.AsyncQueueDataProcessor; |
| 41 | |
import com.sun.grizzly.async.AsyncQueueReadable; |
| 42 | |
import com.sun.grizzly.async.AsyncReadCallbackHandler; |
| 43 | |
import com.sun.grizzly.async.AsyncReadCondition; |
| 44 | |
import com.sun.grizzly.async.AsyncWriteCallbackHandler; |
| 45 | |
import com.sun.grizzly.async.AsyncQueueWritable; |
| 46 | |
import com.sun.grizzly.util.InputReader; |
| 47 | |
import com.sun.grizzly.util.OutputWriter; |
| 48 | |
import java.io.IOException; |
| 49 | |
import java.net.Socket; |
| 50 | |
import java.net.SocketAddress; |
| 51 | |
import java.net.SocketException; |
| 52 | |
import java.nio.ByteBuffer; |
| 53 | |
import java.nio.channels.AlreadyConnectedException; |
| 54 | |
import java.nio.channels.NotYetConnectedException; |
| 55 | |
import java.nio.channels.SelectableChannel; |
| 56 | |
import java.nio.channels.SelectionKey; |
| 57 | |
import java.nio.channels.SocketChannel; |
| 58 | |
import java.util.concurrent.CountDownLatch; |
| 59 | |
import java.util.concurrent.TimeUnit; |
| 60 | |
import java.util.logging.Level; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | 34 | public class TCPConnectorHandler implements |
| 94 | |
ConnectorHandler<TCPSelectorHandler, CallbackHandler>, |
| 95 | |
AsyncQueueWritable, AsyncQueueReadable { |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
private static final int DEFAULT_CONNECTION_TIMEOUT = 30 * 1000; |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
protected TCPSelectorHandler selectorHandler; |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
private CallbackHandler callbackHandler; |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
private InputReader inputStream; |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
private SocketChannel socketChannel; |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
private volatile boolean isConnected; |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
private Controller controller; |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
private CountDownLatch isConnectedLatch; |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | 25 | private boolean isStandalone = false; |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | 25 | protected boolean tcpNoDelay = true; |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | 25 | protected boolean reuseAddress = true; |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | 25 | protected int linger = -1; |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | 25 | protected int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
public void connect(SocketAddress remoteAddress, |
| 190 | |
CallbackHandler callbackHandler) throws IOException { |
| 191 | |
|
| 192 | 32 | connect(remoteAddress,null,callbackHandler); |
| 193 | 32 | } |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, |
| 210 | |
CallbackHandler callbackHandler) throws IOException { |
| 211 | |
|
| 212 | 32 | if (controller == null){ |
| 213 | 0 | throw new IllegalStateException("Controller cannot be null"); |
| 214 | |
} |
| 215 | |
|
| 216 | 32 | connect(remoteAddress,localAddress,callbackHandler, |
| 217 | |
(TCPSelectorHandler)controller.getSelectorHandler(protocol())); |
| 218 | 32 | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public void connect(SocketAddress remoteAddress, |
| 235 | |
CallbackHandler callbackHandler, |
| 236 | |
TCPSelectorHandler selectorHandler) throws IOException { |
| 237 | |
|
| 238 | 0 | connect(remoteAddress,null,callbackHandler,selectorHandler); |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, |
| 256 | |
CallbackHandler callbackHandler, |
| 257 | |
TCPSelectorHandler selectorHandler) throws IOException { |
| 258 | |
|
| 259 | 52 | if (isConnected){ |
| 260 | 0 | throw new AlreadyConnectedException(); |
| 261 | |
} |
| 262 | |
|
| 263 | 52 | if (controller == null){ |
| 264 | 0 | throw new IllegalStateException("Controller cannot be null"); |
| 265 | |
} |
| 266 | |
|
| 267 | 52 | if (selectorHandler == null){ |
| 268 | 0 | throw new IllegalStateException("SelectorHandler cannot be null"); |
| 269 | |
} |
| 270 | |
|
| 271 | 52 | this.selectorHandler = selectorHandler; |
| 272 | |
|
| 273 | 52 | if (callbackHandler == null){ |
| 274 | 0 | callbackHandler = new DefaultCallbackHandler(this); |
| 275 | |
} else { |
| 276 | 52 | this.callbackHandler = callbackHandler; |
| 277 | |
} |
| 278 | |
|
| 279 | |
|
| 280 | 52 | isConnectedLatch = new CountDownLatch(1); |
| 281 | |
|
| 282 | 52 | selectorHandler.connect(remoteAddress,localAddress,callbackHandler); |
| 283 | 52 | inputStream = new InputReader(); |
| 284 | |
|
| 285 | |
try { |
| 286 | 52 | isConnectedLatch.await(connectionTimeout, TimeUnit.MILLISECONDS); |
| 287 | 0 | } catch (InterruptedException ex) { |
| 288 | 0 | throw new IOException(ex.getMessage()); |
| 289 | 52 | } |
| 290 | 52 | } |
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
public void connect(SocketAddress remoteAddress) |
| 302 | |
throws IOException { |
| 303 | 20 | connect(remoteAddress,(SocketAddress)null); |
| 304 | 20 | } |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
public void connect(SocketAddress remoteAddress, SocketAddress localAddress) |
| 317 | |
throws IOException { |
| 318 | |
|
| 319 | 20 | if (isConnected){ |
| 320 | 0 | throw new AlreadyConnectedException(); |
| 321 | |
} |
| 322 | |
|
| 323 | 20 | if (controller == null){ |
| 324 | 20 | isStandalone = true; |
| 325 | 20 | controller = new Controller(); |
| 326 | 20 | controller.setSelectorHandler(new TCPSelectorHandler(true)); |
| 327 | 20 | DefaultPipeline pipeline = new DefaultPipeline(); |
| 328 | 20 | pipeline.initPipeline(); |
| 329 | 20 | pipeline.startPipeline(); |
| 330 | 20 | controller.setPipeline(pipeline); |
| 331 | |
|
| 332 | 20 | final CountDownLatch latch = new CountDownLatch(1); |
| 333 | 20 | controller.addStateListener(new ControllerStateListenerAdapter() { |
| 334 | |
@Override |
| 335 | |
public void onReady() { |
| 336 | 20 | latch.countDown(); |
| 337 | 20 | } |
| 338 | |
|
| 339 | |
@Override |
| 340 | |
public void onException(Throwable e) { |
| 341 | 0 | latch.countDown(); |
| 342 | 0 | } |
| 343 | |
}); |
| 344 | |
|
| 345 | 20 | callbackHandler = new DefaultCallbackHandler(this,false); |
| 346 | |
|
| 347 | 20 | new Thread(controller, "GrizzlyTCPConnectorHandler-Controller").start(); |
| 348 | |
|
| 349 | |
try { |
| 350 | 20 | latch.await(); |
| 351 | 0 | } catch (InterruptedException ex) { |
| 352 | 20 | } |
| 353 | |
} |
| 354 | |
|
| 355 | 20 | if (null == callbackHandler) { |
| 356 | 0 | callbackHandler = new DefaultCallbackHandler(this); |
| 357 | |
} |
| 358 | |
|
| 359 | 20 | connect(remoteAddress,localAddress,callbackHandler, |
| 360 | |
(TCPSelectorHandler)controller.getSelectorHandler(protocol())); |
| 361 | 20 | } |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
public long read(ByteBuffer byteBuffer, boolean blocking) throws IOException { |
| 374 | 1605 | if (!isConnected){ |
| 375 | 0 | throw new NotYetConnectedException(); |
| 376 | |
} |
| 377 | |
|
| 378 | 1605 | SelectionKey key = socketChannel.keyFor(selectorHandler.getSelector()); |
| 379 | 1605 | if (blocking){ |
| 380 | 312 | inputStream.setSelectionKey(key); |
| 381 | 312 | return inputStream.read(byteBuffer); |
| 382 | |
} else { |
| 383 | 1293 | if (callbackHandler == null){ |
| 384 | 0 | throw new IllegalStateException |
| 385 | |
("Non blocking read needs a CallbackHandler"); |
| 386 | |
} |
| 387 | 1293 | int nRead = socketChannel.read(byteBuffer); |
| 388 | |
|
| 389 | 1293 | if (nRead == 0){ |
| 390 | 1097 | selectorHandler.register(key,SelectionKey.OP_READ); |
| 391 | |
} |
| 392 | 1293 | return nRead; |
| 393 | |
} |
| 394 | |
} |
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
public long write(ByteBuffer byteBuffer, boolean blocking) throws IOException { |
| 407 | 1414 | if (!isConnected){ |
| 408 | 0 | throw new NotYetConnectedException(); |
| 409 | |
} |
| 410 | |
|
| 411 | 1414 | if (blocking){ |
| 412 | 313 | return OutputWriter.flushChannel(socketChannel,byteBuffer); |
| 413 | |
} else { |
| 414 | |
|
| 415 | 1101 | if (callbackHandler == null){ |
| 416 | 0 | throw new IllegalStateException |
| 417 | |
("Non blocking write needs a CallbackHandler"); |
| 418 | |
} |
| 419 | |
|
| 420 | 1101 | SelectionKey key = socketChannel.keyFor(selectorHandler.getSelector()); |
| 421 | 1101 | int nWrite = 1; |
| 422 | 1101 | int totalWriteBytes = 0; |
| 423 | 2202 | while (nWrite > 0 && byteBuffer.hasRemaining()){ |
| 424 | 1101 | nWrite = socketChannel.write(byteBuffer); |
| 425 | 1101 | totalWriteBytes += nWrite; |
| 426 | |
} |
| 427 | |
|
| 428 | 1101 | if (totalWriteBytes == 0 && byteBuffer.hasRemaining()){ |
| 429 | 0 | selectorHandler.register(key,SelectionKey.OP_WRITE); |
| 430 | |
} |
| 431 | 1101 | return totalWriteBytes; |
| 432 | |
} |
| 433 | |
} |
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
public void readFromAsyncQueue(ByteBuffer buffer, |
| 440 | |
AsyncReadCallbackHandler callbackHandler) throws IOException { |
| 441 | 100 | readFromAsyncQueue(buffer, callbackHandler, null); |
| 442 | 100 | } |
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
public void readFromAsyncQueue(ByteBuffer buffer, |
| 448 | |
AsyncReadCallbackHandler callbackHandler, |
| 449 | |
AsyncReadCondition condition) throws IOException { |
| 450 | 100 | readFromAsyncQueue(buffer, callbackHandler, condition, null); |
| 451 | 100 | } |
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
public void readFromAsyncQueue(ByteBuffer buffer, |
| 457 | |
AsyncReadCallbackHandler callbackHandler, |
| 458 | |
AsyncReadCondition condition, |
| 459 | |
AsyncQueueDataProcessor readPostProcessor) throws IOException { |
| 460 | 100 | selectorHandler.getAsyncQueueReader().read( |
| 461 | |
socketChannel.keyFor(selectorHandler.getSelector()), buffer, |
| 462 | |
callbackHandler, condition, readPostProcessor); |
| 463 | 100 | } |
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
public void writeToAsyncQueue(ByteBuffer buffer) throws IOException { |
| 470 | 200000 | writeToAsyncQueue(buffer, null); |
| 471 | 200000 | } |
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
public void writeToAsyncQueue(ByteBuffer buffer, |
| 478 | |
AsyncWriteCallbackHandler callbackHandler) throws IOException { |
| 479 | 200000 | writeToAsyncQueue(buffer, callbackHandler, null); |
| 480 | 200000 | } |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
public void writeToAsyncQueue(ByteBuffer buffer, |
| 487 | |
AsyncWriteCallbackHandler callbackHandler, |
| 488 | |
AsyncQueueDataProcessor writePreProcessor) throws IOException { |
| 489 | 200000 | writeToAsyncQueue(buffer, callbackHandler, writePreProcessor, false); |
| 490 | 200000 | } |
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
public void writeToAsyncQueue(ByteBuffer buffer, |
| 497 | |
AsyncWriteCallbackHandler callbackHandler, |
| 498 | |
AsyncQueueDataProcessor writePreProcessor, |
| 499 | |
boolean isCloneByteBuffer) throws IOException { |
| 500 | 200000 | selectorHandler.getAsyncQueueWriter().write( |
| 501 | |
socketChannel.keyFor(selectorHandler.getSelector()), buffer, |
| 502 | |
callbackHandler, writePreProcessor, isCloneByteBuffer); |
| 503 | 200000 | } |
| 504 | |
|
| 505 | |
|
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer) |
| 510 | |
throws IOException { |
| 511 | 0 | writeToAsyncQueue(dstAddress, buffer, null); |
| 512 | 0 | } |
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, |
| 519 | |
AsyncWriteCallbackHandler callbackHandler) throws IOException { |
| 520 | 0 | writeToAsyncQueue(dstAddress, buffer, callbackHandler, null); |
| 521 | 0 | } |
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, |
| 528 | |
AsyncWriteCallbackHandler callbackHandler, |
| 529 | |
AsyncQueueDataProcessor writePreProcessor) throws IOException { |
| 530 | 0 | writeToAsyncQueue(dstAddress, buffer, callbackHandler, writePreProcessor, |
| 531 | |
false); |
| 532 | 0 | } |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, |
| 539 | |
AsyncWriteCallbackHandler callbackHandler, |
| 540 | |
AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer) |
| 541 | |
throws IOException { |
| 542 | 0 | selectorHandler.getAsyncQueueWriter().write( |
| 543 | |
socketChannel.keyFor(selectorHandler.getSelector()), dstAddress, |
| 544 | |
buffer, callbackHandler, writePreProcessor, isCloneByteBuffer); |
| 545 | 0 | } |
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
public void close() throws IOException{ |
| 552 | 51 | if (socketChannel != null){ |
| 553 | 51 | if (selectorHandler != null){ |
| 554 | 51 | SelectionKey key = |
| 555 | |
socketChannel.keyFor(selectorHandler.getSelector()); |
| 556 | |
|
| 557 | 51 | if (key == null) return; |
| 558 | |
|
| 559 | 51 | selectorHandler.getSelectionKeyHandler().cancel(key); |
| 560 | 51 | } else { |
| 561 | 0 | socketChannel.close(); |
| 562 | |
} |
| 563 | |
} |
| 564 | |
|
| 565 | 51 | if (controller != null && isStandalone){ |
| 566 | 20 | controller.stop(); |
| 567 | 20 | controller = null; |
| 568 | |
} |
| 569 | |
|
| 570 | 51 | isStandalone = false; |
| 571 | 51 | isConnected = false; |
| 572 | 51 | connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; |
| 573 | 51 | } |
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
public void finishConnect(SelectionKey key) throws IOException{ |
| 581 | |
try{ |
| 582 | 52 | if (Controller.logger().isLoggable(Level.FINE)) { |
| 583 | 0 | Controller.logger().log(Level.FINE, "Finish connect"); |
| 584 | |
} |
| 585 | |
|
| 586 | 52 | socketChannel = (SocketChannel)key.channel(); |
| 587 | 52 | socketChannel.finishConnect(); |
| 588 | 52 | isConnected = socketChannel.isConnected(); |
| 589 | 52 | configureChannel(socketChannel); |
| 590 | |
|
| 591 | 52 | if (Controller.logger().isLoggable(Level.FINE)) { |
| 592 | 0 | Controller.logger().log(Level.FINE, "isConnected: " + isConnected); |
| 593 | |
} |
| 594 | 0 | } catch (IOException ex){ |
| 595 | 0 | throw ex; |
| 596 | |
} finally { |
| 597 | 52 | isConnectedLatch.countDown(); |
| 598 | 52 | } |
| 599 | 52 | } |
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
public void configureChannel(SelectableChannel channel) throws IOException{ |
| 606 | 52 | Socket socket = ((SocketChannel) channel).socket(); |
| 607 | |
|
| 608 | |
try{ |
| 609 | 52 | if(linger >= 0 ) { |
| 610 | 0 | socket.setSoLinger( true, linger); |
| 611 | |
} |
| 612 | 0 | } catch (SocketException ex){ |
| 613 | 0 | Controller.logger().log(Level.WARNING, |
| 614 | |
"setSoLinger exception ",ex); |
| 615 | 52 | } |
| 616 | |
|
| 617 | |
try{ |
| 618 | 52 | socket.setTcpNoDelay(tcpNoDelay); |
| 619 | 0 | } catch (SocketException ex){ |
| 620 | 0 | Controller.logger().log(Level.WARNING, |
| 621 | |
"setTcpNoDelay exception ",ex); |
| 622 | 52 | } |
| 623 | |
|
| 624 | |
try{ |
| 625 | 52 | socket.setReuseAddress(reuseAddress); |
| 626 | 0 | } catch (SocketException ex){ |
| 627 | 0 | Controller.logger().log(Level.WARNING, |
| 628 | |
"setReuseAddress exception ",ex); |
| 629 | 52 | } |
| 630 | 52 | } |
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
public Controller.Protocol protocol(){ |
| 639 | 83 | return Controller.Protocol.TCP; |
| 640 | |
} |
| 641 | |
|
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
public boolean isConnected(){ |
| 648 | 10 | return isConnected && socketChannel.isOpen(); |
| 649 | |
} |
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
public Controller getController() { |
| 657 | 0 | return controller; |
| 658 | |
} |
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
public void setController(Controller controller) { |
| 666 | 64 | this.controller = controller; |
| 667 | 64 | } |
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
public SelectableChannel getUnderlyingChannel() { |
| 675 | 9 | return socketChannel; |
| 676 | |
} |
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
|
| 683 | |
protected void setUnderlyingChannel(SocketChannel socketChannel){ |
| 684 | 20 | this.socketChannel = socketChannel; |
| 685 | 20 | } |
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
public CallbackHandler getCallbackHandler() { |
| 693 | 0 | return callbackHandler; |
| 694 | |
} |
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
public void setCallbackHandler(CallbackHandler callbackHandler) { |
| 702 | 9 | this.callbackHandler = callbackHandler; |
| 703 | 9 | } |
| 704 | |
|
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
public TCPSelectorHandler getSelectorHandler() { |
| 711 | 9 | return selectorHandler; |
| 712 | |
} |
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
public boolean isTcpNoDelay() { |
| 721 | 0 | return tcpNoDelay; |
| 722 | |
} |
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
public void setTcpNoDelay(boolean tcpNoDelay) { |
| 745 | 0 | this.tcpNoDelay = tcpNoDelay; |
| 746 | 0 | } |
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
public int getLinger() { |
| 754 | 0 | return linger; |
| 755 | |
} |
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
public void setLinger(int linger) { |
| 762 | 0 | this.linger = linger; |
| 763 | 0 | } |
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
public int getConnectionTimeout() { |
| 771 | 0 | return connectionTimeout; |
| 772 | |
} |
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
public void setConnectionTimeout(int connectionTimeout) { |
| 780 | 0 | this.connectionTimeout = connectionTimeout; |
| 781 | 0 | } |
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
|
| 786 | |
|
| 787 | |
public boolean isReuseAddress() { |
| 788 | 0 | return reuseAddress; |
| 789 | |
} |
| 790 | |
|
| 791 | |
|
| 792 | |
|
| 793 | |
|
| 794 | |
|
| 795 | |
public void setReuseAddress(boolean reuseAddress) { |
| 796 | 0 | this.reuseAddress = reuseAddress; |
| 797 | 0 | } |
| 798 | |
} |