All Downloads are FREE. Search and download functionalities are using the official Maven repository.

socketfactory.SocketFactoryService.groovy Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
package socketfactory

import socketfactory.spi.SocketFactory

class SocketFactoryService {

  private static SocketFactoryService service
  private ServiceLoader loader

  private SocketFactoryService() {
    loader = ServiceLoader.load(SocketFactory)
  }

  static synchronized SocketFactoryService getInstance() {
    if (service == null) {
      service = new SocketFactoryService()
    }
    return service
  }

  def getSchemeSocketFactory(scheme) {
    def socketFactory = null

    try {
      Iterator socketFactories = loader.iterator()
      while (socketFactory == null && socketFactories.hasNext()) {
        SocketFactory candidate = socketFactories.next()
        if (candidate.supports(scheme)) {
          socketFactory = candidate
        }
      }
    }
    catch (ServiceConfigurationError serviceError) {
      socketFactory = null
      serviceError.printStackTrace()
    }
    return socketFactory
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy