public static Worker createWorker(SearchConfiguration cfg,
SearchFactoryImplementor searchFactoryImplementor) {
Properties props = getProperties( cfg );
String impl = props.getProperty( Environment.WORKER_SCOPE );
Worker worker;
if ( StringHelper.isEmpty( impl ) ) {
worker = new TransactionalWorker();
}
else if ( "transaction".equalsIgnoreCase( impl ) ) {
worker = new TransactionalWorker();
}
else {
try {
Class workerClass = ReflectHelper.classForName( impl, WorkerFactory.class );
worker = (Worker) workerClass.newInstance();
}
catch (ClassNotFoundException e) {
throw new SearchException( "Unable to find worker class: " + impl, e );
}
catch (IllegalAccessException e) {
throw new SearchException( "Unable to instanciate worker class: " + impl, e );
}
catch (InstantiationException e) {
throw new SearchException( "Unable to instanciate worker class: " + impl, e );
}
}
worker.initialize( props, searchFactoryImplementor );
return worker;
}
|