use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.
the class CSVRecordLookupService method onEnabled.
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException {
this.csvFile = context.getProperty(CSV_FILE).getValue();
this.csvFormat = CSVFormat.Predefined.valueOf(context.getProperty(CSV_FORMAT).getValue()).getFormat();
this.lookupKeyColumn = context.getProperty(LOOKUP_KEY_COLUMN).getValue();
this.ignoreDuplicates = context.getProperty(IGNORE_DUPLICATES).asBoolean();
this.watcher = new SynchronousFileWatcher(Paths.get(csvFile), new LastModifiedMonitor(), 30000L);
try {
loadCache();
} catch (final IllegalStateException e) {
throw new InitializationException(e.getMessage(), e);
}
}
use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.
the class SimpleCsvFileLookupService method onEnabled.
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, FileNotFoundException {
this.csvFile = context.getProperty(CSV_FILE).getValue();
this.csvFormat = CSVFormat.Predefined.valueOf(context.getProperty(CSV_FORMAT).getValue()).getFormat();
this.lookupKeyColumn = context.getProperty(LOOKUP_KEY_COLUMN).getValue();
this.lookupValueColumn = context.getProperty(LOOKUP_VALUE_COLUMN).getValue();
this.ignoreDuplicates = context.getProperty(IGNORE_DUPLICATES).asBoolean();
this.watcher = new SynchronousFileWatcher(Paths.get(csvFile), new LastModifiedMonitor(), 30000L);
try {
loadCache();
} catch (final IllegalStateException e) {
throw new InitializationException(e.getMessage(), e);
}
}
use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.
the class CommonsConfigurationLookupService method onEnabled.
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
final String config = context.getProperty(CONFIGURATION_FILE).getValue();
final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config));
this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params);
builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<ConfigurationBuilderEvent>() {
@Override
public void onEvent(ConfigurationBuilderEvent event) {
if (builder.getReloadingController().checkForReloading(null)) {
getLogger().debug("Reloading " + config);
}
}
});
try {
// Try getting configuration to see if there is any issue, for example wrong file format.
// Then throw InitializationException to keep this service in 'Enabling' state.
builder.getConfiguration();
} catch (ConfigurationException e) {
throw new InitializationException(e);
}
}
use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.
the class IPLookupService method onEnabled.
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws IOException {
databaseFile = context.getProperty(GEO_DATABASE_FILE).evaluateAttributeExpressions().getValue();
final File dbFile = new File(databaseFile);
final String dbFileChecksum = getChecksum(dbFile);
loadDatabase(dbFile, dbFileChecksum);
// initialize the last refresh attempt to the time the service was enabled
databaseLastRefreshAttempt = System.currentTimeMillis();
}
use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.
the class SchemaRegistryService method storeSchemaAccessStrategy.
@OnEnabled
public void storeSchemaAccessStrategy(final ConfigurationContext context) {
this.configurationContext = context;
final SchemaRegistry schemaRegistry = context.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class);
final PropertyDescriptor descriptor = getSchemaAcessStrategyDescriptor();
final String schemaAccess = context.getProperty(descriptor).getValue();
this.schemaAccessStrategy = getSchemaAccessStrategy(schemaAccess, schemaRegistry, context);
}
Aggregations