private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
@Override public void flushToIndexes() { ExtendedSearchIntegrator extendedIntegrator = getSearchIntegrator(); extendedIntegrator.getWorker().flushWorks( transactionContext ); }
public static Worker createWorker(SearchConfiguration searchConfiguration, WorkerBuildContext buildContext, QueueingProcessor queueingProcessor) { Properties properties = getProperties( searchConfiguration ); String workerImplClassName = properties.getProperty( Environment.WORKER_SCOPE ); Worker worker; if ( StringHelper.isEmpty( workerImplClassName ) || "transaction".equalsIgnoreCase( workerImplClassName ) ) { worker = new PerTransactionWorker(); } else { worker = instantiateExplicitlyConfiguredWorker( buildContext, workerImplClassName ); } worker.initialize( properties, buildContext, queueingProcessor ); return worker; }
@Test public void canDeleteByQuery() throws Exception { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); ExtendedSearchIntegrator integrator = session.getSearchFactory() .unwrap( ExtendedSearchIntegrator.class ); DeleteByQueryWork queryWork = new DeleteByQueryWork( new PojoIndexedTypeIdentifier( HockeyPlayer.class ), new SingularTermDeletionQuery( "active", "false" ) ); TransactionContext tc = new TransactionContextForTest(); integrator.getWorker().performWork( queryWork, tc ); integrator.getWorker().flushWorks( tc ); QueryDescriptor query = ElasticsearchQueries.fromJson( "{ 'query': { 'match_all' : {} } }" ); Transaction tx = s.beginTransaction(); @SuppressWarnings("unchecked") List<HockeyPlayer> result = session.createFullTextQuery( query, HockeyPlayer.class ).list(); assertThat( result ).extracting( "name" ).containsExactlyInAnyOrder( "Hergesheimer", "Brand" ); tx.commit(); s.close(); }
@Override public void close() { if ( stopped.compareAndSet( false, true ) ) { //make sure we only stop once try ( Closer<RuntimeException> closer = new Closer<>() ) { closer.push( () -> { try { worker.close(); } catch (Exception e) { log.workerException( e ); } } ); closer.push( allIndexesManager::stop ); closer.push( timingSource::stop ); if ( workSerializer != null ) { closer.push( serviceManager::releaseService, LuceneWorkSerializer.class ); } // Execute this before closing the service manager to allow integrations to release services closer.pushAll( SearchIntegration::close, this.integrations.values() ); closer.push( serviceManager::releaseAllServices ); // unregister statistic mbean if ( statisticsMBeanName != null ) { closer.push( JMXRegistrar::unRegisterMBean, statisticsMBeanName ); } } } }
integrator.getWorker().performWork( queryWork, tc ); integrator.getWorker().flushWorks( tc );
@Override public void close() { if ( stopped.compareAndSet( false, true ) ) { //make sure we only stop once try ( Closer<RuntimeException> closer = new Closer<>() ) { closer.push( () -> { try { worker.close(); } catch (Exception e) { log.workerException( e ); } } ); closer.push( allIndexesManager::stop ); closer.push( timingSource::stop ); if ( workSerializer != null ) { closer.push( serviceManager::releaseService, LuceneWorkSerializer.class ); } closer.push( serviceManager::releaseAllServices ); closer.pushAll( SearchIntegration::close, this.integrations.values() ); // unregister statistic mbean if ( statisticsMBeanName != null ) { closer.push( JMXRegistrar::unRegisterMBean, statisticsMBeanName ); } } } }
private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
public static Worker createWorker(SearchConfiguration searchConfiguration, WorkerBuildContext buildContext, QueueingProcessor queueingProcessor) { Properties properties = getProperties( searchConfiguration ); String workerImplClassName = properties.getProperty( Environment.WORKER_SCOPE ); Worker worker; if ( StringHelper.isEmpty( workerImplClassName ) || "transaction".equalsIgnoreCase( workerImplClassName ) ) { worker = new PerTransactionWorker(); } else { worker = instantiateExplicitlyConfiguredWorker( buildContext, workerImplClassName ); } worker.initialize( properties, buildContext, queueingProcessor ); return worker; }
protected static void updateIndex(TransactionContext context, Collection<DomainObject> objects, WorkType workType) { try { for (DomainObject obj : objects) { if (!INDEXED_CLASSES.contains(obj.getClass())) continue; searchFactory.getWorker().performWork(new Work<DomainObject>(obj, workType), context); } } catch (RuntimeException e) { logger.warn("Problem inside updateIndex", e); throw e; } }
@Override public void accept(int id) { AbstractBookEntity book = dataset.create( id ); Work work = new Work( book, id, WorkType.ADD, false ); worker.performWork( work, tc ); needsFlush = true; ++count; if ( count % 1000 == 0 ) { //commit in batches of 1000: flush(); } }
private void createAndPerformWork(IndexedTypeIdentifier type, Serializable id, WorkType workType) { Work work = new Work( delegate.getTenantIdentifier(), type, id, workType ); getSearchIntegrator().getWorker().performWork( work, transactionContext ); }
public void execute() { TransactionContextForTest tc = new TransactionContextForTest(); works.forEach( w -> integratorProvider.get().getWorker().performWork( w, tc ) ); tc.end(); works.clear(); } }
protected void processWork(String tenantIdentifier, Object entity, Serializable id, WorkType workType, AbstractEvent event, boolean identifierRollbackEnabled) { Work work = new Work( tenantIdentifier, entity, id, workType, identifierRollbackEnabled ); final EventSourceTransactionContext transactionContext = new EventSourceTransactionContext( event.getSession() ); getExtendedSearchFactoryIntegrator().getWorker().performWork( work, transactionContext ); }
@Benchmark @Threads(3 * AbstractBookEntity.TYPE_COUNT) public void write(NonStreamWriteEngineHolder eh, ChangesetGenerator changesetGenerator, NonStreamWriteCounters counters) { SearchIntegrator si = eh.getSearchIntegrator(); Worker worker = si.getWorker(); IndexedTypeIdentifier typeId = changesetGenerator.getTypeId(); changesetGenerator.stream().forEach( changeset -> { TransactionContextForTest tc = new TransactionContextForTest(); changeset.toAdd().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.ADD ); worker.performWork( work, tc ); } ); changeset.toUpdate().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.UPDATE ); worker.performWork( work, tc ); } ); changeset.toDelete().forEach( id -> { Work work = new Work( typeId, id, WorkType.DELETE ); worker.performWork( work, tc ); } ); tc.end(); ++counters.changeset; } ); // Ensure that we'll block until all works have been performed SearchIntegratorHelper.flush( si, typeId ); }
worker.performWork( work, transactionContext );
@Override public void run() { for ( int i = 1; i <= docsPerThread; i++ ) { final Worker worker = integrator.getWorker(); Work work = workLog.generateNewWork(); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); workLog.workApplied( work ); tc.end(); if ( i % printEach == 0 ) { System.out.println( Thread.currentThread().getName() + " sent " + i ); } } } }
private void storeObject(Object entity, Serializable id) { Work work = new Work( entity, id, WorkType.UPDATE, false ); TransactionContextForTest tc = new TransactionContextForTest(); searchIntegrator.getWorker().performWork( work, tc ); tc.end(); }
private static void writeABook(Integer id, String bookTitle, Worker worker) { Book book = new Book(); book.id = id; book.title = bookTitle; Work work = new Work( book, book.id, WorkType.ADD, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private static void deleteABook(Integer id, Worker worker) { Book book = new Book(); book.id = id; Work work = new Work( book, id, WorkType.DELETE, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }