Changes API: How to subscribe to bulk insert operation changes?
forBulkInsert
method can be used to acquire notifications for bulk insert operations.
Syntax
public IObservable<BulkInsertChangeNotification> forBulkInsert(UUID operationId);
Parameters |
|
|
operationId |
UUID |
Id of bulk insert operation, generated when bulk insert operation is created. |
ReturnValue |
|
IObservable<BulkInsertChangeNotification> |
Observable that allows to add subscriptions to notifications for bulk insert operation with given id. |
Example
try (BulkInsertOperation bulkInsert = store.bulkInsert()) {
Closeable subscription = store
.changes()
.forBulkInsert(bulkInsert.getOperationId())
.subscribe(Observers.create(new Action1<BulkInsertChangeNotification>() {
@Override
public void apply(BulkInsertChangeNotification change) {
switch (change.getType()) {
case BULK_INSERT_STARTED:
// do something
break;
case BULK_INSERT_ENDED:
// do something
break;
case BULK_INSERT_ERROR:
// do something
break;
default:
break;
}
}
}));
try {
for (int i = 0; i < 1000 * 1000; i++) {
Employee employee = new Employee();
employee.setFirstName("FirstName #" + i);
employee.setLastName("LastName #" + i);
bulkInsert.store(employee);
}
} finally {
if (subscription != null) {
subscription.close();
}
}
}