From 6385fb6984cb076c5a4a3ef5233deed798dc81c2 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 02 Jun 2011 01:01:18 +0000
Subject: [PATCH] Fix OPENDJ-183: Add support for RequestContext and RequestHandlers
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java | 77 ++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
index 7fe0ca8..7b1c24c 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
@@ -334,6 +334,83 @@
+ /**
+ * Creates a new server connection factory using the provided
+ * {@link RequestHandler}. The returned factory will manage connection and
+ * request life-cycle, including request cancellation.
+ * <p>
+ * When processing requests, {@link RequestHandler} implementations are passed
+ * a {@link RequestContext} as the first parameter which may be used for
+ * detecting whether or not the request should be aborted due to cancellation
+ * requests or other events, such as connection failure.
+ * <p>
+ * The returned factory maintains state information which includes a table of
+ * active requests. Therefore, {@code RequestHandler} implementations are
+ * required to always return results in order to avoid potential memory leaks.
+ *
+ * @param <C>
+ * The type of client context.
+ * @param requestHandler
+ * The request handler which will be used for all client connections.
+ * @return The new server connection factory.
+ * @throws NullPointerException
+ * If {@code requestHandler} was {@code null}.
+ */
+ public static <C> ServerConnectionFactory<C, Integer> newServerConnectionFactory(
+ final RequestHandler<RequestContext> requestHandler)
+ throws NullPointerException
+ {
+ Validator.ensureNotNull(requestHandler);
+
+ final RequestHandlerFactory<C, RequestContext> factory =
+ new RequestHandlerFactory<C, RequestContext>()
+ {
+
+ public RequestHandler<RequestContext> handleAccept(
+ C clientContext) throws ErrorResultException
+ {
+ return requestHandler;
+ }
+ };
+
+ return new RequestHandlerFactoryAdapter<C>(factory);
+ }
+
+
+
+ /**
+ * Creates a new server connection factory using the provided
+ * {@link RequestHandlerFactory}. The returned factory will manage connection
+ * and request life-cycle, including request cancellation.
+ * <p>
+ * When processing requests, {@link RequestHandler} implementations are passed
+ * a {@link RequestContext} as the first parameter which may be used for
+ * detecting whether or not the request should be aborted due to cancellation
+ * requests or other events, such as connection failure.
+ * <p>
+ * The returned factory maintains state information which includes a table of
+ * active requests. Therefore, {@code RequestHandler} implementations are
+ * required to always return results in order to avoid potential memory leaks.
+ *
+ * @param <C>
+ * The type of client context.
+ * @param factory
+ * The request handler factory to use for associating request
+ * handlers with client connections.
+ * @return The new server connection factory.
+ * @throws NullPointerException
+ * If {@code factory} was {@code null}.
+ */
+ public static <C> ServerConnectionFactory<C, Integer> newServerConnectionFactory(
+ final RequestHandlerFactory<C, RequestContext> factory)
+ throws NullPointerException
+ {
+ Validator.ensureNotNull(factory);
+ return new RequestHandlerFactoryAdapter<C>(factory);
+ }
+
+
+
// Prevent instantiation.
private Connections()
{
--
Gitblit v1.10.0