1 16 package com.sun.slamd.example; 17 18 19 20 import netscape.ldap.*; 21 import netscape.ldap.controls.*; 22 23 24 25 32 public class LatencyCheckReplicaThread 33 extends Thread 34 { 35 boolean active; 37 38 boolean started; 41 42 boolean stopRequested; 44 45 boolean stopCompleted; 47 48 LatencyCheckReplicaThread replicaThread; 50 51 LDAPConnection connection; 53 54 ReplicaLatencyCheckJobClass jobThread; 56 57 String entryDN; 59 60 61 62 78 public LatencyCheckReplicaThread(ReplicaLatencyCheckJobClass jobThread, 79 String replicaHost, int replicaPort, 80 String bindDN, String bindPW, String entryDN) 81 throws LDAPException 82 { 83 setName("Latency Check Replica Thread"); 84 85 this.jobThread = jobThread; 86 this.entryDN = entryDN; 87 88 replicaThread = null; 89 active = false; 90 started = false; 91 stopRequested = false; 92 stopCompleted = false; 93 94 connection = new LDAPConnection(); 95 connection.connect(3, replicaHost, replicaPort, bindDN, bindPW); 96 } 97 98 99 100 105 public void startChecking() 106 { 107 active = true; 108 109 while ((! started) && (! stopRequested)) 110 { 111 try 112 { 113 Thread.sleep(10); 114 } catch (InterruptedException ie) {} 115 } 116 } 117 118 119 120 123 public void run() 124 { 125 replicaThread = this; 126 127 while ((! active) && (! stopRequested)) 129 { 130 try 131 { 132 Thread.sleep(10); 133 } catch (InterruptedException ie) {} 134 } 135 136 LDAPPersistSearchControl psearchControl = 138 new LDAPPersistSearchControl(LDAPPersistSearchControl.MODIFY, true, 139 false, true); 140 LDAPSearchConstraints searchConstraints = connection.getSearchConstraints(); 141 searchConstraints.setServerControls(psearchControl); 142 143 LDAPSearchResults results = null; 144 try 145 { 146 results = 147 connection.search(entryDN, LDAPConnection.SCOPE_BASE, 148 "(|(objectClass=*)(objectClass=ldapSubEntry))", 149 null, false, searchConstraints); 150 } 151 catch (LDAPException le) 152 { 153 jobThread.writeVerbose("Unable to register a persistent search against " + 154 "the replica directory: " + le); 155 } 156 157 158 started = true; 160 while ((! stopRequested) && (results != null) && 161 (results.hasMoreElements())) 162 { 163 try 164 { 165 Object result = results.next(); 166 if (result instanceof LDAPEntry) 167 { 168 jobThread.latencyTime.stopTimer(); 169 synchronized (jobThread.latencyCheckMutex) 170 { 171 jobThread.latencyCheckMutex.notifyAll(); 172 } 173 } 174 } 175 catch (LDAPInterruptedException lie) 176 { 177 } 179 catch (LDAPException le) 180 { 181 jobThread.writeVerbose("Error reading response from replica: " + le); 182 break; 183 } 184 } 185 186 stopCompleted = true; 188 replicaThread = null; 189 } 190 191 192 193 197 public void stopAndWait() 198 { 199 if (stopCompleted) 200 { 201 return; 202 } 203 204 stopRequested = true; 205 206 try 207 { 208 if (replicaThread != null) 209 { 210 replicaThread.interrupt(); 211 } 212 } catch (Exception e) {} 213 214 while (! stopCompleted) 215 { 216 try 217 { 218 Thread.sleep(10); 219 } catch (InterruptedException ie) {} 220 } 221 222 try 223 { 224 connection.disconnect(); 225 } catch (LDAPException le) {} 226 } 227 } 228 229 | Popular Tags |