use of org.opencastproject.message.broker.api.index.IndexRecreateObject in project opencast by opencast.
the class AbstractSearchIndex method recreateService.
/**
* Ask for data to be rebuilt from a service.
*
* @param service
* The {@link IndexRecreateObject.Service} representing the service to start re-sending the data from.
* @throws IndexServiceException
* Thrown if there is a problem re-sending the data from the service.
* @throws InterruptedException
* Thrown if the process of re-sending the data is interupted.
* @throws CancellationException
* Thrown if listening to messages has been canceled.
* @throws ExecutionException
* Thrown if the process of re-sending the data has an error.
*/
private void recreateService(IndexRecreateObject.Service service) throws IndexServiceException, InterruptedException, CancellationException, ExecutionException {
logger.info("Starting to recreate index for service '{}'", service);
messageSender.sendObjectMessage(IndexProducer.RECEIVER_QUEUE + "." + service, MessageSender.DestinationType.Queue, IndexRecreateObject.start(getIndexName(), service));
boolean done = false;
// TODO Add a timeout for services that are not going to respond.
while (!done) {
FutureTask<Serializable> future = messageReceiver.receiveSerializable(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue);
executor.execute(future);
BaseMessage message = (BaseMessage) future.get();
if (message.getObject() instanceof IndexRecreateObject) {
IndexRecreateObject indexRecreateObject = (IndexRecreateObject) message.getObject();
switch(indexRecreateObject.getStatus()) {
case Update:
logger.info("Updating service: '{}' with {}/{} finished, {}% complete.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal(), (int) (indexRecreateObject.getCurrent() * 100 / indexRecreateObject.getTotal()));
if (indexRecreateObject.getCurrent() == indexRecreateObject.getTotal()) {
logger.info("Waiting for service '{}' indexing to complete", indexRecreateObject.getService());
}
break;
case End:
done = true;
logger.info("Finished re-creating data for service '{}'", indexRecreateObject.getService());
break;
case Error:
logger.error("Error updating service '{}' with {}/{} finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal());
throw new IndexServiceException(format("Error updating service '%s' with %s/%s finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal()));
default:
logger.error("Unable to handle the status '{}' for service '{}'", indexRecreateObject.getStatus(), indexRecreateObject.getService());
throw new IllegalArgumentException(format("Unable to handle the status '%s' for service '%s'", indexRecreateObject.getStatus(), indexRecreateObject.getService()));
}
}
}
}
Aggregations