org.hibernate.service.spi.ServiceBinding Java Examples

The following examples show how to use org.hibernate.service.spi.ServiceBinding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a BootstrapServiceRegistryImpl.
 *
 * Do not use directly generally speaking.  Use {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder}
 * instead.
 *
 * @param autoCloseRegistry See discussion on
 * {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#disableAutoClose}
 * @param classLoaderService The ClassLoaderService to use
 * @param strategySelector The StrategySelector to use
 * @param integratorService The IntegratorService to use
 *
 * @see org.hibernate.boot.registry.BootstrapServiceRegistryBuilder
 */
public BootstrapServiceRegistryImpl(
		boolean autoCloseRegistry,
		ClassLoaderService classLoaderService,
		StrategySelector strategySelector,
		IntegratorService integratorService) {
	this.autoCloseRegistry = autoCloseRegistry;

	this.classLoaderServiceBinding = new ServiceBinding<ClassLoaderService>(
			this,
			ClassLoaderService.class,
			classLoaderService
	);

	this.strategySelectorBinding = new ServiceBinding<StrategySelector>(
			this,
			StrategySelector.class,
			strategySelector
	);

	this.integratorServiceBinding = new ServiceBinding<IntegratorService>(
			this,
			IntegratorService.class,
			integratorService
	);
}
 
Example #2
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a BootstrapServiceRegistryImpl.
 *
 * Do not use directly generally speaking.  Use {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder}
 * instead.
 *
 * @param autoCloseRegistry See discussion on
 * {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#disableAutoClose}
 * @param classLoaderService The ClassLoaderService to use
 * @param providedIntegrators The group of explicitly provided integrators
 *
 * @see org.hibernate.boot.registry.BootstrapServiceRegistryBuilder
 */
public BootstrapServiceRegistryImpl(
		boolean autoCloseRegistry,
		ClassLoaderService classLoaderService,
		LinkedHashSet<Integrator> providedIntegrators) {
	this.autoCloseRegistry = autoCloseRegistry;

	this.classLoaderServiceBinding = new ServiceBinding<ClassLoaderService>(
			this,
			ClassLoaderService.class,
			classLoaderService
	);

	final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
	this.strategySelectorBinding = new ServiceBinding<StrategySelector>(
			this,
			StrategySelector.class,
			strategySelector
	);

	this.integratorServiceBinding = new ServiceBinding<IntegratorService>(
			this,
			IntegratorService.class,
			new IntegratorServiceImpl( providedIntegrators, classLoaderService )
	);
}
 
Example #3
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings( {"unchecked"})
public synchronized void destroy() {
	if ( active.compareAndSet( true, false ) ) {
		try {
			//First thing, make sure that the fast path read is disabled so that
			//threads not owning the synchronization lock can't get an invalid Service:
			initializedServiceByRole.clear();
			synchronized (serviceBindingList) {
				ListIterator<ServiceBinding> serviceBindingsIterator = serviceBindingList.listIterator(
						serviceBindingList.size()
				);
				while ( serviceBindingsIterator.hasPrevious() ) {
					final ServiceBinding serviceBinding = serviceBindingsIterator.previous();
					serviceBinding.getLifecycleOwner().stopService( serviceBinding );
				}
				serviceBindingList.clear();
			}
			serviceBindingMap.clear();
		}
		finally {
			parent.deRegisterChild( this );
		}
	}
}
 
Example #4
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private <R extends Service> R initializeService(ServiceBinding<R> serviceBinding) {
	if ( log.isTraceEnabled() ) {
		log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() );
	}

	// PHASE 1 : create service
	R service = createService( serviceBinding );
	if ( service == null ) {
		return null;
	}

	// PHASE 2 : inject service (***potentially recursive***)
	serviceBinding.getLifecycleOwner().injectDependencies( serviceBinding );

	// PHASE 3 : configure service
	serviceBinding.getLifecycleOwner().configureService( serviceBinding );

	// PHASE 4 : Start service
	serviceBinding.getLifecycleOwner().startService( serviceBinding );

	return service;
}
 
Example #5
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings( {"unchecked"})
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
	if ( ClassLoaderService.class.equals( serviceRole ) ) {
		return (ServiceBinding<R>) classLoaderServiceBinding;
	}
	else if ( StrategySelector.class.equals( serviceRole) ) {
		return (ServiceBinding<R>) strategySelectorBinding;
	}
	else if ( IntegratorService.class.equals( serviceRole ) ) {
		return (ServiceBinding<R>) integratorServiceBinding;
	}

	return null;
}
 
Example #6
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <R extends Service> void stopService(ServiceBinding<R> binding) {
	final Service service = binding.getService();
	if ( Stoppable.class.isInstance( service ) ) {
		try {
			( (Stoppable) service ).stop();
		}
		catch ( Exception e ) {
			LOG.unableToStopService( service.getClass(), e.toString() );
		}
	}
}
 
