@Override public void registerService(Manageable service, Class<? extends Service> serviceRole) { final String domain = service.getManagementDomain() == null ? AvailableSettings.JMX_DEFAULT_OBJ_NAME_DOMAIN : service.getManagementDomain(); final String serviceType = service.getManagementServiceType() == null ? service.getClass().getName() : service.getManagementServiceType(); try { final ObjectName objectName = new ObjectName( String.format( OBJ_NAME_TEMPLATE, domain, sessionFactoryName, serviceRole.getName(), serviceType ) ); registerMBean( objectName, service.getManagementBean() ); } catch ( MalformedObjectNameException e ) { throw new HibernateException( "Unable to generate service IbjectName", e ); } }
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; }
@Override public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) { // todo : add check/error for unexpected initiator types? SessionFactoryServiceInitiator<R> sessionFactoryServiceInitiator = (SessionFactoryServiceInitiator<R>) serviceInitiator; if ( metadata != null ) { return sessionFactoryServiceInitiator.initiateService( sessionFactory, metadata, this ); } else if ( configuration != null ) { return sessionFactoryServiceInitiator.initiateService( sessionFactory, configuration, this ); } else { throw new IllegalStateException( "Both metadata and configuration are null." ); } }
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() ); }
@Override public <R extends Service> R getService(Class<R> serviceRole) { final ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole ); if ( serviceBinding == null ) { throw new UnknownServiceException( serviceRole ); } R service = serviceBinding.getService(); if ( service == null ) { service = initializeService( serviceBinding ); } return service; }
@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 ); } }
private <R extends Service> void applyInjections(R service) { try { for ( Method method : service.getClass().getMethods() ) { InjectService injectService = method.getAnnotation( InjectService.class ); if ( injectService == null ) { continue; } processInjection( service, method, injectService ); } } catch (NullPointerException e) { log.error( "NPE injecting service deps : " + service.getClass().getName() ); } }
@SuppressWarnings({ "unchecked" }) private <T extends Service> void processInjection(T service, Method injectionMethod, InjectService injectService) { if ( injectionMethod.getParameterTypes() == null || injectionMethod.getParameterTypes().length != 1 ) { throw new ServiceDependencyException( "Encountered @InjectService on method with unexpected number of parameters" ); } Class dependentServiceRole = injectService.serviceRole(); if ( dependentServiceRole == null || dependentServiceRole.equals( Void.class ) ) { dependentServiceRole = injectionMethod.getParameterTypes()[0]; } // todo : because of the use of proxies, this is no longer returning null here... final Service dependantService = getService( dependentServiceRole ); if ( dependantService == null ) { if ( injectService.required() ) { throw new ServiceDependencyException( "Dependency [" + dependentServiceRole + "] declared by service [" + service + "] not found" ); } } else { try { injectionMethod.invoke( service, dependantService ); } catch ( Exception e ) { throw new ServiceDependencyException( "Cannot inject dependency service", e ); } } }
@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() ); } }
@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() ); } } }
@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; }
@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() ); } } }
@Override public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) { //TODO nothing to do here or should we inject SessionFactory properties? }
@SuppressWarnings({ "unchecked" }) protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) { final ServiceBinding serviceBinding = new ServiceBinding( this, initiator ); serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding ); }
@Override @SuppressWarnings({ "unchecked" }) public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) { return locateServiceBinding( serviceRole, true ); }
@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 if ( roleXref != null ) { 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; }
protected <R extends Service> void registerService(ServiceBinding<R> serviceBinding, R service) { serviceBinding.setService( service ); synchronized ( serviceBindingList ) { serviceBindingList.add( serviceBinding ); } }
@Override public <R extends Service> R getService(Class<R> serviceRole) { final ServiceBinding<R> binding = locateServiceBinding( serviceRole ); return binding == null ? null : binding.getService(); }
@Override public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) { throw new ServiceException( "Boot-strap registry should only contain provided services" ); }
@Override public <R extends Service> void configureService(ServiceBinding<R> binding) { throw new ServiceException( "Boot-strap registry should only contain provided services" ); }
@Override public <R extends Service> void injectDependencies(ServiceBinding<R> binding) { throw new ServiceException( "Boot-strap registry should only contain provided services" ); }
@Override public <R extends Service> void startService(ServiceBinding<R> binding) { throw new ServiceException( "Boot-strap registry should only contain provided services" ); }
@Override public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) { // todo : add check/error for unexpected initiator types? return ( (StandardServiceInitiator<R>) serviceInitiator ).initiateService( configurationValues, this ); }
@Override public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) { if ( Configurable.class.isInstance( serviceBinding.getService() ) ) { ( (Configurable) serviceBinding.getService() ).configure( configurationValues ); } }
private <T extends Service> T getService(Class<T> serviceClass) { return eventSource.getFactory().getServiceRegistry().getService( serviceClass ); }
protected Service getService(Class<? extends Service> serviceImpl) { SessionFactoryImplementor factory = super.sfi(); ServiceRegistryImplementor serviceRegistry = factory.getServiceRegistry(); return serviceRegistry.getService(serviceImpl); }
/** * Handles registration of a manageable service. * * @param service The manageable service * @param serviceRole The service's role. */ public void registerService(Manageable service, Class<? extends Service> serviceRole);
/** * Locate the binding for the given role. Should, generally speaking, look into parent registry if one. * * @param serviceRole The service role for which to locate a binding. * @param <R> generic return type. * * @return The located binding; may be {@code null} */ public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole);
/** * Adds a user-provided service. * * @param serviceRole The role of the service being added * @param service The service implementation * * @return this, for method chaining */ @SuppressWarnings( {"unchecked"}) public StandardServiceRegistryBuilder addService(final Class serviceRole, final Service service) { providedServices.add( new ProvidedService( serviceRole, service ) ); return this; }
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
public <R extends Service> void configureService(ServiceBinding<R> binding);
public <R extends Service> void injectDependencies(ServiceBinding<R> binding);
public <R extends Service> void startService(ServiceBinding<R> binding);
public <R extends Service> void stopService(ServiceBinding<R> binding);