| 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 org.ietf.ldap; |
| 39 |
|
| 40 |
import java.io.BufferedInputStream; |
| 41 |
import java.io.BufferedOutputStream; |
| 42 |
import java.io.IOException; |
| 43 |
import java.io.InputStream; |
| 44 |
import java.io.OutputStream; |
| 45 |
import java.io.PrintWriter; |
| 46 |
import java.net.Socket; |
| 47 |
import java.text.SimpleDateFormat; |
| 48 |
import java.util.Date; |
| 49 |
import java.util.Enumeration; |
| 50 |
import java.util.Hashtable; |
| 51 |
import java.util.Vector; |
| 52 |
|
| 53 |
import org.ietf.ldap.ber.stream.BERElement; |
| 54 |
import org.ietf.ldap.client.JDAPBERTagDecoder; |
| 55 |
import org.ietf.ldap.client.opers.JDAPAbandonRequest; |
| 56 |
import org.ietf.ldap.client.opers.JDAPProtocolOp; |
| 57 |
import org.ietf.ldap.client.opers.JDAPUnbindRequest; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
class LDAPConnThread extends Thread { |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
private final static int MAXMSGID = Integer.MAX_VALUE; |
| 84 |
private final static int BACKLOG_CHKCNT = 50; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
transient private static int _highMsgId; |
| 90 |
transient private InputStream _serverInput; |
| 91 |
transient private OutputStream _serverOutput; |
| 92 |
transient private Hashtable<Integer, LDAPMessageQueue> _requests; |
| 93 |
transient private Hashtable<Integer, Vector<Object>> _messages = null; |
| 94 |
transient private Vector<LDAPConnection> _registered; |
| 95 |
transient private boolean _disconnected = false; |
| 96 |
transient private LDAPCache _cache = null; |
| 97 |
transient private boolean _doRun = true; |
| 98 |
private Socket _socket = null; |
| 99 |
transient private Thread _thread = null; |
| 100 |
transient Object _sendRequestLock = new Object(); |
| 101 |
transient LDAPConnSetupMgr _connMgr = null; |
| 102 |
transient Object _traceOutput = null; |
| 103 |
transient private int _backlogCheckCounter = BACKLOG_CHKCNT; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static SimpleDateFormat _timeFormat = |
| 109 |
new SimpleDateFormat( "HH:mm:ss.SSS" ); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public LDAPConnThread( LDAPConnSetupMgr connMgr, |
| 120 |
LDAPCache cache, |
| 121 |
Object traceOutput ) |
| 122 |
throws LDAPException { |
| 123 |
super( "LDAPConnThread " + connMgr.getHost() + |
| 124 |
":" + connMgr.getPort() ); |
| 125 |
_requests = new Hashtable<>(); |
| 126 |
_registered = new Vector<>(); |
| 127 |
_connMgr = connMgr; |
| 128 |
_socket = connMgr.getSocket(); |
| 129 |
setCache( cache ); |
| 130 |
setTraceOutput( traceOutput ); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
setDaemon( true ); |
| 135 |
|
| 136 |
try { |
| 137 |
_serverInput = |
| 138 |
new BufferedInputStream( _socket.getInputStream() ); |
| 139 |
_serverOutput = |
| 140 |
new BufferedOutputStream( _socket.getOutputStream() ); |
| 141 |
} catch ( IOException e ) { |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
_doRun = false; |
| 148 |
start(); |
| 149 |
throw new LDAPException ( "failed to connect to server " + |
| 150 |
_connMgr.getHost(), |
| 151 |
LDAPException.CONNECT_ERROR ); |
| 152 |
} |
| 153 |
|
| 154 |
if ( traceOutput != null ) { |
| 155 |
StringBuffer sb = new StringBuffer( " connected to " ); |
| 156 |
sb.append( _connMgr.getLDAPUrl() ); |
| 157 |
logTraceMessage( sb ); |
| 158 |
} |
| 159 |
|
| 160 |
start(); |
| 161 |
} |
| 162 |
|
| 163 |
InputStream getInputStream() { |
| 164 |
return _serverInput; |
| 165 |
} |
| 166 |
|
| 167 |
void setInputStream( InputStream is ) { |
| 168 |
_serverInput = is; |
| 169 |
} |
| 170 |
|
| 171 |
OutputStream getOutputStream() { |
| 172 |
return _serverOutput; |
| 173 |
} |
| 174 |
|
| 175 |
void setOutputStream( OutputStream os ) { |
| 176 |
_serverOutput = os; |
| 177 |
} |
| 178 |
|
| 179 |
void setTraceOutput( Object traceOutput ) { |
| 180 |
synchronized ( _sendRequestLock ) { |
| 181 |
if ( traceOutput == null ) { |
| 182 |
_traceOutput = null; |
| 183 |
} else if ( traceOutput instanceof OutputStream ) { |
| 184 |
_traceOutput = new PrintWriter( (OutputStream)traceOutput ); |
| 185 |
} else if ( traceOutput instanceof LDAPTraceWriter ) { |
| 186 |
_traceOutput = traceOutput; |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
void logTraceMessage( StringBuffer msg ) { |
| 192 |
if ( _traceOutput == null ) { |
| 193 |
return; |
| 194 |
} |
| 195 |
String timeStamp = _timeFormat.format( new Date() ); |
| 196 |
StringBuffer sb = new StringBuffer( timeStamp ); |
| 197 |
sb.append( " ldc=" ); |
| 198 |
sb.append( _connMgr.getID() ); |
| 199 |
|
| 200 |
synchronized( _sendRequestLock ) { |
| 201 |
if ( _traceOutput instanceof PrintWriter ) { |
| 202 |
PrintWriter traceOutput = (PrintWriter)_traceOutput; |
| 203 |
traceOutput.print( sb ); |
| 204 |
traceOutput.println( msg ); |
| 205 |
traceOutput.flush(); |
| 206 |
} else if ( _traceOutput instanceof LDAPTraceWriter ) { |
| 207 |
sb.append( msg ); |
| 208 |
((LDAPTraceWriter)_traceOutput).write( sb.toString() ); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
synchronized void setCache( LDAPCache cache ) { |
| 219 |
_cache = cache; |
| 220 |
_messages = (_cache != null) ? new Hashtable<>() : null; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
private int allocateId() { |
| 230 |
synchronized( _sendRequestLock ) { |
| 231 |
_highMsgId = (_highMsgId + 1) % MAXMSGID; |
| 232 |
return _highMsgId; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
void sendRequest( LDAPConnection conn, JDAPProtocolOp request, |
| 244 |
LDAPMessageQueue toNotify, LDAPConstraints cons ) |
| 245 |
throws LDAPException { |
| 246 |
if ( !_doRun ) { |
| 247 |
throw new LDAPException ( "not connected to a server", |
| 248 |
LDAPException.SERVER_DOWN ); |
| 249 |
} |
| 250 |
LDAPMessage msg = |
| 251 |
new LDAPMessage( allocateId(), request, cons.getControls() ); |
| 252 |
|
| 253 |
LDAPMessageQueueImpl queue = (LDAPMessageQueueImpl)toNotify; |
| 254 |
if ( queue != null ) { |
| 255 |
if ( !(request instanceof JDAPAbandonRequest || |
| 256 |
request instanceof JDAPUnbindRequest) ) { |
| 257 |
|
| 258 |
this._requests.put( msg.getMessageID(), queue ); |
| 259 |
|
| 260 |
|
| 261 |
resultRetrieved(); |
| 262 |
} |
| 263 |
queue.addRequest( msg.getMessageID(), conn, this, |
| 264 |
cons.getTimeLimit() ); |
| 265 |
} |
| 266 |
|
| 267 |
synchronized( _sendRequestLock ) { |
| 268 |
try { |
| 269 |
if ( _traceOutput != null ) { |
| 270 |
logTraceMessage( msg.toTraceString() ); |
| 271 |
} |
| 272 |
msg.write( _serverOutput ); |
| 273 |
_serverOutput.flush(); |
| 274 |
} catch ( IOException e ) { |
| 275 |
networkError( e ); |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public synchronized void register( LDAPConnection conn ) { |
| 286 |
if ( !_registered.contains( conn ) ) |
| 287 |
_registered.addElement( conn ); |
| 288 |
} |
| 289 |
|
| 290 |
int getClientCount() { |
| 291 |
return _registered.size(); |
| 292 |
} |
| 293 |
|
| 294 |
boolean isRunning() { |
| 295 |
return _doRun; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public synchronized void deregister(LDAPConnection conn) { |
| 305 |
_registered.removeElement( conn ); |
| 306 |
if ( _registered.size() == 0 ) { |
| 307 |
try { |
| 308 |
if ( !_disconnected ) { |
| 309 |
LDAPSearchConstraints cons = conn.getSearchConstraints(); |
| 310 |
sendRequest( null, new JDAPUnbindRequest(), null, cons ); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
_doRun =false; |
| 315 |
|
| 316 |
if ( (_thread != null) && |
| 317 |
(_thread != Thread.currentThread()) ) { |
| 318 |
|
| 319 |
_thread.interrupt(); |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
try { |
| 325 |
wait( 1000 ); |
| 326 |
} |
| 327 |
catch ( InterruptedException e ) { |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
} catch( Exception e ) { |
| 332 |
LDAPConnection.printDebug( e.toString() ); |
| 333 |
} |
| 334 |
finally { |
| 335 |
cleanUp(); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
private void cleanUp() { |
| 344 |
if ( !_disconnected ) { |
| 345 |
try { |
| 346 |
_serverOutput.close(); |
| 347 |
} catch ( Exception e ) { |
| 348 |
} finally { |
| 349 |
_serverOutput = null; |
| 350 |
} |
| 351 |
|
| 352 |
try { |
| 353 |
_serverInput.close (); |
| 354 |
} catch ( Exception e ) { |
| 355 |
} finally { |
| 356 |
_serverInput = null; |
| 357 |
} |
| 358 |
|
| 359 |
try { |
| 360 |
_socket.close (); |
| 361 |
} catch ( Exception e ) { |
| 362 |
} finally { |
| 363 |
_socket = null; |
| 364 |
} |
| 365 |
|
| 366 |
_disconnected = true; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
_connMgr.disconnect(); |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
if ( _requests != null ) { |
| 378 |
Enumeration<LDAPMessageQueue> requests = _requests.elements(); |
| 379 |
while ( requests.hasMoreElements() ) { |
| 380 |
LDAPMessageQueueImpl queue = |
| 381 |
(LDAPMessageQueueImpl)requests.nextElement(); |
| 382 |
queue.removeAllRequests( this ); |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
if ( _registered != null ) { |
| 395 |
Vector<LDAPConnection> registerCopy = (Vector<LDAPConnection>)_registered.clone(); |
| 396 |
|
| 397 |
Enumeration<LDAPConnection> cancelled = registerCopy.elements(); |
| 398 |
|
| 399 |
while ( cancelled.hasMoreElements() ) { |
| 400 |
LDAPConnection c = cancelled.nextElement(); |
| 401 |
c.deregisterConnection(); |
| 402 |
} |
| 403 |
} |
| 404 |
_registered.clear(); |
| 405 |
_registered = null; |
| 406 |
_messages = null; |
| 407 |
_requests.clear(); |
| 408 |
_cache = null; |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
private void checkBacklog() throws InterruptedException{ |
| 416 |
|
| 417 |
while ( true ) { |
| 418 |
|
| 419 |
if ( _requests.size() == 0 ) { |
| 420 |
return; |
| 421 |
} |
| 422 |
|
| 423 |
Enumeration<LDAPMessageQueue> queues = _requests.elements(); |
| 424 |
while( queues.hasMoreElements() ) { |
| 425 |
LDAPMessageQueue l = queues.nextElement(); |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
if ( !(l instanceof LDAPSearchQueue ) ) { |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
LDAPSearchQueue sl = (LDAPSearchQueue)l; |
| 434 |
|
| 435 |
|
| 436 |
if ( sl.getSearchConstraints() == null ) { |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
int slMaxBacklog = sl.getSearchConstraints().getMaxBacklog(); |
| 441 |
int slBatchSize = sl.getSearchConstraints().getBatchSize(); |
| 442 |
|
| 443 |
|
| 444 |
if ( slMaxBacklog == 0 ) { |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
if ( !sl.isAsynchOp() && slBatchSize == 0 ) { |
| 450 |
return; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
if ( sl.getMessageCount() < slMaxBacklog ) { |
| 456 |
return; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
synchronized( this ) { |
| 461 |
wait( 3000 ); |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
synchronized void resultRetrieved() { |
| 474 |
notifyAll(); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
public void run() { |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
if ( !_doRun ) { |
| 485 |
return; |
| 486 |
} |
| 487 |
|
| 488 |
_thread = Thread.currentThread(); |
| 489 |
LDAPMessage msg = null; |
| 490 |
JDAPBERTagDecoder decoder = new JDAPBERTagDecoder(); |
| 491 |
|
| 492 |
while ( _doRun ) { |
| 493 |
Thread.yield(); |
| 494 |
int[] nread = new int[1]; |
| 495 |
nread[0] = 0; |
| 496 |
try { |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
if ( --_backlogCheckCounter <= 0 ) { |
| 501 |
_backlogCheckCounter = BACKLOG_CHKCNT; |
| 502 |
checkBacklog(); |
| 503 |
} |
| 504 |
|
| 505 |
BERElement element = BERElement.getElement( decoder, |
| 506 |
_serverInput, |
| 507 |
nread ); |
| 508 |
msg = LDAPMessage.parseMessage( element ); |
| 509 |
|
| 510 |
if ( _traceOutput != null ) { |
| 511 |
logTraceMessage( msg.toTraceString() ); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
processResponse( msg, nread[0] ); |
| 518 |
|
| 519 |
} catch ( Exception e ) { |
| 520 |
if (_doRun) { |
| 521 |
networkError( e ); |
| 522 |
} else { |
| 523 |
|
| 524 |
synchronized( this ) { |
| 525 |
_thread = null; |
| 526 |
notifyAll(); |
| 527 |
} |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
private void processResponse( LDAPMessage msg, int size ) { |
| 540 |
Integer messageID = msg.getMessageID(); |
| 541 |
LDAPMessageQueueImpl l = |
| 542 |
(LDAPMessageQueueImpl)_requests.get( messageID ); |
| 543 |
if ( l == null ) { |
| 544 |
return; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
if ( ! l.isAsynchOp() ) { |
| 552 |
|
| 553 |
|
| 554 |
LDAPControl[] con = msg.getControls(); |
| 555 |
if ( con != null ) { |
| 556 |
int msgid = msg.getMessageID(); |
| 557 |
LDAPConnection ldc = l.getConnection( msgid ); |
| 558 |
if ( ldc != null ) { |
| 559 |
ldc.setResponseControls( |
| 560 |
this, new LDAPResponseControl(ldc, msgid, con) ); |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
if ( (_cache != null) && (l instanceof LDAPSearchQueue) ) { |
| 566 |
cacheSearchResult( (LDAPSearchQueue)l, msg, size ); |
| 567 |
} |
| 568 |
|
| 569 |
l.addMessage( msg ); |
| 570 |
|
| 571 |
if ( msg instanceof LDAPResponse ) { |
| 572 |
_requests.remove( messageID ); |
| 573 |
if ( _requests.size() == 0 ) { |
| 574 |
_backlogCheckCounter = BACKLOG_CHKCNT; |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
private synchronized void cacheSearchResult( LDAPSearchQueue l, |
| 591 |
LDAPMessage msg, int size ) { |
| 592 |
Integer messageID = msg.getMessageID(); |
| 593 |
Long key = l.getKey(); |
| 594 |
Vector<Object> v = null; |
| 595 |
|
| 596 |
if ( (_cache == null) || (key == null) ) { |
| 597 |
return; |
| 598 |
} |
| 599 |
|
| 600 |
if ( msg instanceof LDAPSearchResult ) { |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
v = _messages.get( messageID ); |
| 605 |
if ( v == null ) { |
| 606 |
_messages.put( messageID, v = new Vector<>() ); |
| 607 |
v.addElement( 0L ); |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
if ( ((Long)v.firstElement()).longValue() == -1L ) { |
| 612 |
return; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
long entrySize = ((Long)v.firstElement()).longValue() + size; |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
if ( entrySize > _cache.getSize() ) { |
| 625 |
v.removeAllElements(); |
| 626 |
v.addElement( -1L ); |
| 627 |
return; |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
v.setElementAt( entrySize, 0 ); |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
v.addElement( ((LDAPSearchResult)msg).getEntry() ); |
| 636 |
|
| 637 |
} else if ( msg instanceof LDAPSearchResultReference ) { |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
v = _messages.get(messageID); |
| 642 |
if ( v == null ) { |
| 643 |
_messages.put( messageID, v = new Vector<>() ); |
| 644 |
} |
| 645 |
else { |
| 646 |
v.removeAllElements(); |
| 647 |
} |
| 648 |
v.addElement( -1L ); |
| 649 |
|
| 650 |
} else if ( msg instanceof LDAPResponse ) { |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
boolean fail = ((LDAPResponse)msg).getResultCode() > 0; |
| 657 |
v = _messages.remove( messageID ); |
| 658 |
|
| 659 |
if ( !fail ) { |
| 660 |
|
| 661 |
|
| 662 |
if ( v == null ) { |
| 663 |
v = new Vector<>(); |
| 664 |
v.addElement( 0L ); |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
if ( ((Long)v.firstElement()).longValue() != -1L ) { |
| 670 |
_cache.addEntry( key, v ); |
| 671 |
} |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
void abandon( int id ) { |
| 682 |
if ( !_doRun ) { |
| 683 |
return; |
| 684 |
} |
| 685 |
|
| 686 |
LDAPMessageQueueImpl l = |
| 687 |
(LDAPMessageQueueImpl)_requests.remove( id ); |
| 688 |
|
| 689 |
if ( _messages != null ) { |
| 690 |
_messages.remove( id ); |
| 691 |
} |
| 692 |
if ( l != null ) { |
| 693 |
l.removeRequest( id ); |
| 694 |
} |
| 695 |
resultRetrieved(); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
LDAPMessageQueue changeQueue( int id, LDAPMessageQueue toNotify ) { |
| 706 |
if ( !_doRun ) { |
| 707 |
LDAPMessageQueueImpl queue = (LDAPMessageQueueImpl)toNotify; |
| 708 |
queue.setException( this, |
| 709 |
new LDAPException( "Server down", |
| 710 |
LDAPException.OTHER ) ); |
| 711 |
return null; |
| 712 |
} |
| 713 |
return _requests.put( id, toNotify ); |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
private synchronized void networkError( Exception e ) { |
| 723 |
_doRun = false; |
| 724 |
|
| 725 |
|
| 726 |
_connMgr.invalidateConnection(); |
| 727 |
|
| 728 |
try { |
| 729 |
|
| 730 |
|
| 731 |
Enumeration<LDAPMessageQueue> requests = _requests.elements(); |
| 732 |
while ( requests.hasMoreElements() ) { |
| 733 |
LDAPMessageQueueImpl queue = |
| 734 |
(LDAPMessageQueueImpl)requests.nextElement(); |
| 735 |
queue.setException( this, |
| 736 |
new LDAPException( "Server down", |
| 737 |
LDAPException.OTHER) ); |
| 738 |
} |
| 739 |
|
| 740 |
} catch( NullPointerException ee ) { |
| 741 |
System.err.println( "Exception: " + ee.toString() ); |
| 742 |
} |
| 743 |
|
| 744 |
cleanUp(); |
| 745 |
} |
| 746 |
} |