Class IgniteClientSpringBean

  • All Implemented Interfaces:
    AutoCloseable, IgniteClient, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

    public class IgniteClientSpringBean
    extends Object
    implements IgniteClient, org.springframework.context.SmartLifecycle
    Represents Ignite client Spring bean that provides the ability to automatically start Ignite client during Spring Context initialization. It requires ClientConfiguration to be set before bean use (see setClientConfiguration(ClientConfiguration)}). A note should be taken that Ignite client 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 IgniteClientSpringBean from any kind of Spring bean init methods like PostConstruct. If it's required to reference IgniteClientSpringBean for other bean initialization purposes, it should be done from a ContextRefreshedEvent listener method declared in that bean.

    Spring XML Configuration Example

     <bean id="igniteClient" class="org.apache.ignite.IgniteClientSpringBean">
         <property name="clientConfiguration">
             <bean class="org.apache.ignite.configuration.ClientConfiguration">
                 <property name="addresses">
                     <list>
                         <value>127.0.0.1:10800</value>
                     </list>
                 </property>
             </bean>
         </property>
     </bean>
     
    • Field Detail

      • DFLT_IGNITE_CLI_LIFECYCLE_PHASE

        public static final int DFLT_IGNITE_CLI_LIFECYCLE_PHASE
        Default Ignite client SmartLifecycle phase.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IgniteClientSpringBean

        public IgniteClientSpringBean()
    • Method Detail

      • isAutoStartup

        public boolean isAutoStartup()
        Specified by:
        isAutoStartup in interface org.springframework.context.SmartLifecycle
      • stop

        public void stop​(Runnable callback)
        Specified by:
        stop in interface org.springframework.context.SmartLifecycle
      • stop

        public void stop()
        Specified by:
        stop in interface org.springframework.context.Lifecycle
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface org.springframework.context.Lifecycle
      • start

        public void start()
        Specified by:
        start in interface org.springframework.context.Lifecycle
      • getPhase

        public int getPhase()
        Specified by:
        getPhase in interface org.springframework.context.Phased
        Specified by:
        getPhase in interface org.springframework.context.SmartLifecycle
      • getOrCreateCache

        public <K,​V> ClientCache<K,​V> getOrCreateCache​(String name)
                                                            throws ClientException
        Gets the existing cache or creates a new cache with default configuration if it does not exist.
        Specified by:
        getOrCreateCache in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        name - Cache name.
        Returns:
        Client cache instance.
        Throws:
        ClientException
      • getOrCreateCacheAsync

        public <K,​V> IgniteClientFuture<ClientCache<K,​V>> getOrCreateCacheAsync​(String name)
                                                                                     throws ClientException
        Gets the existing cache or creates a new cache with default configuration if it does not exist.
        Specified by:
        getOrCreateCacheAsync in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        name - Cache name.
        Returns:
        a Future representing pending completion of the operation, which wraps the resulting cache.
        Throws:
        ClientException
      • getOrCreateCache

        public <K,​V> ClientCache<K,​V> getOrCreateCache​(ClientCacheConfiguration cfg)
                                                            throws ClientException
        Gets the existing cache or creates a new cache if it does not exist.
        Specified by:
        getOrCreateCache in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        cfg - Cache configuration. If the cache exists, this configuration is ignored.
        Returns:
        Client cache instance.
        Throws:
        ClientException
      • getOrCreateCacheAsync

        public <K,​V> IgniteClientFuture<ClientCache<K,​V>> getOrCreateCacheAsync​(ClientCacheConfiguration cfg)
                                                                                     throws ClientException
        Gets the existing cache or creates a new cache if it does not exist.
        Specified by:
        getOrCreateCacheAsync in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        cfg - Cache configuration. If the cache exists, this configuration is ignored.
        Returns:
        a Future representing pending completion of the operation, which wraps the resulting cache.
        Throws:
        ClientException
      • cache

        public <K,​V> ClientCache<K,​V> cache​(String name)
        Get existing cache.
        Specified by:
        cache in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        name - Cache name.
        Returns:
        Client cache instance.
      • createCache

        public <K,​V> ClientCache<K,​V> createCache​(String name)
                                                       throws ClientException
        Creates a cache with a default configuration.
        Specified by:
        createCache in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        name - Cache name.
        Returns:
        Resulting cache.
        Throws:
        ClientException
      • createCacheAsync

        public <K,​V> IgniteClientFuture<ClientCache<K,​V>> createCacheAsync​(String name)
                                                                                throws ClientException
        Creates a cache with a default configuration.
        Specified by:
        createCacheAsync in interface IgniteClient
        Type Parameters:
        K - Type of the cache key.
        V - Type of the cache value.
        Parameters:
        name - Cache name.
        Returns:
        a Future representing pending completion of the operation, which wraps the resulting cache.
        Throws:
        ClientException
      • compute

        public ClientCompute compute()
        Gets compute facade over all cluster nodes started in server mode.
        Specified by:
        compute in interface IgniteClient
        Returns:
        Compute instance over all cluster nodes started in server mode.
      • compute

        public ClientCompute compute​(ClientClusterGroup grp)
        Gets compute facade over the specified cluster group. All operations on the returned ClientCompute instance will only include nodes from this cluster group.
        Specified by:
        compute in interface IgniteClient
        Parameters:
        grp - Cluster group.
        Returns:
        Compute instance over given cluster group.
      • services

        public ClientServices services()
        Gets services facade over all cluster nodes started in server mode.
        Specified by:
        services in interface IgniteClient
        Returns:
        Services facade over all cluster nodes started in server mode.
      • services

        public ClientServices services​(ClientClusterGroup grp)
        Gets services facade over nodes within the cluster group. All operations on the returned ClientServices instance will only include nodes from the specified cluster group. Note: In some cases there will be additional requests for each service invocation from client to server to resolve cluster group.
        Specified by:
        services in interface IgniteClient
        Parameters:
        grp - Cluster group.
        Returns:
        Services functionality over given cluster group.
      • atomicLong

        public ClientAtomicLong atomicLong​(String name,
                                           long initVal,
                                           boolean create)
        Gets an atomic long from cache and creates one if it has not been created yet and create flag is true.
        Specified by:
        atomicLong in interface IgniteClient
        Parameters:
        name - Name of atomic long.
        initVal - Initial value for atomic long. Ignored if create flag is false.
        create - Boolean flag indicating whether data structure should be created if it does not exist.
        Returns:
        Atomic long.
      • atomicLong

        public ClientAtomicLong atomicLong​(String name,
                                           ClientAtomicConfiguration cfg,
                                           long initVal,
                                           boolean create)
        Gets an atomic long from cache and creates one if it has not been created yet and create flag is true.
        Specified by:
        atomicLong in interface IgniteClient
        Parameters:
        name - Name of atomic long.
        cfg - Configuration.
        initVal - Initial value for atomic long. Ignored if create flag is false.
        create - Boolean flag indicating whether data structure should be created if it does not exist.
        Returns:
        Atomic long.
      • set

        public <T> ClientIgniteSet<T> set​(String name,
                                          @Nullable
                                          @Nullable ClientCollectionConfiguration cfg)
        Gets a distributed set from cache. Creates one if it has not been created yet and cfg is not null.
        Specified by:
        set in interface IgniteClient
        Type Parameters:
        T - Type of the elements in set.
        Parameters:
        name - Set name.
        cfg - Set configuration if new set should be created.
        Returns:
        Set with given properties.
      • close

        public void close()
        Closes this client's open connections and relinquishes all underlying resources.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface IgniteClient
      • setClientConfiguration

        public IgniteClientSpringBean setClientConfiguration​(ClientConfiguration cfg)
        Sets Ignite client configuration.
        Parameters:
        cfg - Ignite thin client configuration.
        Returns:
        this for chaining.
      • getClientConfiguration

        public ClientConfiguration getClientConfiguration()
        Returns:
        Ignite client configuration.
      • setPhase

        public IgniteClientSpringBean setPhase​(int phase)
        Sets SmartLifecycle phase during which the current bean will be initialized. Note, underlying Ignite client will be closed during handling of DisposableBean since IgniteClient implements AutoCloseable interface.
        Parameters:
        phase - SmartLifecycle phase.
        Returns:
        this for chaining.