Tabnine Logo
Closer
Code IndexAdd Tabnine to your IDE (free)

How to use
Closer
in
org.hibernate.search.util.impl.common

Best Java code snippets using org.hibernate.search.util.impl.common.Closer (Showing top 20 results out of 315)

origin: hibernate/hibernate-search

@Override
protected void doClose() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ElasticsearchBatchingSharedWorkOrchestrator::awaitCompletionBeforeClose, this );
    closer.push( ExecutorService::shutdownNow, executor );
    //It's possible that a task was successfully scheduled but had no chance to run,
    //so we need to release waiting threads:
    closer.push( Phaser::forceTermination, phaser );
  }
}
origin: hibernate/hibernate-search

@Override
void closeOnFailure() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.pushAll( ContainerExtractorHolder::close, extractorHolder );
    closer.pushAll(
        PojoIndexingProcessorValueNodeBuilderDelegate::closeOnFailure,
        valueNodeProcessorCollectionBuilder
    );
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ContainerExtractorHolder::close, extractorHolder );
    closer.pushAll( PojoIndexingProcessor::close, nestedNodes );
  }
}
origin: hibernate/hibernate-search

/**
 * @return A closer sharing the same state as {@code this}, allowing to handle
 * multiple exception types.
 * @see <a href="#splitting">splitting</a>
 */
public <E2 extends Exception> Closer<E2> split() {
  return new Closer<>( state );
}
origin: hibernate/hibernate-search

@Override
public void close() {
  if ( !closed ) {
    // Make sure to avoid infinite recursion when one of the delegates calls this.close()
    closed = true;
    try ( Closer<RuntimeException> closer = new Closer<>() ) {
      closer.push( PojoMappingDelegate::close, delegate );
      closer.pushAll( CloseDelegate::close, closeDelegates );
    }
  }
}
origin: hibernate/hibernate-search

void closeOnFailure() {
  if ( closed ) {
    return;
  }
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( PojoIndexingProcessorTypeNodeBuilder::closeOnFailure, processorBuilder );
    closer.push( PojoIdentityMappingCollectorImpl::closeOnFailure, identityMappingCollector );
    closer.push( PojoIndexingProcessor::close, preBuiltIndexingProcessor );
    closed = true;
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.pushAll( BeanHolder::close, chainElementBeanHolders );
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ContainerExtractorHolder::close, extractorHolder );
    closer.pushAll( PojoImplicitReindexingResolverNode::close, nestedNodes );
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( IdentifierMapping::close, identifierMapping );
    closer.push( RoutingKeyProvider::close, routingKeyProvider );
    closer.push( PojoIndexingProcessor::close, processor );
    closer.push( PojoImplicitReindexingResolver::close, reindexingResolver );
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.pushAll( PojoImplicitReindexingResolverNode::close, nestedNodes );
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ContainerExtractorHolder::close, extractorHolder );
    closer.pushAll( PojoImplicitReindexingResolverNode::close, nestedNodes );
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( IdentifierMapping::close, identifierMapping );
    closer.push( RoutingKeyProvider::close, routingKeyProvider );
    closer.push( PojoIndexingProcessor::close, processor );
    closer.push( PojoImplicitReindexingResolver::close, reindexingResolver );
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.pushAll( PojoImplicitReindexingResolverNode::close, nestedNodes );
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ContainerExtractorHolder::close, extractorHolder );
    closer.pushAll( PojoIndexingProcessor::close, nestedNodes );
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
void closeOnFailure() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( ContainerExtractorHolder::close, extractorHolder );
    closer.push( PojoImplicitReindexingResolverValueNodeBuilderDelegate::closeOnFailure, valueBuilderDelegate );
  }
}
origin: hibernate/hibernate-search

  @Override
  public void close() {
    try ( Closer<RuntimeException> closer = new Closer<>() ) {
      closer.pushAll( BeanHolder::close, delegates );
    }
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

@Override
public void close() {
  if ( !closed ) {
    // Make sure to avoid infinite recursion when one of the delegates calls this.close()
    closed = true;
    try ( Closer<RuntimeException> closer = new Closer<>() ) {
      closer.push( PojoMappingDelegate::close, delegate );
      closer.pushAll( CloseDelegate::close, closeDelegates );
    }
  }
}
origin: org.hibernate.search/hibernate-search-mapper-pojo

void closeOnFailure() {
  if ( closed ) {
    return;
  }
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( PojoIndexingProcessorTypeNodeBuilder::closeOnFailure, processorBuilder );
    closer.push( PojoIdentityMappingCollectorImpl::closeOnFailure, identityMappingCollector );
    closer.push( PojoIndexingProcessor::close, preBuiltIndexingProcessor );
    closed = true;
  }
}
origin: hibernate/hibernate-search

@Override
public void close() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.pushAll( PojoImplicitReindexingResolverNode::close, nestedNodes );
  }
}
origin: hibernate/hibernate-search

void closeOnFailure() {
  try ( Closer<RuntimeException> closer = new Closer<>() ) {
    closer.push( AbstractPojoImplicitReindexingResolverNodeBuilder::closeOnFailure, typeNodeBuilder );
    closer.pushAll(
        AbstractPojoImplicitReindexingResolverNodeBuilder::closeOnFailure, castedTypeNodeBuilders.values()
    );
  }
}
org.hibernate.search.util.impl.commonCloser

Javadoc

A helper for closing multiple resources and re-throwing only one exception, Throwable#addSuppressed(Throwable) the others as necessary.

This class is not thread safe.

This helper is mainly useful when implementing AutoCloseable#close()or a similar closing method in your own class, to make sure that all resources are at least given the chance to close, even if closing one of them fails. When creating then closing resources in the scope of a single method call, try-with-resource blocks should be favored.

See the AbstractCloser superclass for a list of methods allowing to close objects while catching exceptions.

Warning: In order not to ignore exceptions, you should always call Closer#close()once you closed all of your resources. The most straightforward way to do this is to use a try-with-resource block:

 
public void myCloseFunction() throws MyException { 
try ( Closer<MyException> closer = new Closer<>() ) { 
closer.push( this.myCloseable::close ); 
closer.pushAll( this.myListOfCloseables, MyCloseableType::close ); 
} 
} 

Exception type

Note that the closer has a generic type parameter, allowing it to re-throw a given checked exception. If you don't want to use this feature, you can simply use a Closer.

Splitting

If you need to close multiple resources throwing different checked exceptions, and those exceptions don't have a practical common superclass, you can "split" the closer:

 
public void myCloseFunction() throws IOException, MyException, MyOtherException { 
try ( Closer<MyException> closer1 = new Closer<>(); 
Closer<IOException> closer2 = closer1.split(); 
Closer<MyOtherException> closer3 = closer1.split() ) { 
closer2.push( this.someJavaIOCloseable::close ); 
closer1.pushAll( this.myListOfCloseables1, MyCloseableTypeThrowingMyException::close ); 
closer3.pushAll( this.myListOfCloseables2, MyCloseableTypeThrowingMyOtherException::close ); 
} 
} 

The multiple closers will share the same state, which means the first exception to be caught by any of the closers will be the one to be re-thrown, and all subsequent exceptions caught by any closer will be added as suppressed to this first exception. Be careful though, you will have to close every single closer. Closing just the original one will not be enough.

Most used methods

  • <init>
  • push
  • pushAll

Popular in Java

  • Reading from database using SQL prepared statement
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • getExternalFilesDir (Context)
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • JLabel (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now