| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 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 | |
|
| 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 | |
} |