From 5ea0197fec6beb79da70bc0461dc468ed11be9c0 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 16 Feb 2012 17:23:59 +0000
Subject: [PATCH] Fix OPENDJ-422: Concurrent writes of large LDAP messages can become interleaved
---
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java | 14
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPServerFilter.java | 159 +++++++------
/dev/null | 375 -------------------------------
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java | 9
opendj-sdk/opendj3/pom.xml | 2
opendj-sdk/opendj3/opendj-ldap-sdk/pom.xml | 2
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java | 120 ++++++---
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPClientFilter.java | 4
8 files changed, 180 insertions(+), 505 deletions(-)
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/pom.xml b/opendj-sdk/opendj3/opendj-ldap-sdk/pom.xml
index 53b2fae..504fb9b 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/pom.xml
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/pom.xml
@@ -47,7 +47,7 @@
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
- <version>2.1.7</version>
+ <version>2.1.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPClientFilter.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPClientFilter.java
index 9468824..8635ad5 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPClientFilter.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPClientFilter.java
@@ -126,8 +126,8 @@
if (!bindClient.evaluateResult(result))
{
// The server is expecting a multi stage bind response.
- final int msgID = ldapConnection
- .addPendingRequest(pendingRequest);
+ final int msgID =
+ ldapConnection.continuePendingBindRequest(future);
final ASN1BufferWriter asn1Writer =
ASN1BufferWriter.getWriter();
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
index 8894e8c..1988d9d 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
@@ -30,7 +30,6 @@
-import static com.forgerock.opendj.ldap.SynchronizedConnection.synchronizeConnection;
import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult;
import java.io.IOException;
@@ -49,9 +48,9 @@
import org.forgerock.opendj.ldap.requests.*;
import org.forgerock.opendj.ldap.responses.*;
import org.glassfish.grizzly.CompletionHandler;
-import org.glassfish.grizzly.filterchain.DefaultFilterChain;
import org.glassfish.grizzly.filterchain.Filter;
import org.glassfish.grizzly.filterchain.FilterChain;
+import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
import org.glassfish.grizzly.ssl.SSLFilter;
@@ -69,9 +68,8 @@
final class LDAPConnection extends AbstractAsynchronousConnection implements
Connection
{
- private final SynchronizedConnection<?> connection;
+ private final org.glassfish.grizzly.Connection<?> connection;
private Result connectionInvalidReason;
- private FilterChain customFilterChain;
private boolean isClosed = false;
private final List<ConnectionEventListener> listeners =
new CopyOnWriteArrayList<ConnectionEventListener>();
@@ -97,8 +95,7 @@
LDAPConnection(final org.glassfish.grizzly.Connection<?> connection,
final LDAPOptions options)
{
- // FIXME: remove synchronization when OPENDJ-422 is resolved.
- this.connection = synchronizeConnection(connection);
+ this.connection = connection;
this.options = options;
}
@@ -255,9 +252,8 @@
{
context = request
.createBindClient(connection.getPeerAddress() instanceof InetSocketAddress ?
- ((InetSocketAddress) connection
- .getPeerAddress()).getHostName() : connection.getPeerAddress()
- .toString());
+ ((InetSocketAddress) connection.getPeerAddress()).getHostName()
+ : connection.getPeerAddress().toString());
}
catch (final Exception e)
{
@@ -567,7 +563,10 @@
*/
public boolean isClosed()
{
- return isClosed;
+ synchronized (stateLock)
+ {
+ return isClosed;
+ }
}
@@ -577,7 +576,10 @@
*/
public boolean isValid()
{
- return connectionInvalidReason == null && !isClosed;
+ synchronized (stateLock)
+ {
+ return connectionInvalidReason == null && !isClosed;
+ }
}
@@ -784,7 +786,7 @@
- int addPendingRequest(final AbstractLDAPFutureResultImpl<?> request)
+ int continuePendingBindRequest(final LDAPBindFutureResultImpl future)
throws ErrorResultException
{
final int newMsgID = nextMsgID.getAndIncrement();
@@ -794,7 +796,7 @@
{
throw newErrorResult(connectionInvalidReason);
}
- pendingRequests.put(newMsgID, request);
+ pendingRequests.put(newMsgID, future);
}
return newMsgID;
}
@@ -969,9 +971,9 @@
- synchronized void handleUnsolicitedNotification(final ExtendedResult result)
+ void handleUnsolicitedNotification(final ExtendedResult result)
{
- if (isClosed)
+ if (isClosed())
{
// Don't notify after connection is closed.
return;
@@ -985,17 +987,41 @@
+ /**
+ * Installs a new Grizzly filter (e.g. SSL/SASL) beneath the top-level LDAP
+ * filter.
+ *
+ * @param filter
+ * The filter to be installed.
+ */
void installFilter(final Filter filter)
{
- if (customFilterChain == null)
+ synchronized (stateLock)
{
- customFilterChain = new DefaultFilterChain(
- (FilterChain) connection.getProcessor());
- connection.setProcessor(customFilterChain);
- }
+ // Determine the index where the filter should be added.
+ FilterChain oldFilterChain = (FilterChain) connection.getProcessor();
+ int filterIndex = oldFilterChain.size() - 1;
+ if (filter instanceof SSLFilter)
+ {
+ // Beneath any ConnectionSecurityLayerFilters if present, otherwise
+ // beneath the LDAP filter.
+ for (int i = oldFilterChain.size() - 2; i >= 0; i--)
+ {
+ if (!(oldFilterChain.get(i) instanceof ConnectionSecurityLayerFilter))
+ {
+ filterIndex = i + 1;
+ break;
+ }
+ }
+ }
- // Install the SSLFilter in the custom filter chain
- customFilterChain.add(customFilterChain.size() - 1, filter);
+ // Create the new filter chain.
+ FilterChain newFilterChain = FilterChainBuilder.stateless()
+ .addAll(oldFilterChain)
+ .add(filterIndex, filter)
+ .build();
+ connection.setProcessor(newFilterChain);
+ }
}
@@ -1008,9 +1034,19 @@
*/
boolean isTLSEnabled()
{
- final FilterChain currentFilterChain = (FilterChain) connection
- .getProcessor();
- return currentFilterChain.get(currentFilterChain.size() - 2) instanceof SSLFilter;
+ synchronized (stateLock)
+ {
+ final FilterChain currentFilterChain = (FilterChain) connection
+ .getProcessor();
+ for (Filter filter : currentFilterChain)
+ {
+ if (filter instanceof SSLFilter)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}
@@ -1029,28 +1065,28 @@
- synchronized void startTLS(final SSLContext sslContext,
+ void startTLS(final SSLContext sslContext,
final List<String> protocols, final List<String> cipherSuites,
final CompletionHandler<SSLEngine> completionHandler) throws IOException
{
- if (isTLSEnabled())
+ synchronized (stateLock)
{
- return;
+ if (isTLSEnabled())
+ {
+ throw new IllegalStateException("TLS already enabled");
+ }
+
+ SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator(
+ sslContext, true, false, false);
+ sslEngineConfigurator.setEnabledProtocols(protocols.isEmpty() ? null
+ : protocols.toArray(new String[protocols.size()]));
+ sslEngineConfigurator
+ .setEnabledCipherSuites(cipherSuites.isEmpty() ? null : cipherSuites
+ .toArray(new String[cipherSuites.size()]));
+ SSLFilter sslFilter = new SSLFilter(null, sslEngineConfigurator);
+ installFilter(sslFilter);
+ sslFilter.handshake(connection, completionHandler);
}
-
- SSLFilter sslFilter;
- SSLEngineConfigurator sslEngineConfigurator;
-
- sslEngineConfigurator = new SSLEngineConfigurator(sslContext, true, false,
- false);
- sslEngineConfigurator.setEnabledProtocols(protocols.isEmpty() ? null
- : protocols.toArray(new String[protocols.size()]));
- sslEngineConfigurator.setEnabledCipherSuites(cipherSuites.isEmpty() ? null
- : cipherSuites.toArray(new String[cipherSuites.size()]));
- sslFilter = new SSLFilter(null, sslEngineConfigurator);
- installFilter(sslFilter);
- sslFilter.handshake(connection.getUnsynchronizedConnection(),
- completionHandler);
}
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
index 4b11b85..71b5131 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
@@ -45,8 +45,8 @@
import org.forgerock.opendj.ldap.responses.Result;
import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.EmptyCompletionHandler;
-import org.glassfish.grizzly.filterchain.DefaultFilterChain;
import org.glassfish.grizzly.filterchain.FilterChain;
+import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
@@ -261,9 +261,10 @@
this.options = new LDAPOptions(options);
this.clientFilter = new LDAPClientFilter(new LDAPReader(
this.options.getDecodeOptions()), 0);
- this.defaultFilterChain = new DefaultFilterChain();
- this.defaultFilterChain.add(new TransportFilter());
- this.defaultFilterChain.add(clientFilter);
+ this.defaultFilterChain = FilterChainBuilder.stateless()
+ .add(new TransportFilter())
+ .add(clientFilter)
+ .build();
}
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java
index 5dc3f19..a1c1fd5 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java
@@ -39,8 +39,8 @@
import org.forgerock.opendj.ldap.LDAPClientContext;
import org.forgerock.opendj.ldap.LDAPListenerOptions;
import org.forgerock.opendj.ldap.ServerConnectionFactory;
-import org.glassfish.grizzly.filterchain.DefaultFilterChain;
import org.glassfish.grizzly.filterchain.FilterChain;
+import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
@@ -89,10 +89,14 @@
this.transport = options.getTCPNIOTransport();
}
this.connectionFactory = factory;
- this.defaultFilterChain = new DefaultFilterChain();
- this.defaultFilterChain.add(new TransportFilter());
- this.defaultFilterChain.add(new LDAPServerFilter(this, new LDAPReader(
- new DecodeOptions(options.getDecodeOptions())), 0));
+
+ final DecodeOptions decodeOptions = new DecodeOptions(options
+ .getDecodeOptions());
+ this.defaultFilterChain = FilterChainBuilder
+ .stateless()
+ .add(new TransportFilter())
+ .add(new LDAPServerFilter(this, new LDAPReader(decodeOptions), 0))
+ .build();
this.serverConnection = transport.bind(address, options.getBacklog());
this.serverConnection.setProcessor(defaultFilterChain);
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPServerFilter.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPServerFilter.java
index c9b5564..d44bfbc 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPServerFilter.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPServerFilter.java
@@ -31,7 +31,6 @@
import static com.forgerock.opendj.ldap.LDAPConstants.OID_NOTICE_OF_DISCONNECTION;
-import static com.forgerock.opendj.ldap.SynchronizedConnection.synchronizeConnection;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -215,8 +214,7 @@
private ClientContextImpl(final Connection<?> connection)
{
- // FIXME: remove synchronization when OPENDJ-422 is resolved.
- this.connection = synchronizeConnection(connection);
+ this.connection = connection;
}
@@ -320,27 +318,36 @@
public void enableConnectionSecurityLayer(
final ConnectionSecurityLayer layer)
{
- installFilter(connection, new ConnectionSecurityLayerFilter(layer,
- connection.getTransport().getMemoryManager()));
+ synchronized (this)
+ {
+ installFilter(new ConnectionSecurityLayerFilter(layer, connection
+ .getTransport().getMemoryManager()));
+ }
}
@Override
- public void enableTLS(final SSLContext sslContext, final String[] protocols,
- final String[] suites, final boolean wantClientAuth,
- final boolean needClientAuth)
+ public void enableTLS(final SSLContext sslContext,
+ final String[] protocols, final String[] suites,
+ final boolean wantClientAuth, final boolean needClientAuth)
{
Validator.ensureNotNull(sslContext);
- SSLEngineConfigurator sslEngineConfigurator;
+ synchronized (this)
+ {
+ if (isTLSEnabled())
+ {
+ throw new IllegalStateException("TLS already enabled");
+ }
- sslEngineConfigurator = new SSLEngineConfigurator(sslContext, false,
- false, false);
- sslEngineConfigurator.setEnabledCipherSuites(suites);
- sslEngineConfigurator.setEnabledProtocols(protocols);
- sslEngineConfigurator.setWantClientAuth(wantClientAuth);
- sslEngineConfigurator.setNeedClientAuth(needClientAuth);
- installFilter(connection, new SSLFilter(sslEngineConfigurator, null));
+ SSLEngineConfigurator sslEngineConfigurator =
+ new SSLEngineConfigurator(sslContext, false, false, false);
+ sslEngineConfigurator.setEnabledCipherSuites(suites);
+ sslEngineConfigurator.setEnabledProtocols(protocols);
+ sslEngineConfigurator.setWantClientAuth(wantClientAuth);
+ sslEngineConfigurator.setNeedClientAuth(needClientAuth);
+ installFilter(new SSLFilter(sslEngineConfigurator, null));
+ }
}
@@ -383,9 +390,61 @@
- private Connection<?> getConnection()
+ /**
+ * Installs a new Grizzly filter (e.g. SSL/SASL) beneath the top-level LDAP
+ * filter.
+ *
+ * @param filter
+ * The filter to be installed.
+ */
+ private void installFilter(final Filter filter)
{
- return connection;
+ // Determine the index where the filter should be added.
+ final FilterChain oldFilterChain = (FilterChain) connection.getProcessor();
+ int filterIndex = oldFilterChain.size() - 1;
+ if (filter instanceof SSLFilter)
+ {
+ // Beneath any ConnectionSecurityLayerFilters if present, otherwise
+ // beneath the LDAP filter.
+ for (int i = oldFilterChain.size() - 2; i >= 0; i--)
+ {
+ if (!(oldFilterChain.get(i) instanceof ConnectionSecurityLayerFilter))
+ {
+ filterIndex = i + 1;
+ break;
+ }
+ }
+ }
+
+ // Create the new filter chain.
+ final FilterChain newFilterChain = FilterChainBuilder.stateless()
+ .addAll(oldFilterChain).add(filterIndex, filter).build();
+ connection.setProcessor(newFilterChain);
+ }
+
+
+
+ /**
+ * Indicates whether or not TLS is enabled this provided connection.
+ *
+ * @return {@code true} if TLS is enabled on this connection, otherwise
+ * {@code false}.
+ */
+ private boolean isTLSEnabled()
+ {
+ synchronized (this)
+ {
+ final FilterChain currentFilterChain = (FilterChain) connection
+ .getProcessor();
+ for (Filter filter : currentFilterChain)
+ {
+ if (filter instanceof SSLFilter)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}
}
@@ -880,7 +939,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final AddHandler handler = new AddHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleAdd(messageID, request, handler, handler);
}
}
@@ -899,7 +958,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final BindHandler handler = new BindHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleBind(messageID, version, bindContext, handler, handler);
}
}
@@ -918,7 +977,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final CompareHandler handler = new CompareHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleCompare(messageID, request, handler, handler);
}
}
@@ -937,7 +996,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final DeleteHandler handler = new DeleteHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleDelete(messageID, request, handler, handler);
}
}
@@ -956,7 +1015,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final ExtendedHandler<R> handler = new ExtendedHandler<R>(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleExtendedRequest(messageID, request, handler, handler);
}
}
@@ -975,7 +1034,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final ModifyDNHandler handler = new ModifyDNHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleModifyDN(messageID, request, handler, handler);
}
}
@@ -994,7 +1053,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final ModifyHandler handler = new ModifyHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleModify(messageID, request, handler, handler);
}
}
@@ -1013,7 +1072,7 @@
final ServerConnection<Integer> conn = clientContext
.getServerConnection();
final SearchHandler handler = new SearchHandler(messageID,
- clientContext.getConnection());
+ ctx.getConnection());
conn.handleSearch(messageID, request, handler, handler);
}
}
@@ -1128,52 +1187,4 @@
return ctx.getStopAction();
}
-
-
-
- private synchronized void installFilter(final Connection<?> connection,
- final org.glassfish.grizzly.filterchain.Filter filter)
- {
- FilterChain filterChain = (FilterChain) connection.getProcessor();
-
- // Ensure that the SSL filter is not installed twice.
- if (filter instanceof SSLFilter)
- {
- for (Filter f : filterChain)
- {
- if (f instanceof SSLFilter)
- {
- // SSLFilter already installed.
- throw new IllegalStateException("SSL already installed on connection");
- }
- }
- }
-
- // Copy on update the default filter chain.
- if (listener.getDefaultFilterChain() == filterChain)
- {
- filterChain = new DefaultFilterChain(filterChain);
- connection.setProcessor(filterChain);
- }
-
- // Ensure that the SSL filter is beneath any connection security layer
- // filters.
- if (filter instanceof SSLFilter)
- {
- for (int i = filterChain.size() - 1; i >= 0; i--)
- {
- if (!(filterChain.get(i) instanceof ConnectionSecurityLayerFilter))
- {
- filterChain.add(i, filter);
- break;
- }
- }
- }
- else
- {
- // Add connection security layers to the end of the chain.
- filterChain.add(filterChain.size() - 1, filter);
- }
-
- }
}
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/SynchronizedConnection.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/SynchronizedConnection.java
deleted file mode 100644
index daafc7e..0000000
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/SynchronizedConnection.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opendj3/legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opendj3/legal-notices/CDDLv1_0.txt. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- * Copyright 2012 ForgeRock AS
- */
-
-package com.forgerock.opendj.ldap;
-
-
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-import org.glassfish.grizzly.*;
-import org.glassfish.grizzly.attributes.AttributeHolder;
-import org.glassfish.grizzly.monitoring.MonitoringConfig;
-
-
-
-/**
- * A Grizzly connection which synchronizes write requests in order to workaround
- * issue GRIZZLY-1191 (http://java.net/jira/browse/GRIZZLY-1191). See OPENDJ-422
- * (https://bugster.forgerock.org/jira/browse/OPENDJ-422) for more information.
- * <p>
- * This class should be removed once we issue GRIZZLY-422 is resolved and/or we
- * move to non-blocking IO (requires Grizzly 2.2).
- */
-final class SynchronizedConnection<L> implements Connection<L>
-{
- private final Connection<L> connection;
- private final Object writeLock = new Object();
-
-
-
- /**
- * Returns a synchronized view of the provided Grizzly connection.
- *
- * @param connection
- * The Grizzly connection to be synchronized.
- * @return The synchronized view of the provided Grizzly connection.
- */
- static <L> SynchronizedConnection<L> synchronizeConnection(
- Connection<L> connection)
- {
- if (connection instanceof SynchronizedConnection)
- {
- return (SynchronizedConnection<L>) connection;
- }
- else
- {
- return new SynchronizedConnection<L>(connection);
- }
- }
-
-
-
- private SynchronizedConnection(Connection<L> connection)
- {
- this.connection = connection;
- }
-
-
-
- /**
- * Returns the underlying unsynchronized connection.
- *
- * @return The underlying unsynchronized connection.
- */
- Connection<L> getUnsynchronizedConnection()
- {
- return connection;
- }
-
-
-
- public <M> GrizzlyFuture<WriteResult<M, L>> write(M message)
- throws IOException
- {
- synchronized (writeLock)
- {
- return connection.write(message);
- }
- }
-
-
-
- public <M> GrizzlyFuture<ReadResult<M, L>> read() throws IOException
- {
- return connection.read();
- }
-
-
-
- public AttributeHolder getAttributes()
- {
- return connection.getAttributes();
- }
-
-
-
- public <M> GrizzlyFuture<ReadResult<M, L>> read(
- CompletionHandler<ReadResult<M, L>> completionHandler) throws IOException
- {
- return connection.read(completionHandler);
- }
-
-
-
- public Transport getTransport()
- {
- return connection.getTransport();
- }
-
-
-
- public <M> GrizzlyFuture<WriteResult<M, L>> write(M message,
- CompletionHandler<WriteResult<M, L>> completionHandler)
- throws IOException
- {
- synchronized (writeLock)
- {
- return connection.write(message, completionHandler);
- }
- }
-
-
-
- public boolean isOpen()
- {
- return connection.isOpen();
- }
-
-
-
- public void configureBlocking(boolean isBlocking)
- {
- connection.configureBlocking(isBlocking);
- }
-
-
-
- public <M> GrizzlyFuture<WriteResult<M, L>> write(L dstAddress, M message,
- CompletionHandler<WriteResult<M, L>> completionHandler)
- throws IOException
- {
- synchronized (writeLock)
- {
- return connection.write(dstAddress, message, completionHandler);
- }
- }
-
-
-
- public boolean isBlocking()
- {
- return connection.isBlocking();
- }
-
-
-
- public void configureStandalone(boolean isStandalone)
- {
- connection.configureStandalone(isStandalone);
- }
-
-
-
- public boolean isStandalone()
- {
- return connection.isStandalone();
- }
-
-
-
- @SuppressWarnings("rawtypes")
- public Processor obtainProcessor(IOEvent ioEvent)
- {
- return connection.obtainProcessor(ioEvent);
- }
-
-
-
- @SuppressWarnings("rawtypes")
- public Processor getProcessor()
- {
- return connection.getProcessor();
- }
-
-
-
- @SuppressWarnings("rawtypes")
- public void setProcessor(Processor preferableProcessor)
- {
- connection.setProcessor(preferableProcessor);
- }
-
-
-
- public ProcessorSelector getProcessorSelector()
- {
- return connection.getProcessorSelector();
- }
-
-
-
- public void setProcessorSelector(ProcessorSelector preferableProcessorSelector)
- {
- connection.setProcessorSelector(preferableProcessorSelector);
- }
-
-
-
- public L getPeerAddress()
- {
- return connection.getPeerAddress();
- }
-
-
-
- public L getLocalAddress()
- {
- return connection.getLocalAddress();
- }
-
-
-
- @SuppressWarnings("rawtypes")
- public GrizzlyFuture<Connection> close() throws IOException
- {
- synchronized (writeLock)
- {
- return connection.close();
- }
- }
-
-
-
- @SuppressWarnings("rawtypes")
- public GrizzlyFuture<Connection> close(
- CompletionHandler<Connection> completionHandler) throws IOException
- {
- synchronized (writeLock)
- {
- return connection.close(completionHandler);
- }
- }
-
-
-
- public int getReadBufferSize()
- {
- return connection.getReadBufferSize();
- }
-
-
-
- public void setReadBufferSize(int readBufferSize)
- {
- connection.setReadBufferSize(readBufferSize);
- }
-
-
-
- public int getWriteBufferSize()
- {
- return connection.getWriteBufferSize();
- }
-
-
-
- public void setWriteBufferSize(int writeBufferSize)
- {
- connection.setWriteBufferSize(writeBufferSize);
- }
-
-
-
- public long getReadTimeout(TimeUnit timeUnit)
- {
- return connection.getReadTimeout(timeUnit);
- }
-
-
-
- public void setReadTimeout(long timeout, TimeUnit timeUnit)
- {
- connection.setReadTimeout(timeout, timeUnit);
- }
-
-
-
- public long getWriteTimeout(TimeUnit timeUnit)
- {
- return connection.getWriteTimeout(timeUnit);
- }
-
-
-
- public void setWriteTimeout(long timeout, TimeUnit timeUnit)
- {
- connection.setWriteTimeout(timeout, timeUnit);
- }
-
-
-
- public void enableIOEvent(IOEvent ioEvent) throws IOException
- {
- connection.enableIOEvent(ioEvent);
- }
-
-
-
- public void disableIOEvent(IOEvent ioEvent) throws IOException
- {
- connection.disableIOEvent(ioEvent);
- }
-
-
-
- public MonitoringConfig<ConnectionProbe> getMonitoringConfig()
- {
- return connection.getMonitoringConfig();
- }
-
-
-
- public void addCloseListener(
- org.glassfish.grizzly.Connection.CloseListener closeListener)
- {
- connection.addCloseListener(closeListener);
- }
-
-
-
- public boolean removeCloseListener(
- org.glassfish.grizzly.Connection.CloseListener closeListener)
- {
- return connection.removeCloseListener(closeListener);
- }
-
-
-
- public void notifyConnectionError(Throwable error)
- {
- connection.notifyConnectionError(error);
- }
-
-
-
- public String toString()
- {
- return connection.toString();
- }
-
-}
diff --git a/opendj-sdk/opendj3/pom.xml b/opendj-sdk/opendj3/pom.xml
index ad22401..8718440 100644
--- a/opendj-sdk/opendj3/pom.xml
+++ b/opendj-sdk/opendj3/pom.xml
@@ -826,7 +826,6 @@
<enabled>false</enabled>
</releases>
</repository>
- <!--
<repository>
<id>jvnet-nexus-snapshots</id>
<url>https://maven.java.net/content/repositories/snapshots</url>
@@ -837,7 +836,6 @@
<enabled>true</enabled>
</snapshots>
</repository>
- -->
</repositories>
<dependencyManagement>
<dependencies>
--
Gitblit v1.10.0