Coverage Report - fr.fastconnect.gigaspaces.datasource.strategy.SpaceStorageExecutionFailureStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
SpaceStorageExecutionFailureStrategy
0%
0/32
0%
0/14
0
 
 1  
 /*
 2  
  * Copyright 2008 fastConnect.
 3  
  *    
 4  
  * This file is part of Composite BulkDataPersister.  
 5  
  *
 6  
  * This is free software; you can redistribute it and/or modify it
 7  
  * under the terms of the GNU Lesser General Public License as
 8  
  * published by the Free Software Foundation; either version 3 of
 9  
  * the License, or (at your option) any later version.
 10  
  *
 11  
  * This software is distributed in the hope that it will be useful,
 12  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14  
  * Lesser General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU Lesser General Public
 17  
  * License along with this software. If not, see <http://www.gnu.org/licenses/>.
 18  
  */
 19  
 package fr.fastconnect.gigaspaces.datasource.strategy;
 20  
 
 21  
 import java.util.List;
 22  
 import java.util.Properties;
 23  
 import java.util.logging.Level;
 24  
 import java.util.logging.Logger;
 25  
 
 26  
 import net.jini.core.lease.Lease;
 27  
 
 28  
 import com.gigaspaces.datasource.BulkDataPersister;
 29  
 import com.gigaspaces.datasource.BulkItem;
 30  
 import com.gigaspaces.datasource.DataSourceException;
 31  
 import com.j_spaces.core.IJSpace;
 32  
 import com.j_spaces.core.client.FinderException;
 33  
 import com.j_spaces.core.client.SpaceFinder;
 34  
 
 35  
 import fr.fastconnect.gigaspaces.datasource.ExecutionFailureStrategy;
 36  
 
 37  
 /**
 38  
  * Use a space to store data.
 39  
  * <br />
 40  
  * Space is defined by a URL configured through {@value SpaceStorageExecutionFailureStrategy#SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY}SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY.
 41  
  * If undefined then {@link SpaceStorageExecutionFailureStrategy#init(Properties)} will throw a {@link DataSourceException}.
 42  
  * <br />
 43  
  * If underlying {@link SpaceFinder#find(String)} throws an exception then {@link SpaceStorageExecutionFailureStrategy#init(Properties)} will throw a {@link DataSourceException}.
 44  
  */
 45  
 public class SpaceStorageExecutionFailureStrategy implements ExecutionFailureStrategy {
 46  
         
 47  0
         private final static Logger LOGGER = Logger.getLogger(SpaceStorageExecutionFailureStrategy.class.getName());
 48  
         
 49  
         public static final String SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY = "spacestorage-executionexceptionstrategy-url";
 50  
         
 51  
         private IJSpace proxy;
 52  
         
 53  0
         public SpaceStorageExecutionFailureStrategy() {
 54  0
         }
 55  
         
 56  0
         public SpaceStorageExecutionFailureStrategy(final IJSpace proxy) {
 57  0
                 this.proxy = proxy;
 58  0
         }
 59  
         
 60  
         /** 
 61  
          * {@inheritDoc}
 62  
          */
 63  
         public void init(final Properties properties) throws DataSourceException {
 64  0
                 if (this.proxy != null) {
 65  0
                         final String url = properties.getProperty(SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY);
 66  0
                         if (url != null) {
 67  0
                                 if (SpaceStorageExecutionFailureStrategy.LOGGER.isLoggable(Level.FINE)) {
 68  0
                                         SpaceStorageExecutionFailureStrategy.LOGGER.fine("Using <"+url+"> as "+SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY);
 69  
                                 }
 70  
                                 
 71  
                                 try {
 72  0
                                         this.proxy = IJSpace.class.cast(SpaceFinder.find(url));
 73  0
                                 } catch(FinderException e) {
 74  0
                                         final String message = "Cannot find Space using URL <"+url+">";
 75  0
                                         if (SpaceStorageExecutionFailureStrategy.LOGGER.isLoggable(Level.SEVERE)) {
 76  0
                                                 SpaceStorageExecutionFailureStrategy.LOGGER.log(Level.SEVERE, message, e);
 77  
                                         }
 78  0
                                         throw new DataSourceException(message, e);
 79  0
                                 }
 80  
                         } else {
 81  0
                                 final String message = "No "+SPACE_STORAGE_EXECUTION_EXCEPTION_STRATEGY_URL_PROPERTY+" defined";
 82  0
                                 if (SpaceStorageExecutionFailureStrategy.LOGGER.isLoggable(Level.SEVERE)) {
 83  0
                                         SpaceStorageExecutionFailureStrategy.LOGGER.log(Level.SEVERE, message);
 84  
                                 }
 85  0
                                 throw new DataSourceException(message);
 86  
                         }
 87  0
                 } else {
 88  0
                         if (SpaceStorageExecutionFailureStrategy.LOGGER.isLoggable(Level.CONFIG)) {
 89  0
                                 SpaceStorageExecutionFailureStrategy.LOGGER.log(Level.CONFIG, SpaceStorageExecutionFailureStrategy.class.getSimpleName()+" configured manually; ignoring properties");
 90  
                         }
 91  
                 }
 92  
                 
 93  0
                 if (SpaceStorageExecutionFailureStrategy.LOGGER.isLoggable(Level.CONFIG)) {
 94  0
                         SpaceStorageExecutionFailureStrategy.LOGGER.log(Level.CONFIG, "Using proxy <"+this.proxy+">");
 95  
                 }
 96  0
         }
 97  
         
 98  
         public void handleExecutionFailure(final BulkDataPersister bulkDataPersister, final List<BulkItem> bulkItems, final DataSourceException exception) throws Exception {
 99  0
                 this.proxy.write(new SpaceStorageExecutionFailure(bulkDataPersister.getClass().getName(), bulkItems, exception), null, Lease.FOREVER);
 100  0
         }
 101  
         
 102  
         public void setSpace(final IJSpace space) {
 103  0
                 this.proxy = space;
 104  0
         }
 105  
 
 106  
 }