/** {@inheritDoc} */
    @Override
    public void addCancelRequestListener(final CancelRequestListener listener) {
      Reject.ifNull(listener);

      boolean invokeImmediately = false;
      synchronized (stateLock) {
        switch (state) {
          case PENDING:
            if (cancelRequestListeners == null) {
              cancelRequestListeners = new LinkedList<>();
            }
            cancelRequestListeners.add(listener);
            break;
          case CANCEL_REQUESTED:
            // Signal immediately outside lock.
            invokeImmediately = true;
            break;
          case TOO_LATE:
          case RESULT_SENT:
          case CANCELLED:
            /*
             * No point in registering the callback since the request
             * can never be cancelled now.
             */
            break;
        }
      }

      if (invokeImmediately) {
        listener.handleCancelRequest(cancelRequestReason);
      }
    }
    /** {@inheritDoc} */
    @Override
    public void removeCancelRequestListener(final CancelRequestListener listener) {
      Reject.ifNull(listener);

      synchronized (stateLock) {
        if (cancelRequestListeners != null) {
          cancelRequestListeners.remove(listener);
        }
      }
    }
  /**
   * Attempts to convert the given field name, operator and value into an appropriate SearchFilter
   * instance. The conversion used depends on the {@link QueryAttribute} configured for this field
   * in the queryAttributes map.
   *
   * @param field Non null, The name of a queryable Application attribute.
   * @param operator Non null, The query operator to use when comparing the field value to the
   *     valueAssertion.
   * @param valueAssertion Non null, The value with which the Application field's value should be
   *     compared.
   */
  protected SearchFilter comparison(
      String field, SearchFilter.Operator operator, Object valueAssertion) {
    Reject.ifNull(field, operator, valueAssertion);

    QueryAttribute attribute = queryAttributes.get(field);
    if (attribute == null) {
      throw new UnsupportedOperationException("Unknown query field '" + field + "'");
    }

    return attribute.getFilter(operator, valueAssertion);
  }
 /**
  * Constructs a script object with the given name, script body, language and variable bindings.
  *
  * @param name the name of the script.
  * @param script the script itself.
  * @param language the language that the script is written in.
  * @param bindings the bindings used for the script.
  */
 public ScriptObject(
     final String name,
     final String script,
     final ScriptingLanguage language,
     final Bindings bindings) {
   Reject.ifNull(name, script, language);
   this.name = name;
   this.script = script;
   this.language = language;
   this.bindings = bindings;
 }
