List of usage examples for org.springframework.util Assert isInstanceOf
public static void isInstanceOf(Class<?> type, @Nullable Object obj)
From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory); this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; }
From source file:org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener.java
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) { Assert.isInstanceOf(StandardContext.class, event.getSource()); StandardContext standardContext = (StandardContext) event.getSource(); for (ServletContextInitializer initializer : this.initializers) { try { initializer.onStartup(standardContext.getServletContext()); } catch (Exception ex) { this.startUpException = ex; // Prevent Tomcat from logging and re-throwing when we know we can // deal with it in the main thread, but log for information here. logger.error("Error starting Tomcat context: " + ex.getClass().getName()); break; }//from w w w .j a v a2s . c o m } } }
From source file:org.springframework.boot.SpringApplication.java
/** * Refresh the underlying {@link ApplicationContext}. * @param applicationContext the application context to refresh *//*from w w w .j a va2 s . c om*/ protected void refresh(ApplicationContext applicationContext) { Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext); ((AbstractApplicationContext) applicationContext).refresh(); }
From source file:org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.java
private Object getSourceContext(Object[] args) { ApplicationContext context = getStartedApplicationContext(); if (!ObjectUtils.isEmpty(args)) { Assert.isInstanceOf((Class<?>) args[0], context); }//from ww w . j a v a 2 s . co m return context; }
From source file:org.springframework.cloud.stream.binder.AbstractBinder.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext); this.applicationContext = (AbstractApplicationContext) applicationContext; }
From source file:org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.java
@Override public Binding<PollableSource<MessageHandler>> bindPollableConsumer(String name, String group, final PollableSource<MessageHandler> inboundBindTarget, C properties) { Assert.isInstanceOf(DefaultPollableMessageSource.class, inboundBindTarget); DefaultPollableMessageSource bindingTarget = (DefaultPollableMessageSource) inboundBindTarget; ConsumerDestination destination = this.provisioningProvider.provisionConsumerDestination(name, group, properties);// w w w . ja va 2 s . c om if (HeaderMode.embeddedHeaders.equals(properties.getHeaderMode())) { bindingTarget.addInterceptor(0, this.embeddedHeadersChannelInterceptor); } final PolledConsumerResources resources = createPolledConsumerResources(name, group, destination, properties); bindingTarget.setSource(resources.getSource()); if (resources.getErrorInfrastructure() != null) { if (resources.getErrorInfrastructure().getErrorChannel() != null) { bindingTarget.setErrorChannel(resources.getErrorInfrastructure().getErrorChannel()); } ErrorMessageStrategy ems = getErrorMessageStrategy(); if (ems != null) { bindingTarget.setErrorMessageStrategy(ems); } } if (properties.getMaxAttempts() > 1) { bindingTarget.setRetryTemplate(buildRetryTemplate(properties)); bindingTarget.setRecoveryCallback( getPolledConsumerRecoveryCallback(resources.getErrorInfrastructure(), properties)); } postProcessPollableSource(bindingTarget); if (resources.getSource() instanceof Lifecycle) { ((Lifecycle) resources.getSource()).start(); } return new DefaultBinding<PollableSource<MessageHandler>>(name, group, inboundBindTarget, resources.getSource() instanceof Lifecycle ? (Lifecycle) resources.getSource() : null) { @Override public void afterUnbind() { afterUnbindConsumer(destination, this.group, properties); destroyErrorInfrastructure(destination, group, properties); } }; }
From source file:org.springframework.cloud.stream.function.FunctionInvoker.java
FunctionInvoker(String functionName, FunctionCatalog functionCatalog, FunctionInspector functionInspector, CompositeMessageConverterFactory compositeMessageConverterFactory) { this.userFunction = functionCatalog.lookup(functionName); Assert.isInstanceOf(Function.class, this.userFunction); Assert.notNull(this.userFunction, "userFunction: " + functionName + " can not be located."); this.messageConverter = compositeMessageConverterFactory.getMessageConverterForAllRegistered(); FunctionType functionType = functionInspector.getRegistration(this.userFunction).getType(); this.inputClass = functionType.getInputType(); }
From source file:org.springframework.integration.config.GlobalChannelInterceptorProcessor.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ListableBeanFactory.class, beanFactory); this.beanFactory = (ListableBeanFactory) beanFactory; //NOSONAR (inconsistent sync) }
From source file:org.springframework.integration.redis.util.RedisLockRegistry.java
@Override public Lock obtain(Object lockKey) { Assert.isInstanceOf(String.class, lockKey); //try to find the lock within hard references RedisLock lock = findLock(this.hardThreadLocks.get(), lockKey); /*/*from w w w . ja v a 2 s . c om*/ * If the lock is locked, check that it matches what's in the store. * If it doesn't, the lock must have expired. */ if (lock != null && lock.thread != null) { RedisLock lockInStore = this.redisTemplate.boundValueOps(this.registryKey + ":" + lockKey).get(); if (lockInStore == null || !lock.equals(lockInStore)) { try { lock.unlock(); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Lock was released due to expiration. A new one will be obtained...", e); } } if (this.hardThreadLocks.get() != null) { this.hardThreadLocks.get().remove(lock); } if (this.weakThreadLocks.get() != null) { this.weakThreadLocks.get().remove(lock); } lock = null; } } if (lock == null) { //try to find the lock within weak references lock = findLock(this.weakThreadLocks.get(), lockKey); if (lock == null) { lock = new RedisLock((String) lockKey); if (this.useWeakReferences) { getWeakThreadLocks().add(lock); } } } return lock; }
From source file:org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory.java
public TransactionSynchronization create(Object key) { Assert.notNull(key, "'key' must not be null"); Object resourceHolder = TransactionSynchronizationManager.getResource(key); Assert.isInstanceOf(IntegrationResourceHolder.class, resourceHolder); return new DefaultTransactionalResourceSynchronization((IntegrationResourceHolder) resourceHolder, key); }