use of nl.uva.cs.lobcder.catalogue.beans.ItemBean in project lobcder by skoulouzis.
the class ReplicateSweep method run.
@Override
public void run() {
try {
Collection<PdriGroupBean> pdriGroupBeanCollection = connector.selectPdriGroupsToRelocate(localCacheId);
if (pdriGroupBeanCollection != null) {
for (PdriGroupBean pdriGroupBean : pdriGroupBeanCollection) {
try {
Set<StorageSiteBean> preferences = new HashSet<>();
if (pdriGroupBean.getItem() != null) {
for (ItemBean itemBean : pdriGroupBean.getItem()) {
Collection<StorageSiteBean> itemPreferences = itemBean.getPreference();
if (itemPreferences != null)
preferences.addAll(itemPreferences);
}
}
Set<StorageSiteBean> toReplicate = new HashSet<>(preferences);
Set<PdriBean> wantRemove = new HashSet<>();
Set<StorageSiteBean> removingStorage = connector.getRemovingStorage();
Set<PdriBean> noCache = new HashSet<>();
Set<PdriBean> remoteCache = new HashSet<>();
if (pdriGroupBean.getPdri() != null) {
for (PdriBean pdriBean : pdriGroupBean.getPdri()) {
if (isLocalCachePdri(pdriBean)) {
wantRemove.add(pdriBean);
} else {
if (pdriBean.getStorage().getCache()) {
remoteCache.add(pdriBean);
} else {
if (preferences.isEmpty()) {
if (removingStorage.contains(pdriBean.getStorage())) {
wantRemove.add(pdriBean);
} else {
noCache.add(pdriBean);
}
} else {
if (preferences.contains(pdriBean.getStorage())) {
toReplicate.remove(pdriBean.getStorage());
} else {
wantRemove.add(pdriBean);
}
}
}
}
}
}
if (preferences.isEmpty()) {
if (noCache.isEmpty()) {
replicate(pdriGroupBean, replicationPolicy.getSitesToReplicate());
}
} else {
replicate(pdriGroupBean, toReplicate);
}
removePdris(wantRemove);
if (remoteCache.isEmpty()) {
connector.reportPdriGroupDone(pdriGroupBean);
} else {
connector.reportPdriGroupRelease(pdriGroupBean);
}
} catch (Exception e) {
Logger.getLogger(ReplicateSweep.class.getName()).log(Level.SEVERE, null, e);
connector.reportPdriGroupRelease(pdriGroupBean);
}
}
}
} catch (Exception e) {
Logger.getLogger(ReplicateSweep.class.getName()).log(Level.SEVERE, null, e);
}
}
Aggregations