Java 类org.hibernate.service.Service 实例源码

项目:lams    文件:JmxServiceImpl.java   
@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 );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
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;
}
项目:lams    文件:SessionFactoryServiceRegistryImpl.java   
@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." );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
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() );
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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;
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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 );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
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() );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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 );
        }
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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()
        );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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() );
        }
    }
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@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;
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@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() );
        }
    }
}
项目:lams    文件:SessionFactoryServiceRegistryImpl.java   
@Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
    //TODO nothing to do here or should we inject SessionFactory properties?
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@SuppressWarnings({ "unchecked" })
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
    final ServiceBinding serviceBinding = new ServiceBinding( this, initiator );
    serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding );
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@Override
@SuppressWarnings({ "unchecked" })
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
    return locateServiceBinding( serviceRole, true );
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
@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;
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
protected <R extends Service> void registerService(ServiceBinding<R> serviceBinding, R service) {
    serviceBinding.setService( service );
    synchronized ( serviceBindingList ) {
        serviceBindingList.add( serviceBinding );
    }
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@Override
public <R extends Service> R getService(Class<R> serviceRole) {
    final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
    return binding == null ? null : binding.getService();
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@Override
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
    throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@Override
public <R extends Service> void configureService(ServiceBinding<R> binding) {
    throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@Override
public <R extends Service> void injectDependencies(ServiceBinding<R> binding) {
    throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
项目:lams    文件:BootstrapServiceRegistryImpl.java   
@Override
public <R extends Service> void startService(ServiceBinding<R> binding) {
    throw new ServiceException( "Boot-strap registry should only contain provided services" );
}
项目:lams    文件:StandardServiceRegistryImpl.java   
@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 );
}
项目:lams    文件:StandardServiceRegistryImpl.java   
@Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
    if ( Configurable.class.isInstance( serviceBinding.getService() ) ) {
        ( (Configurable) serviceBinding.getService() ).configure( configurationValues );
    }
}
项目:Hibernate-Search-GenericJPA    文件:EventSourceTransactionContext.java   
private <T extends Service> T getService(Class<T> serviceClass) {
    return eventSource.getFactory().getServiceRegistry().getService( serviceClass );
}
项目:debop4j    文件:LoadSelectedColumnsCollectionTest.java   
protected Service getService(Class<? extends Service> serviceImpl) {
    SessionFactoryImplementor factory = super.sfi();
    ServiceRegistryImplementor serviceRegistry = factory.getServiceRegistry();
    return serviceRegistry.getService(serviceImpl);
}
项目:lams    文件:JmxService.java   
/**
 * 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);
项目:lams    文件:ServiceRegistryImplementor.java   
/**
 * 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);
项目:lams    文件:StandardServiceRegistryBuilder.java   
/**
 * 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;
}
项目:lams    文件:ServiceBinding.java   
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
项目:lams    文件:ServiceBinding.java   
public <R extends Service> void configureService(ServiceBinding<R> binding);
项目:lams    文件:ServiceBinding.java   
public <R extends Service> void injectDependencies(ServiceBinding<R> binding);
项目:lams    文件:ServiceBinding.java   
public <R extends Service> void startService(ServiceBinding<R> binding);
项目:lams    文件:ServiceBinding.java   
public <R extends Service> void stopService(ServiceBinding<R> binding);