Class IgniteSpringBean
- java.lang.Object
-
- org.apache.ignite.IgniteSpringBean
-
- All Implemented Interfaces:
Externalizable,Serializable,AutoCloseable,Ignite,org.springframework.beans.factory.Aware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.SmartInitializingSingleton,org.springframework.context.ApplicationContextAware
public class IgniteSpringBean extends Object implements Ignite, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, Externalizable
Ignite Spring bean allows to bypassIgnitionmethods. In other words, this bean class allows to inject new grid instance from Spring configuration file directly without invoking staticIgnitionmethods. This class can be wired directly from Spring and can be referenced from within other Spring beans. By virtue of implementingDisposableBeanandSmartInitializingSingletoninterfaces,IgniteSpringBeanautomatically starts and stops underlying grid instance.A note should be taken that Ignite instance is started after all other Spring beans have been initialized and right before Spring context is refreshed. That implies that it's not valid to reference IgniteSpringBean from any kind of Spring bean init methods like
javax.annotation.PostConstruct. If it's required to reference IgniteSpringBean for other bean initialization purposes, it should be done from aContextRefreshedEventlistener method declared in that bean.Spring Configuration Example
Here is a typical example of describing it in Spring file:<bean id="mySpringBean" class="org.apache.ignite.IgniteSpringBean"> <property name="configuration"> <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> <property name="igniteInstanceName" value="mySpringGrid"/> </bean> </property> </bean>Or use default configuration:<bean id="mySpringBean" class="org.apache.ignite.IgniteSpringBean"/>
Java Example
Here is how you may access this bean from code:AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("/path/to/spring/file"); // Register Spring hook to destroy bean automatically. ctx.registerShutdownHook(); Ignite ignite = (Ignite)ctx.getBean("mySpringBean");- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IgniteSpringBean()
-
Method Summary
-
-
-
Method Detail
-
configuration
public IgniteConfiguration configuration()
- Specified by:
configurationin interfaceIgnite
-
getConfiguration
public IgniteConfiguration getConfiguration()
Gets the configuration of this Ignite instance.This method is required for proper Spring integration and is the same as
configuration(). See https://issues.apache.org/jira/browse/IGNITE-1102 for details.NOTE:
SPIs obtains through this method should never be used directly. SPIs provide internal view on the subsystem and is used internally by Ignite kernal. In rare use cases when access to a specific implementation of this SPI is required - an instance of this SPI can be obtained via this method to check its configuration properties or call other non-SPI methods.- Returns:
- Ignite configuration instance.
- See Also:
configuration()
-
setConfiguration
public void setConfiguration(IgniteConfiguration cfg)
Sets Ignite configuration.- Parameters:
cfg- Ignite configuration.
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext() throws org.springframework.beans.BeansExceptionGets the spring application context this Ignite runs in.- Returns:
- Application context this Ignite runs in.
- Throws:
org.springframework.beans.BeansException
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext ctx) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
destroy
public void destroy() throws Exception- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
- Specified by:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
log
public IgniteLogger log()
-
version
public IgniteProductVersion version()
-
compute
public IgniteCompute compute()
-
metrics
public IgniteMetrics metrics()
-
services
public IgniteServices services()
-
message
public IgniteMessaging message()
-
events
public IgniteEvents events()
-
executorService
public ExecutorService executorService()
- Specified by:
executorServicein interfaceIgnite
-
cluster
public IgniteCluster cluster()
-
compute
public IgniteCompute compute(ClusterGroup grp)
-
message
public IgniteMessaging message(ClusterGroup prj)
-
events
public IgniteEvents events(ClusterGroup grp)
-
services
public IgniteServices services(ClusterGroup grp)
-
executorService
public ExecutorService executorService(ClusterGroup grp)
- Specified by:
executorServicein interfaceIgnite
-
scheduler
public IgniteScheduler scheduler()
-
resetLostPartitions
public void resetLostPartitions(Collection<String> cacheNames)
- Specified by:
resetLostPartitionsin interfaceIgnite
-
dataRegionMetrics
public Collection<DataRegionMetrics> dataRegionMetrics()
- Specified by:
dataRegionMetricsin interfaceIgnite
-
dataRegionMetrics
@Nullable public @Nullable DataRegionMetrics dataRegionMetrics(String memPlcName)
- Specified by:
dataRegionMetricsin interfaceIgnite
-
encryption
public IgniteEncryption encryption()
- Specified by:
encryptionin interfaceIgnite
-
snapshot
public IgniteSnapshot snapshot()
-
tracingConfiguration
@NotNull public @NotNull TracingConfigurationManager tracingConfiguration()
- Specified by:
tracingConfigurationin interfaceIgnite
-
withApplicationAttributes
public Ignite withApplicationAttributes(Map<String,String> attrs)
- Specified by:
withApplicationAttributesin interfaceIgnite
-
memoryMetrics
public Collection<MemoryMetrics> memoryMetrics()
- Specified by:
memoryMetricsin interfaceIgnite
-
memoryMetrics
@Nullable public @Nullable MemoryMetrics memoryMetrics(String memPlcName)
- Specified by:
memoryMetricsin interfaceIgnite
-
cache
public <K,V> IgniteCache<K,V> cache(@Nullable @Nullable String name)
-
cacheNames
public Collection<String> cacheNames()
- Specified by:
cacheNamesin interfaceIgnite
-
createCache
public <K,V> IgniteCache<K,V> createCache(CacheConfiguration<K,V> cacheCfg)
- Specified by:
createCachein interfaceIgnite
-
getOrCreateCache
public <K,V> IgniteCache<K,V> getOrCreateCache(CacheConfiguration<K,V> cacheCfg)
- Specified by:
getOrCreateCachein interfaceIgnite
-
createCache
public <K,V> IgniteCache<K,V> createCache(CacheConfiguration<K,V> cacheCfg, NearCacheConfiguration<K,V> nearCfg)
- Specified by:
createCachein interfaceIgnite
-
createCaches
public Collection<IgniteCache> createCaches(Collection<CacheConfiguration> cacheCfgs)
- Specified by:
createCachesin interfaceIgnite
-
getOrCreateCache
public <K,V> IgniteCache<K,V> getOrCreateCache(CacheConfiguration<K,V> cacheCfg, NearCacheConfiguration<K,V> nearCfg)
- Specified by:
getOrCreateCachein interfaceIgnite
-
createNearCache
public <K,V> IgniteCache<K,V> createNearCache(String cacheName, NearCacheConfiguration<K,V> nearCfg)
- Specified by:
createNearCachein interfaceIgnite
-
getOrCreateNearCache
public <K,V> IgniteCache<K,V> getOrCreateNearCache(@Nullable @Nullable String cacheName, NearCacheConfiguration<K,V> nearCfg)
- Specified by:
getOrCreateNearCachein interfaceIgnite
-
getOrCreateCache
public <K,V> IgniteCache<K,V> getOrCreateCache(String cacheName)
- Specified by:
getOrCreateCachein interfaceIgnite
-
getOrCreateCaches
public Collection<IgniteCache> getOrCreateCaches(Collection<CacheConfiguration> cacheCfgs)
- Specified by:
getOrCreateCachesin interfaceIgnite
-
createCache
public <K,V> IgniteCache<K,V> createCache(String cacheName)
- Specified by:
createCachein interfaceIgnite
-
addCacheConfiguration
public <K,V> void addCacheConfiguration(CacheConfiguration<K,V> cacheCfg)
- Specified by:
addCacheConfigurationin interfaceIgnite
-
destroyCache
public void destroyCache(String cacheName)
- Specified by:
destroyCachein interfaceIgnite
-
destroyCaches
public void destroyCaches(Collection<String> cacheNames)
- Specified by:
destroyCachesin interfaceIgnite
-
transactions
public IgniteTransactions transactions()
- Specified by:
transactionsin interfaceIgnite
-
dataStreamer
public <K,V> IgniteDataStreamer<K,V> dataStreamer(@Nullable @Nullable String cacheName)
- Specified by:
dataStreamerin interfaceIgnite
-
plugin
public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException
- Specified by:
pluginin interfaceIgnite- Throws:
PluginNotFoundException
-
binary
public IgniteBinary binary()
-
close
public void close() throws IgniteException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIgnite- Throws:
IgniteException
-
atomicSequence
@Nullable public @Nullable IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create)
- Specified by:
atomicSequencein interfaceIgnite
-
atomicSequence
public IgniteAtomicSequence atomicSequence(String name, AtomicConfiguration cfg, long initVal, boolean create) throws IgniteException
- Specified by:
atomicSequencein interfaceIgnite- Throws:
IgniteException
-
atomicLong
@Nullable public @Nullable IgniteAtomicLong atomicLong(String name, long initVal, boolean create)
- Specified by:
atomicLongin interfaceIgnite
-
atomicLong
public IgniteAtomicLong atomicLong(String name, AtomicConfiguration cfg, long initVal, boolean create) throws IgniteException
- Specified by:
atomicLongin interfaceIgnite- Throws:
IgniteException
-
atomicReference
@Nullable public <T> @Nullable IgniteAtomicReference<T> atomicReference(String name, @Nullable T initVal, boolean create)
- Specified by:
atomicReferencein interfaceIgnite
-
atomicReference
public <T> IgniteAtomicReference<T> atomicReference(String name, AtomicConfiguration cfg, @Nullable T initVal, boolean create) throws IgniteException
- Specified by:
atomicReferencein interfaceIgnite- Throws:
IgniteException
-
atomicStamped
@Nullable public <T,S> @Nullable IgniteAtomicStamped<T,S> atomicStamped(String name, @Nullable T initVal, @Nullable S initStamp, boolean create)
- Specified by:
atomicStampedin interfaceIgnite
-
atomicStamped
public <T,S> IgniteAtomicStamped<T,S> atomicStamped(String name, AtomicConfiguration cfg, @Nullable T initVal, @Nullable S initStamp, boolean create) throws IgniteException
- Specified by:
atomicStampedin interfaceIgnite- Throws:
IgniteException
-
countDownLatch
@Nullable public @Nullable IgniteCountDownLatch countDownLatch(String name, int cnt, boolean autoDel, boolean create)
- Specified by:
countDownLatchin interfaceIgnite
-
semaphore
@Nullable public @Nullable IgniteSemaphore semaphore(String name, int cnt, boolean failoverSafe, boolean create)
-
reentrantLock
@Nullable public @Nullable IgniteLock reentrantLock(String name, boolean failoverSafe, boolean fair, boolean create)
- Specified by:
reentrantLockin interfaceIgnite
-
queue
@Nullable public <T> @Nullable IgniteQueue<T> queue(String name, int cap, CollectionConfiguration cfg)
-
set
@Nullable public <T> @Nullable IgniteSet<T> set(String name, CollectionConfiguration cfg)
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
checkIgnite
protected void checkIgnite() throws IllegalStateExceptionChecks if this bean is valid.- Throws:
IllegalStateException- If bean is not valid, i.e. Ignite has already been stopped or has not yet been started.
-
-