}
@Override
public boolean unavailable(String resource) {
for(String indexName : managedCores.getIndexNames(resource)){
IndexMetadata metadata = managedCores.getIndexMetadata(indexName);
if(metadata != null){ //may be removed in the meantime
String currentArchive = metadata.getArchive();
boolean inSync = metadata.isSynchronized();
if(resource.equals(currentArchive)){ //current archive may be null
currentArchive = null; //reset the current archive to null (none)
ArchiveInputStream ais = null;
for(String archive : metadata.getIndexArchives()){
if(!archive.equals(resource)) {
if(currentArchive == null){
try {
InputStream is = provider.getInputStream(null, archive, null);
if(is != null){
ais = ManagementUtils.getArchiveInputStream(archive, is);
} else {
ais = null;
}
} catch (IOException e) {
//not available
ais = null;
} catch (ArchiveException e) {
log.error("Unable to open ArchiveInputStream for Resource '"+
archive+"'!",e);
ais = null;
}
if(ais != null){ //ais != null also
currentArchive = archive; //currentArchive != null
}
}
//if resource become unavailable we might need to
//add resources for tracking
if(!tracker.isTracked(this, null, archive) && //if not already tracked
(currentArchive == null || ( //and no archive found
currentArchive != null && inSync))){ //or found but inSync
tracker.add(this, archive,
IndexMetadata.toStringMap(metadata));
} // else already tracked or no tracking needed
}
}
//If we have now a currentArchive and an ais we can
//switch to an alternate archive.
//If not we need to switch this in index in the UNAVAILABLE
// state
metadata.setArchive(currentArchive);//update the metadata
managedCores.store(metadata);
//if the parsed ais is NULL the index will be uninitialised
indexUpdateDaemon.update(
currentArchive == null ? ManagedIndexState.UNINITIALISED :
ManagedIndexState.ACTIVE,