예제 #1
0
 /* package */
 Object getReply() {
   Object msg;
   if (replies == null) {
     return null;
   }
   synchronized (replies) {
     // Test and remove must be atomic
     if (replies.isEmpty()) {
       if (Debug.LDAP_DEBUG) {
         Debug.trace(Debug.messages, name + "No replies queued for message");
       }
       return null; // No data
     }
     msg = replies.remove(0); // Atomic get and remove
   }
   if (Debug.LDAP_DEBUG) {
     Debug.trace(
         Debug.messages, name + "Got reply from queue(" + replies.size() + " remaining in queue)");
   }
   if ((conn != null) && (complete || !acceptReplies) && replies.isEmpty()) {
     // Remove msg from connection queue when last reply read
     conn.removeMessage(this);
   }
   return msg;
 }
예제 #2
0
 /* package */
 Object waitForReply() {
   if (Debug.LDAP_DEBUG) {
     Debug.trace(Debug.messages, name + "waitForReply()");
   }
   if (replies == null) {
     return null;
   }
   // sync on message so don't confuse with timer thread
   synchronized (replies) {
     Object msg = null;
     while (waitForReply) {
       if (replies.isEmpty()) {
         if (Debug.LDAP_DEBUG) {
           Debug.trace(Debug.messages, name + "No replies queued, waitForReply=" + waitForReply);
         }
         try {
           if (Debug.LDAP_DEBUG) {
             Debug.trace(Debug.messages, name + "Wait for a reply");
           }
           replies.wait();
         } catch (InterruptedException ir) {; // do nothing
         }
         if (waitForReply) {
           continue;
         } else {
           break;
         }
       } else {
         msg = replies.remove(0); // Atomic get and remove
       }
       if ((complete || !acceptReplies) && replies.isEmpty()) {
         // Remove msg from connection queue when last reply read
         conn.removeMessage(this);
         if (Debug.LDAP_DEBUG) {
           Debug.trace(Debug.messages, name + "Last message removed, remove msg from Connection");
         }
       } else {
         if (Debug.LDAP_DEBUG) {
           Debug.trace(
               Debug.messages,
               name + "Got reply from queue(" + replies.size() + " remaining in queue)");
         }
       }
       return msg;
     }
     return null;
   }
 }
예제 #3
0
 /** Release reply messages */
 private void cleanup() {
   if (Debug.LDAP_DEBUG) {
     Debug.trace(Debug.messages, name + "cleanup");
   }
   stopTimer(); // Make sure timer stopped
   try {
     acceptReplies = false;
     if (conn != null) {
       conn.removeMessage(this);
     }
     // Empty out any accumuluated replies
     if (replies != null) {
       if (Debug.LDAP_DEBUG) {
         if (!replies.isEmpty()) {
           Debug.trace(Debug.messages, name + "cleanup: remove " + replies.size() + " replies");
         }
       }
       while (!replies.isEmpty()) {
         replies.remove(0);
       }
     }
   } catch (Throwable ex) {
     if (Debug.LDAP_DEBUG) {
       Debug.trace(Debug.messages, name + "cleanup exception:" + ex.toString());
     }
     ; // nothing
   }
   // Let GC clean up this stuff, leave name in case finalized is called
   conn = null;
   msg = null;
   // agent = null;  // leave this reference
   queue = null;
   // replies = null; //leave this since we use it as a semaphore
   bindprops = null;
   return;
 }