org.hibernate.search.backend.spi.Worker类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中org.hibernate.search.backend.spi.Worker类的一些代码示例,展示了Worker类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Worker类的具体详情如下:
包路径:org.hibernate.search.backend.spi.Worker
类名称:Worker

Worker介绍

[英]Perform work for a given context (eg a transaction). This implementation has to be threaded-safe.
[中]为给定的上下文(如事务)执行工作。这个实现必须是线程安全的。

代码示例

代码示例来源:origin: org.infinispan/infinispan-query

private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) {
 Worker worker = searchFactory.getWorker();
 for (Work work : works) {
   worker.performWork(work, transactionContext);
 }
}

代码示例来源:origin: hibernate/hibernate-search

@Override
public void flushToIndexes() {
  ExtendedSearchIntegrator extendedIntegrator = getSearchIntegrator();
  extendedIntegrator.getWorker().flushWorks( transactionContext );
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

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;
}

代码示例来源:origin: hibernate/hibernate-search

@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();
}

代码示例来源:origin: hibernate/hibernate-search

@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 );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-search

integrator.getWorker().performWork( queryWork, tc );
integrator.getWorker().flushWorks( tc );

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@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 );
      }
    }
  }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) {
 Worker worker = searchFactory.getWorker();
 for (Work work : works) {
   worker.performWork(work, transactionContext);
 }
}

代码示例来源:origin: hibernate/hibernate-search

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;
}

代码示例来源:origin: fenix-framework/fenix-framework

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;
  }
}

代码示例来源:origin: hibernate/hibernate-search

@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();
  }
}

代码示例来源:origin: hibernate/hibernate-search

private void createAndPerformWork(IndexedTypeIdentifier type, Serializable id, WorkType workType) {
  Work work = new Work( delegate.getTenantIdentifier(), type, id, workType );
  getSearchIntegrator().getWorker().performWork( work, transactionContext );
}

代码示例来源:origin: hibernate/hibernate-search

public void execute() {
    TransactionContextForTest tc = new TransactionContextForTest();
    works.forEach(
        w -> integratorProvider.get().getWorker().performWork( w, tc )
    );
    tc.end();
    works.clear();
  }
}

代码示例来源:origin: hibernate/hibernate-search

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 );
}

代码示例来源:origin: hibernate/hibernate-search

@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 );
}

代码示例来源:origin: hibernate/hibernate-search

worker.performWork( work, transactionContext );

代码示例来源:origin: hibernate/hibernate-search

@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 );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

相关文章