Beispiel #1
0
 /**
  * removes the listener from the list of Persistent Search listeners of the asynchronous seach for
  * the given search ID.
  *
  * @param request The request returned by the addListener
  * @supported.api
  */
 protected void removeListener(Request request) {
   LDAPConnection connection = request.getLDAPConnection();
   if (connection != null) {
     if (debugger.messageEnabled()) {
       debugger.message(
           "EventService.removeListener(): Removing "
               + "listener requestID: "
               + request.getRequestID()
               + " Listener: "
               + request.getListener());
     }
     try {
       if ((connection != null) && (connection.isConnected())) {
         connection.abandon(request.getId());
         connection.disconnect();
       }
     } catch (LDAPException le) {
       // Might have to check the reset codes and try to reset
       if (debugger.warningEnabled()) {
         debugger.warning(
             "EventService.removeListener(): " + "LDAPException, when trying to remove listener",
             le);
       }
     }
   }
 }
Beispiel #2
0
 /** Helper method to disconnect from Directory Server. */
 private static void disconnectDServer(LDAPConnection ld) {
   if ((ld != null) && ld.isConnected()) {
     try {
       ld.disconnect();
     } catch (LDAPException e) {
     }
   }
 }
Beispiel #3
0
  /**
   * Adds a listener to the directory.
   *
   * @supported.api
   */
  protected synchronized String addListener(
      SSOToken token,
      IDSEventListener listener,
      String base,
      int scope,
      String filter,
      int operations)
      throws LDAPException, EventException {

    if (_shutdownCalled) {
      throw new EventException(i18n.getString(IUMSConstants.DSCFG_CONNECTFAIL));
    }

    LDAPConnection lc = null;
    try {
      // Check for SMS listener and use "sms" group if present
      if ((listener.getClass().getName().equals("com.sun.identity.sm.ldap.LDAPEventManager"))
          && (cm.getServerGroup("sms") != null)) {
        lc = cm.getNewConnection("sms", LDAPUser.Type.AUTH_ADMIN);

      } else {
        lc = cm.getNewAdminConnection();
      }
    } catch (LDAPServiceException le) {
      throw new EventException(i18n.getString(IUMSConstants.DSCFG_CONNECTFAIL), le);
    }

    LDAPSearchConstraints cons = lc.getSearchConstraints();

    // Create Persistent Search Control object
    LDAPPersistSearchControl psearchCtrl =
        new LDAPPersistSearchControl(operations, CHANGES_ONLY, RETURN_CONTROLS, IS_CRITICAL);

    // Add LDAPControl array to the search constraint object
    cons.setServerControls(psearchCtrl);
    cons.setBatchSize(1);

    // Listeners can not read attributes from the event.
    // Request only javaClassName to be able to determine object type
    String[] attrs = new String[] {"objectclass"};
    LDAPSearchListener searchListener = null;
    // Set (asynchronous) persistent search request in the DS
    try {
      if (debugger.messageEnabled()) {
        debugger.message(
            "EventService.addListener() - Submiting "
                + "Persistent Search on: "
                + base
                + " for listener: "
                + listener);
      }
      searchListener = lc.search(base, scope, filter, attrs, false, null, cons);
    } catch (LDAPException le) {
      if ((lc != null) && lc.isConnected()) {
        try {
          lc.disconnect();
        } catch (Exception ex) {
          // ignored
        }
      }
      debugger.error(
          "EventService.addListener() - Failed to set " + "Persistent Search" + le.getMessage());
      throw le;
    }

    int[] outstandingRequests = searchListener.getMessageIDs();
    int id = outstandingRequests[outstandingRequests.length - 1];

    String reqID = Integer.toString(id);
    long startTime = System.currentTimeMillis();
    Request request =
        new Request(
            id, reqID, token, base, scope, filter, attrs, operations, listener, lc, startTime);
    _requestList.put(reqID, request);

    // Add this search request to the m_msgQueue so it can be
    // processed by the monitor thread
    if (_msgQueue == null) {
      _msgQueue = searchListener;
    } else {
      _msgQueue.merge(searchListener);
    }

    if (!_isThreadStarted) {
      startMonitorThread();
    } else {
      if (_requestList.size() == 1) {
        notify();
      }
    }

    if (debugger.messageEnabled()) {
      outstandingRequests = _msgQueue.getMessageIDs();
      debugger.message(
          "EventService.addListener(): merged Listener: "
              + " requestID: "
              + reqID
              + " & Request: "
              + request
              + " on to message Queue. No. of current outstanding "
              + "requests = "
              + outstandingRequests.length);
    }

    // Create new (EventService) Thread, if one doesn't exist.
    return reqID;
  }