001package org.apache.commons.jcs3.auxiliary.remote; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheMonitor; 023 024/** 025 * The RemoteCacheFailoverRunner tries to establish a connection with a failover 026 * server, if any are defined. Once a failover connection is made, it will 027 * attempt to replace the failover with the primary remote server. 028 * <p> 029 * It works by switching out the RemoteCacheNoWait inside the Facade. 030 * <p> 031 * Client (i.e.) the CompositeCache has reference to a RemoteCacheNoWaitFacade. 032 * This facade is created by the RemoteCacheFactory. The factory maintains a set 033 * of managers, one for each remote server. Typically, there will only be one 034 * manager. 035 * <p> 036 * If you use multiple remote servers, you may want to set one or more as 037 * failovers. If a local cache cannot connect to the primary server, or looses 038 * its connection to the primary server, it will attempt to restore that 039 * Connection in the background. If failovers are defined, the Failover runner 040 * will try to connect to a failover until the primary is restored. 041 * 042 * @deprecated Functionality moved to RemoteCacheNoWaitFacade 043 */ 044@Deprecated 045public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonitor 046{ 047 /** The facade returned to the composite cache. */ 048 private final RemoteCacheNoWaitFacade<K, V> facade; 049 050 /** 051 * Constructor for the RemoteCacheFailoverRunner object. This allows the 052 * FailoverRunner to modify the facade that the CompositeCache references. 053 * 054 * @param facade the facade the CompositeCache talks to. 055 * @param cacheFactory the cache factory instance 056 */ 057 public RemoteCacheFailoverRunner( final RemoteCacheNoWaitFacade<K, V> facade, final RemoteCacheFactory cacheFactory ) 058 { 059 super("JCS-RemoteCacheFailoverRunner"); 060 this.facade = facade; 061 setIdlePeriod(20000L); 062 } 063 064 /** 065 * Clean up all resources before shutdown 066 */ 067 @Override 068 protected void dispose() 069 { 070 // empty 071 } 072 073 /** 074 * do actual work 075 */ 076 @Override 077 protected void doWork() 078 { 079 // empty 080 } 081 082 083 /** 084 * Main processing method for the RemoteCacheFailoverRunner object. 085 * <p> 086 * If we do not have a connection with any failover server, this will try to 087 * connect one at a time. If no connection can be made, it goes to sleep for 088 * a while (20 seconds). 089 * <p> 090 * Once a connection with a failover is made, we will try to reconnect to 091 * the primary server. 092 * <p> 093 * The primary server is the first server defines in the FailoverServers 094 * list. 095 */ 096 @Override 097 public void run() 098 { 099 // start the main work of connecting to a failover and then restoring 100 // the primary. 101 facade.connectAndRestore(); 102 } 103 104}