use of org.apache.asterix.lang.common.statement.StopFeedStatement in project asterixdb by apache.
the class QueryTranslator method handleStopFeedStatement.
private void handleStopFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
StopFeedStatement sfst = (StopFeedStatement) stmt;
String dataverseName = getActiveDataverse(sfst.getDataverseName());
String feedName = sfst.getFeedName().getValue();
EntityId feedId = new EntityId(Feed.EXTENSION_NAME, dataverseName, feedName);
ActiveLifecycleListener activeListener = (ActiveLifecycleListener) appCtx.getActiveLifecycleListener();
ActiveJobNotificationHandler activeEventHandler = activeListener.getNotificationHandler();
// Obtain runtime info from ActiveListener
FeedEventsListener listener = (FeedEventsListener) activeEventHandler.getActiveEntityListener(feedId);
if (listener == null) {
throw new AlgebricksException("Feed " + feedName + " is not started.");
}
IActiveEventSubscriber eventSubscriber = listener.subscribe(ActivityState.STOPPED);
// Transaction
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.stopFeedBegin(metadataProvider.getLocks(), dataverseName, feedName);
try {
// validate
FeedMetadataUtil.validateIfFeedExists(dataverseName, feedName, mdTxnCtx);
// Construct ActiveMessage
for (int i = 0; i < listener.getSources().length; i++) {
String intakeLocation = listener.getSources()[i];
FeedOperations.SendStopMessageToNode(appCtx, feedId, intakeLocation, i);
}
eventSubscriber.sync();
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
Aggregations