Category delete throws cache exception
@@ -27,12 +27,12 @@ import com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver;
import com.thinkbiganalytics.feedmgr.rest.model.FeedCategory;
import com.thinkbiganalytics.metadata.api.MetadataAccess;
import com.thinkbiganalytics.metadata.api.category.Category;
-import com.thinkbiganalytics.metadata.api.event.category.CategoryChange;
-import com.thinkbiganalytics.metadata.api.event.category.CategoryChangeEvent;
import com.thinkbiganalytics.metadata.api.category.CategoryProvider;
import com.thinkbiganalytics.metadata.api.event.MetadataChange;
import com.thinkbiganalytics.metadata.api.event.MetadataEventListener;
import com.thinkbiganalytics.metadata.api.event.MetadataEventService;
+import com.thinkbiganalytics.metadata.api.event.category.CategoryChange;
+import com.thinkbiganalytics.metadata.api.event.category.CategoryChangeEvent;
import java.util.List;
import java.util.Map;
@@ -83,9 +83,6 @@ public class SimpleCategoryCache implements ClusterServiceMessageReceiver {
}
-
-
-
private LoadingCache<String, FeedCategory> categoryIdCache = CacheBuilder.newBuilder().build(new CacheLoader<String, FeedCategory>() {
@Override
public FeedCategory load(String id) throws Exception {
@@ -161,11 +158,24 @@ public class SimpleCategoryCache implements ClusterServiceMessageReceiver {
return categoryIdCache.asMap();
}
+ private void onCategoryChange(CategoryChange change) {
+ if (change != null) {
+ if (change.getChange() == MetadataChange.ChangeType.DELETE) {
+ categoryIdCache.invalidate(change.getCategoryId().toString());
+ if (change.getCategoryName().isPresent()) {
+ categoryNameCache.invalidate(change.getCategoryName().get());
+ }
+ } else {
+ categoryIdCache.refresh(change.getCategoryId().toString());
+ }
+ }
+ }
+
private class CategoryChangeListener implements MetadataEventListener<CategoryChangeEvent> {
public void notify(@Nonnull final CategoryChangeEvent metadataEvent) {
CategoryChange change = metadataEvent.getData();
- categoryIdCache.refresh(change.getCategoryId().toString());
+ onCategoryChange(change);
}
}
@@ -174,17 +184,7 @@ public class SimpleCategoryCache implements ClusterServiceMessageReceiver {
public void onMessageReceived(String from, ClusterMessage message) {
if (CategoryChange.CLUSTER_EVENT_TYPE.equals(message.getType())) {
CategoryChange change = (CategoryChange) message.getMessage();
- if(change != null){
- if(change.getChange() == MetadataChange.ChangeType.DELETE){
- categoryIdCache.invalidate(change.getCategoryId().toString());
- if(change.getCategoryName().isPresent()){
- categoryNameCache.invalidate(change.getCategoryName().get());
- }
- }
- else {
- categoryIdCache.refresh(change.getCategoryId().toString());
- }
- }
+ onCategoryChange(change);
}
}
}