Exemple #5
0
 /**
  * Open a log with the provided log path, record parser and maximum size per log file.
  *
  * <p>If no log exists for the provided path, a new one is created.
  *
  * @param <K> Type of the key of a record, which must be comparable.
  * @param <V> Type of the value of a record.
  * @param replicationEnv The replication environment used to create this log.
  * @param logPath Path of the log.
  * @param parser Parser for encoding/decoding of records.
  * @param rotationParameters Parameters for the log files rotation.
  * @return a log
  * @throws ChangelogException If a problem occurs during initialization.
  */
 static synchronized <K extends Comparable<K>, V> Log<K, V> openLog(
     final ReplicationEnvironment replicationEnv,
     final File logPath,
     final RecordParser<K, V> parser,
     final LogRotationParameters rotationParameters)
     throws ChangelogException {
   Reject.ifNull(logPath, parser);
   @SuppressWarnings("unchecked")
   Log<K, V> log = (Log<K, V>) logsCache.get(logPath);
   if (log == null) {
     log = new Log<>(replicationEnv, logPath, parser, rotationParameters);
     logsCache.put(logPath, log);
   } else {
     // TODO : check that parser and size limit are compatible with the existing one,
     // and issue a warning if it is not the case
     log.referenceCount++;
   }
   return log;
 }
    private <R extends ExtendedResult> void cancel(
        final LocalizableMessage reason,
        final ExtendedRequest<R> cancelRequest,
        final LdapResultHandler<R> cancelResultHandler,
        final boolean sendResult) {
      Reject.ifNull(reason);

      if (!isCancelSupported) {
        if (cancelResultHandler != null) {
          final Result result = Responses.newGenericExtendedResult(ResultCode.CANNOT_CANCEL);
          cancelResultHandler.handleException(newLdapException(result));
        }
        return;
      }

      List<CancelRequestListener> tmpListeners = null;
      boolean invokeResultHandler = false;
      boolean resultHandlerIsSuccess = false;

      synchronized (stateLock) {
        switch (state) {
          case PENDING:
            /* Switch to CANCEL_REQUESTED state. */
            cancelRequestReason = reason;
            if (cancelResultHandler != null) {
              cancelResultHandlers = new LinkedList<>();
              cancelResultHandlers.add(
                  new ExtendedResultHandlerHolder<R>(cancelRequest, cancelResultHandler));
            }
            tmpListeners = cancelRequestListeners;
            cancelRequestListeners = null;
            state = RequestState.CANCEL_REQUESTED;
            this.sendResult &= sendResult;
            break;
          case CANCEL_REQUESTED:
            /*
             * Cancel already request so listeners already invoked.
             */
            if (cancelResultHandler != null) {
              if (cancelResultHandlers == null) {
                cancelResultHandlers = new LinkedList<>();
              }
              cancelResultHandlers.add(
                  new ExtendedResultHandlerHolder<R>(cancelRequest, cancelResultHandler));
            }
            break;
          case TOO_LATE:
          case RESULT_SENT:
            /*
             * Cannot cancel, so invoke result handler immediately
             * outside of lock.
             */
            if (cancelResultHandler != null) {
              invokeResultHandler = true;
              resultHandlerIsSuccess = false;
            }
            break;
          case CANCELLED:
            /*
             * Multiple cancellation attempts. Clients should not do
             * this, but the cancel will effectively succeed
             * immediately, so invoke result handler immediately outside
             * of lock.
             */
            if (cancelResultHandler != null) {
              invokeResultHandler = true;
              resultHandlerIsSuccess = true;
            }
            break;
        }
      }

      /* Invoke listeners outside of lock. */
      if (tmpListeners != null) {
        for (final CancelRequestListener listener : tmpListeners) {
          listener.handleCancelRequest(reason);
        }
      }

      if (invokeResultHandler) {
        if (resultHandlerIsSuccess) {
          final R result =
              cancelRequest.getResultDecoder().newExtendedErrorResult(ResultCode.SUCCESS, "", "");
          cancelResultHandler.handleResult(result);
        } else {
          final Result result = Responses.newGenericExtendedResult(ResultCode.TOO_LATE);
          cancelResultHandler.handleException(newLdapException(result));
        }
      }
    }
 /**
  * Creates a new {@code FallbackAuthContext} managing the provided {@code AsyncServerAuthModule}s.
  *
  * @param logger The {@link Logger} instance.
  * @param authModules The {@code List} of {@code AsyncServerAuthModule}s.
  */
 public FallbackAuthContext(Logger logger, List<AsyncServerAuthModule> authModules) {
   Reject.ifNull(logger, authModules);
   this.logger = logger;
   this.authModules = withValidation(withAuditing(withLogging(logger, authModules)));
 }
 /**
  * Sets the decoding options which will be used to control how requests and responses are decoded.
  *
  * @param decodeOptions The decoding options which will be used to control how requests and
  *     responses are decoded (never {@code null}).
  * @return A reference to this set of options.
  * @throws NullPointerException If {@code decodeOptions} was {@code null}.
  */
 public T setDecodeOptions(final DecodeOptions decodeOptions) {
   Reject.ifNull(decodeOptions);
   this.decodeOptions = decodeOptions;
   return getThis();
 }
Exemple #9
0
 public void put(WriteableTransaction txn, EntryID entryID, ByteSequence encodedEntry)
     throws StorageRuntimeException, DirectoryException {
   Reject.ifNull(txn, "txn must not be null.");
   txn.put(getName(), entryID.toByteString(), encodedEntry);
 }
Exemple #10
0
 /**
  * Creates a new Root DSE instance backed by the provided entry. Modifications made to {@code
  * entry} will be reflected in the returned Root DSE. The returned Root DSE instance is
  * unmodifiable and attempts to use modify any of the returned collections will result in a {@code
  * UnsupportedOperationException}.
  *
  * @param entry The Root DSE entry.
  * @return A Root DSE instance backed by the provided entry.
  * @throws NullPointerException If {@code entry} was {@code null} .
  */
 public static RootDSE valueOf(Entry entry) {
   Reject.ifNull(entry);
   return new RootDSE(entry);
 }
 /**
  * Constructs the compiled script with the given script engine and compiled Rhino script object.
  *
  * @param engine the script engine to use to run the compiled script. Must not be null.
  * @param compiledScript the compiled script itself. Must not be null.
  */
 RhinoCompiledScript(final RhinoScriptEngine engine, final Script compiledScript) {
   Reject.ifNull(engine, compiledScript);
   this.engine = engine;
   this.compiledScript = compiledScript;
 }
 /**
  * Creates a new contains value condition.
  *
  * @param propertyName The property name.
  * @param stringValue The string representation of the required property value.
  */
 public ContainsCondition(String propertyName, String stringValue) {
   Reject.ifNull(propertyName, stringValue);
   this.propertyName = propertyName;
   this.propertyStringValue = stringValue;
 }