mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
11.23.2010 6bef18d19414f3680165472e37dc4444da765f13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.opends.sdk;
 
 
 
import com.sun.opends.sdk.util.Validator;
import com.sun.opends.sdk.util.AbstractFutureResult;
 
import org.opends.sdk.responses.Responses;
 
 
 
/**
 * Created by IntelliJ IDEA. User: digitalperk Date: Dec 15, 2009 Time:
 * 3:23:52 PM To change this template use File | Settings | File
 * Templates.
 */
public class LoadBalancingConnectionFactory extends
    AbstractConnectionFactory
{
  private final LoadBalancingAlgorithm algorithm;
 
 
 
  public LoadBalancingConnectionFactory(LoadBalancingAlgorithm algorithm)
  {
    Validator.ensureNotNull(algorithm);
    this.algorithm = algorithm;
  }
 
 
 
  public FutureResult<AsynchronousConnection> getAsynchronousConnection(
      ResultHandler<AsynchronousConnection> resultHandler)
  {
    ConnectionFactory factory = algorithm.getNextConnectionFactory();
    if (factory == null)
    {
      AbstractFutureResult<AsynchronousConnection> future = new AbstractFutureResult<AsynchronousConnection>(
          resultHandler)
      {
        public int getRequestID()
        {
          return -1;
        }
      };
      future.handleErrorResult(new ErrorResultException(Responses
          .newResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR)
          .setDiagnosticMessage("No connection factories available")));
      return future;
    }
 
    return factory.getAsynchronousConnection(resultHandler);
  }
}