Example #7
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) {
	ServiceBinding<R> binding = locateServiceBinding( providedService.getServiceRole(), false );
	if ( binding == null ) {
		binding = new ServiceBinding<R>( this, providedService.getServiceRole(), providedService.getService() );
		serviceBindingMap.put( providedService.getServiceRole(), binding );
	}
	registerService( binding, providedService.getService() );
}
 
Example #8
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <R extends Service> void stopService(ServiceBinding<R> binding) {
	final Service service = binding.getService();
	if ( Stoppable.class.isInstance( service ) ) {
		try {
			( (Stoppable) service ).stop();
		}
		catch ( Exception e ) {
			log.unableToStopService( service.getClass(), e.toString() );
		}
	}
}
 
Example #9
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <R extends Service> R getService(Class<R> serviceRole) {
	// TODO: should an exception be thrown if active == false???
	R service = serviceRole.cast( initializedServiceByRole.get( serviceRole ) );
	if ( service != null ) {
		return service;
	}

	//Any service initialization needs synchronization
	synchronized ( this ) {
		// Check again after having acquired the lock:
		service = serviceRole.cast( initializedServiceByRole.get( serviceRole ) );
		if ( service != null ) {
			return service;
		}

		final ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole );
		if ( serviceBinding == null ) {
			throw new UnknownServiceException( serviceRole );
		}
		service = serviceBinding.getService();
		if ( service == null ) {
			service = initializeService( serviceBinding );
		}
		if ( service != null ) {
			// add the service only after it is completely initialized
			initializedServiceByRole.put( serviceRole, service );
		}
		return service;
	}
}
 
Example #10
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <R extends Service> void injectDependencies(ServiceBinding<R> serviceBinding) {
	final R service = serviceBinding.getService();

	applyInjections( service );

	if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
		( (ServiceRegistryAwareService) service ).injectServices( this );
	}
}
 
Example #11
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked" })
public <R extends Service> void startService(ServiceBinding<R> serviceBinding) {
	if ( Startable.class.isInstance( serviceBinding.getService() ) ) {
		( (Startable) serviceBinding.getService() ).start();
	}

	if ( Manageable.class.isInstance( serviceBinding.getService() ) ) {
		getService( JmxService.class ).registerService(
				(Manageable) serviceBinding.getService(),
				serviceBinding.getServiceRole()
		);
	}
}
 
Example #12
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void destroy(ServiceBinding serviceBinding) {
	serviceBinding.getLifecycleOwner().stopService( serviceBinding );
}
 
Example #13
Source File: StandardServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
	if ( Configurable.class.isInstance( serviceBinding.getService() ) ) {
		( (Configurable) serviceBinding.getService() ).configure( configurationValues );
	}
}
 
Example #14
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> void configureService(ServiceBinding<R> binding) {
	throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
 
Example #15
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> void injectDependencies(ServiceBinding<R> binding) {
	throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
 
Example #16
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> void startService(ServiceBinding<R> binding) {
	throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
 
Example #17
Source File: TestingRegistryRule.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
    return null;
}
 
Example #18
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> R getService(Class<R> serviceRole) {
	final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
	return binding == null ? null : binding.getService();
}
 
Example #19
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected <R extends Service> void registerService(ServiceBinding<R> serviceBinding, R service) {
	serviceBinding.setService( service );
	synchronized ( serviceBindingList ) {
		serviceBindingList.add( serviceBinding );
	}
}
 
Example #20
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked" })
protected <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) {
	ServiceBinding<R> serviceBinding = serviceBindingMap.get( serviceRole );
	if ( serviceBinding == null && checkParent && parent != null ) {
		// look in parent
		serviceBinding = parent.locateServiceBinding( serviceRole );
	}

	if ( serviceBinding != null ) {
		return serviceBinding;
	}

	if ( !allowCrawling ) {
		return null;
	}

	// look for a previously resolved alternate registration
	final Class alternative = roleXref.get( serviceRole );
	if ( alternative != null ) {
		return serviceBindingMap.get( alternative );
	}

	// perform a crawl looking for an alternate registration
	for ( ServiceBinding binding : serviceBindingMap.values() ) {
		if ( serviceRole.isAssignableFrom( binding.getServiceRole() ) ) {
			// we found an alternate...
			log.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
			registerAlternate( serviceRole, binding.getServiceRole() );
			return binding;
		}

		if ( binding.getService() != null && serviceRole.isInstance( binding.getService() ) ) {
			// we found an alternate...
			log.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
			registerAlternate( serviceRole, binding.getServiceRole() );
			return binding;
		}
	}

	return null;
}
 
Example #21
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked" })
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
	return locateServiceBinding( serviceRole, true );
}
 
Example #22
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void visitServiceBindings(Consumer<ServiceBinding> action) {
	serviceBindingList.forEach( action );
}
 
Example #23
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked" })
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
	final ServiceBinding serviceBinding = new ServiceBinding( this, initiator );
	serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding );
}
 
Example #24
Source File: SessionFactoryServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
	if ( Configurable.class.isInstance( serviceBinding.getService() ) ) {
		( (Configurable) serviceBinding.getService() ).configure( getService( ConfigurationService.class ).getSettings() );
	}
}