Changes API: How to subscribe to index changes?
Following methods allow you to subscribe to index changes:
ForIndex
Index changes for one index can be observed using forIndex
method.
Syntax
public IObservable<IndexChangeNotification> forIndex(String indexName);
Parameters | ||
---|---|---|
indexName | String | Name of an index for which notifications will be processed. |
Return value | |
---|---|
IObservable<IndexChangeNotification> | Observable that allows to add subscriptions to notifications for index with given name. |
Example
Closeable subscription = store.
changes().
forIndex("Orders/All")
.subscribe(Observers.create(new Action1<IndexChangeNotification>() {
@Override
public void apply(IndexChangeNotification change) {
switch (change.getType()) {
case INDEX_ADDED:
// do something
break;
case INDEX_DEMOTED_TO_ABANDONED:
// do something
break;
case INDEX_DEMOTED_TO_DISABLED:
// do something
break;
case INDEX_DEMOTED_TO_IDLE:
// do something
break;
case INDEX_MARKED_AS_ERRORED:
// do something
break;
case INDEX_PROMOTED_FROM_IDLE:
// do something
break;
case INDEX_REMOVED:
// do something
break;
case MAP_COMPLETED:
// do something
break;
case REDUCE_COMPLETED:
// do something
break;
case REMOVE_FROM_INDEX:
// do something
break;
default:
break;
}
}
}));
ForAllIndexes
Index changes for all indexes can be observed using forAllIndexes
method.
Return value | |
---|---|
IObservable<IndexChangeNotification> | Observable that allows to add subscriptions to notifications for all indexes. |
Syntax
public IObservable<IndexChangeNotification> forAllIndexes();
Example
Closeable subscription = store.
changes().
forAllIndexes()
.subscribe(Observers.create(new Action1<IndexChangeNotification>() {
@Override
public void apply(IndexChangeNotification change) {
System.out.println(change.getType() + " on index " + change.getName());
}
}));