/** Notifies all waiting threads */ private void sleepersAwake() { if (Debug.LDAP_DEBUG) { Debug.trace(Debug.messages, name + "Sleepers Awake, " + agent.getAgentName()); } // Notify any thread waiting for this message id synchronized (replies) { replies.notify(); } // Notify a thread waiting for any message id agent.sleepersAwake(false); return; }
public static void main(final String[] argv) { final Getopt g = new Getopt("DomainCommand", argv, "n:m:t:P:"); String[] allocName = null; int c; while ((c = g.getopt()) != -1) { switch (c) { case 110: { allocName = g.getOptarg().split(",", 2); } case 109: case 116: { continue; } } } final String worldName = System.getProperty("atavism.worldname"); final String hostName = determineHostName(); final Properties properties = InitLogAndPid.initLogAndPid(argv, worldName, hostName); final MessageAgent agent = new MessageAgent(); final String domainHost = properties.getProperty( "atavism.msgsvr_hostname", System.getProperty("atavism.msgsvr_hostname")); final String portString = properties.getProperty("atavism.msgsvr_port", System.getProperty("atavism.msgsvr_port")); int domainPort = 20374; if (portString != null) { domainPort = Integer.parseInt(portString); } try { agent.connectToDomain(domainHost, domainPort); if (allocName != null) { final String agentName = agent.getDomainClient().allocName(allocName[0], allocName[1]); System.out.println(agentName); } } catch (Exception ex) { System.err.println("DomainCommand: " + ex); throw new RuntimeException("failed", ex); } }
/* package */ void abandon(LDAPConstraints cons, InterThreadException informUserEx) { if (!waitForReply) { Debug.trace(Debug.messages, name + "Abandon request ignored"); return; } if (Debug.LDAP_DEBUG) { Debug.trace( Debug.messages, name + "Abandon request, complete=" + complete + ", bind=" + (bindprops != null) + ", informUser="******", waitForReply=" + waitForReply); } acceptReplies = false; // don't listen to anyone waitForReply = false; // don't let sleeping threads lie if (!complete) { try { // If a bind, release bind semaphore & wake up waiting threads // Must do before writing abandon message, otherwise deadlock if (bindprops != null) { int id; if (conn.isBindSemIdClear()) { // Semaphore id for normal operations id = msgId; } else { // Semaphore id for sasl bind id = conn.getBindSemId(); conn.clearBindSemId(); } conn.freeWriteSemaphore(id); } if (Debug.LDAP_DEBUG) { Debug.trace(Debug.messages, name + "Sending abandon request"); } // Create the abandon message, but don't track it. LDAPControl[] cont = null; if (cons != null) { cont = cons.getControls(); } LDAPMessage msg = new LDAPAbandonRequest(msgId, cont); // Send abandon message to server conn.writeMessage(msg); } catch (LDAPException ex) {; // do nothing } // If not informing user, remove message from agent if (informUserEx == null) { agent.abandon(msgId, null); } conn.removeMessage(this); } // Get rid of all replies queued if (informUserEx != null) { replies.addElement(new LDAPResponse(informUserEx, conn.getActiveReferral())); if (Debug.LDAP_DEBUG) { Debug.trace( Debug.messages, name + "Queued exception as LDAPResponse (" + replies.size() + " in queue):" + " following referral=" + (conn.getActiveReferral() != null) + "\n\texception: " + informUserEx.getLDAPErrorMessage()); } stopTimer(); // wake up waiting threads to receive exception sleepersAwake(); // Message will get cleaned up when last response removed from queue } else { // Wake up any waiting threads, so they can terminate. // If informing the user, we wake sleepers after // caller queues dummy response with error status sleepersAwake(); cleanup(); } return; }