View Javadoc
1   /*
2    * #%L
3    * ReconnectStrategy.java - mongodb-async-driver - Allanbank Consulting, Inc.
4    * %%
5    * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  
21  package com.allanbank.mongodb.client.connection;
22  
23  import com.allanbank.mongodb.MongoClientConfiguration;
24  import com.allanbank.mongodb.client.connection.proxy.ProxiedConnectionFactory;
25  import com.allanbank.mongodb.client.state.Cluster;
26  import com.allanbank.mongodb.client.state.ServerSelector;
27  
28  /**
29   * ReconnectStrategy provides a common interface for a strategy for reconnecting
30   * to a MongoDB server.
31   * 
32   * @api.no This class is <b>NOT</b> part of the drivers API. This class may be
33   *         mutated in incompatible ways between any two releases of the driver.
34   * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved
35   */
36  public interface ReconnectStrategy {
37  
38      /**
39       * Sets the configuration to be used by the reconnection strategy.
40       * 
41       * @param config
42       *            The configuration for the connections.
43       */
44      public void setConfig(MongoClientConfiguration config);
45  
46      /**
47       * Sets the connection factory to use to establish connections to the
48       * server.
49       * 
50       * @param connectionFactory
51       *            The connection factory to use to establish connections to the
52       *            server.
53       */
54      public void setConnectionFactory(ProxiedConnectionFactory connectionFactory);
55  
56      /**
57       * Sets the selector to be used by the reconnection strategy.
58       * 
59       * @param selector
60       *            The selector for connections.
61       */
62      public void setSelector(ServerSelector selector);
63  
64      /**
65       * Sets the state of the cluster to be used by the reconnection strategy.
66       * 
67       * @param state
68       *            The state of the cluster.
69       */
70      public void setState(Cluster state);
71  
72      /**
73       * Encapsulates the strategy for re-establishing the connection to the
74       * server.
75       * 
76       * @param oldConnection
77       *            The connection that has become disconnected.
78       * @return The new connection to the server or null if a connection could
79       *         not be created.
80       */
81      Connection reconnect(Connection oldConnection);
82  }