View Javadoc
1   package org.apache.commons.jcs3.auxiliary.remote;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheMonitor;
23  
24  /**
25   * The RemoteCacheFailoverRunner tries to establish a connection with a failover
26   * server, if any are defined. Once a failover connection is made, it will
27   * attempt to replace the failover with the primary remote server.
28   * <p>
29   * It works by switching out the RemoteCacheNoWait inside the Facade.
30   * <p>
31   * Client (i.e.) the CompositeCache has reference to a RemoteCacheNoWaitFacade.
32   * This facade is created by the RemoteCacheFactory. The factory maintains a set
33   * of managers, one for each remote server. Typically, there will only be one
34   * manager.
35   * <p>
36   * If you use multiple remote servers, you may want to set one or more as
37   * failovers. If a local cache cannot connect to the primary server, or looses
38   * its connection to the primary server, it will attempt to restore that
39   * Connection in the background. If failovers are defined, the Failover runner
40   * will try to connect to a failover until the primary is restored.
41   *
42   * @deprecated Functionality moved to RemoteCacheNoWaitFacade
43   */
44  @Deprecated
45  public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonitor
46  {
47      /** The facade returned to the composite cache. */
48      private final RemoteCacheNoWaitFacade<K, V> facade;
49  
50      /**
51       * Constructor for the RemoteCacheFailoverRunner object. This allows the
52       * FailoverRunner to modify the facade that the CompositeCache references.
53       *
54       * @param facade the facade the CompositeCache talks to.
55       * @param cacheFactory the cache factory instance
56       */
57      public RemoteCacheFailoverRunner( final RemoteCacheNoWaitFacade<K, V> facade, final RemoteCacheFactory cacheFactory )
58      {
59          super("JCS-RemoteCacheFailoverRunner");
60          this.facade = facade;
61          setIdlePeriod(20000L);
62      }
63  
64      /**
65       * Clean up all resources before shutdown
66       */
67      @Override
68      protected void dispose()
69      {
70          // empty
71      }
72  
73      /**
74       * do actual work
75       */
76      @Override
77      protected void doWork()
78      {
79          // empty
80      }
81  
82  
83      /**
84       * Main processing method for the RemoteCacheFailoverRunner object.
85       * <p>
86       * If we do not have a connection with any failover server, this will try to
87       * connect one at a time. If no connection can be made, it goes to sleep for
88       * a while (20 seconds).
89       * <p>
90       * Once a connection with a failover is made, we will try to reconnect to
91       * the primary server.
92       * <p>
93       * The primary server is the first server defines in the FailoverServers
94       * list.
95       */
96      @Override
97      public void run()
98      {
99          // start the main work of connecting to a failover and then restoring
100         // the primary.
101         facade.connectAndRestore();
102     }
103 
104 }