/** * This method retrieves the DocumentWorkerConfiguration or throws an exception. * * @return the DocumentWorkerConfiguration object * @throws WorkerException if there is a problem creating the configuration object */ @Nonnull private static DocumentWorkerConfiguration getConfiguration(final ConfigurationSource configSource) throws WorkerException { try { return configSource.getConfiguration(DocumentWorkerConfiguration.class); } catch (final ConfigurationException ce) { throw new WorkerException("Failed to construct DocumentWorkerConfiguration object", ce); } }
/** * Instantiates a new DefaultWorkerFactory. * * @param configSource the worker configuration source * @param dataStore the external data store * @param codec the codec used in serialisation * @param configurationClass the worker configuration class * @param taskClass the worker task class * @throws WorkerException if the factory cannot be instantiated */ public AbstractWorkerFactory(final ConfigurationSource configSource, final DataStore dataStore, final Codec codec, final Class<C> configurationClass, final Class<T> taskClass) throws WorkerException { this.codec = Objects.requireNonNull(codec); this.taskClass = Objects.requireNonNull(taskClass); this.dataStore = Objects.requireNonNull(dataStore); try { this.configuration = configSource.getConfiguration(configurationClass); } catch (ConfigurationException e) { throw new WorkerException("Failed to create worker factory", e); } }
public WorkerFactory getWorkerFactory(ConfigurationSource config, DataStore dataStore, Codec codec) throws WorkerException { { try { Objects.requireNonNull(config); PolicyWorkerConfiguration testConfig = config.getConfiguration(PolicyWorkerConfiguration.class); return new PolicyWorkerFactory(codec, dataStore, testConfig); } catch ( ConfigurationException e ) { throw new WorkerException("Failed to create factory", e); } } }
@Override public WorkerFactory getWorkerFactory(final ConfigurationSource configSource, final DataStore dataStore, final Codec codec) throws WorkerException { // Construct the application object final ApplicationImpl application = new ApplicationImpl(configSource, dataStore, codec); // Construct the DocumentWorker implementation object final DocumentWorker documentWorker = createDocumentWorker(application); if (documentWorker == null) { throw new WorkerException("The DocumentWorker instance could not be constructed. " + "Check that the implementation JARs are on the classpath."); } // Construct the appropriate type of adapter depending on whether the implementation support processing documents in bulk if (documentWorker instanceof BulkDocumentWorker) { return new BulkDocumentWorkerAdapter(application, (BulkDocumentWorker) documentWorker); } else { return new DocumentWorkerAdapter(application, documentWorker); } }