Package org.apache.ignite
Class IgniteClientSpringBean
- java.lang.Object
-
- org.apache.ignite.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 requiresClientConfiguration
to be set before bean use (seesetClientConfiguration(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 referenceIgniteClientSpringBean
from any kind of Spring bean init methods likePostConstruct
. If it's required to referenceIgniteClientSpringBean
for other bean initialization purposes, it should be done from aContextRefreshedEvent
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 Summary
Fields Modifier and Type Field Description static int
DFLT_IGNITE_CLI_LIFECYCLE_PHASE
Default Ignite clientSmartLifecycle
phase.
-
Constructor Summary
Constructors Constructor Description IgniteClientSpringBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientAtomicLong
atomicLong(String name, long initVal, boolean create)
Gets an atomic long from cache and creates one if it has not been created yet andcreate
flag istrue
.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 andcreate
flag istrue
.IgniteBinary
binary()
<K,V>
ClientCache<K,V>cache(String name)
Get existing cache.Collection<String>
cacheNames()
Gets the names of all available caches.IgniteClientFuture<Collection<String>>
cacheNamesAsync()
Gets the names of all available caches.void
close()
Closes this client's open connections and relinquishes all underlying resources.ClientCluster
cluster()
Gets client cluster facade.ClientCompute
compute()
Gets compute facade over all cluster nodes started in server mode.ClientCompute
compute(ClientClusterGroup grp)
Gets compute facade over the specified cluster group.<K,V>
ClientCache<K,V>createCache(String name)
Creates a cache with a default configuration.<K,V>
ClientCache<K,V>createCache(ClientCacheConfiguration cfg)
Creates a cache with the specified configuration.<K,V>
IgniteClientFuture<ClientCache<K,V>>createCacheAsync(String name)
Creates a cache with a default configuration.<K,V>
IgniteClientFuture<ClientCache<K,V>>createCacheAsync(ClientCacheConfiguration cfg)
Creates a cache with the specified configuration.void
destroyCache(String name)
Destroys the cache with the given name.IgniteClientFuture<Void>
destroyCacheAsync(String name)
Destroys the cache with the given name.ClientConfiguration
getClientConfiguration()
<K,V>
ClientCache<K,V>getOrCreateCache(String name)
Gets the existing cache or creates a new cache with default configuration if it does not exist.<K,V>
ClientCache<K,V>getOrCreateCache(ClientCacheConfiguration cfg)
Gets the existing cache or creates a new cache if it does not exist.<K,V>
IgniteClientFuture<ClientCache<K,V>>getOrCreateCacheAsync(String name)
Gets the existing cache or creates a new cache with default configuration if it does not exist.<K,V>
IgniteClientFuture<ClientCache<K,V>>getOrCreateCacheAsync(ClientCacheConfiguration cfg)
Gets the existing cache or creates a new cache if it does not exist.int
getPhase()
boolean
isAutoStartup()
boolean
isRunning()
FieldsQueryCursor<List<?>>
query(SqlFieldsQuery qry)
Execute SQL query and get cursor to iterate over results.ClientServices
services()
Getsservices
facade over all cluster nodes started in server mode.ClientServices
services(ClientClusterGroup grp)
Getsservices
facade over nodes within the cluster group.<T> ClientIgniteSet<T>
set(String name, @Nullable ClientCollectionConfiguration cfg)
Gets a distributed set from cache.IgniteClientSpringBean
setClientConfiguration(ClientConfiguration cfg)
Sets Ignite client configuration.IgniteClientSpringBean
setPhase(int phase)
SetsSmartLifecycle
phase during which the current bean will be initialized.void
start()
void
stop()
void
stop(Runnable callback)
ClientTransactions
transactions()
Gets client transactions facade.
-
-
-
Field Detail
-
DFLT_IGNITE_CLI_LIFECYCLE_PHASE
public static final int DFLT_IGNITE_CLI_LIFECYCLE_PHASE
Default Ignite clientSmartLifecycle
phase.- See Also:
- Constant Field Values
-
-
Method Detail
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
stop
public void stop(Runnable callback)
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
stop
public void stop()
- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()
- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
start
public void start()
- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()
- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.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 interfaceIgniteClient
- 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 interfaceIgniteClient
- 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 interfaceIgniteClient
- 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 interfaceIgniteClient
- 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 interfaceIgniteClient
- Type Parameters:
K
- Type of the cache key.V
- Type of the cache value.- Parameters:
name
- Cache name.- Returns:
- Client cache instance.
-
cacheNames
public Collection<String> cacheNames() throws ClientException
Gets the names of all available caches.- Specified by:
cacheNames
in interfaceIgniteClient
- Returns:
- Collection of names of currently available caches or an empty collection if no caches are available.
- Throws:
ClientException
-
cacheNamesAsync
public IgniteClientFuture<Collection<String>> cacheNamesAsync() throws ClientException
Gets the names of all available caches.- Specified by:
cacheNamesAsync
in interfaceIgniteClient
- Returns:
- a Future representing pending completion of the operation, which wraps the Ńollection of names of currently available caches or an empty collection if no caches are available.
- Throws:
ClientException
-
destroyCache
public void destroyCache(String name) throws ClientException
Destroys the cache with the given name. ThrowsClientException
if the cache does not exist.- Specified by:
destroyCache
in interfaceIgniteClient
- Parameters:
name
- Name of the cache to destroy.- Throws:
ClientException
-
destroyCacheAsync
public IgniteClientFuture<Void> destroyCacheAsync(String name) throws ClientException
Destroys the cache with the given name. ThrowsClientException
if the cache does not exist.- Specified by:
destroyCacheAsync
in interfaceIgniteClient
- Parameters:
name
- Name of the cache to destroy.- Returns:
- a Future representing pending completion of the operation.
- Throws:
ClientException
-
createCache
public <K,V> ClientCache<K,V> createCache(String name) throws ClientException
Creates a cache with a default configuration.- Specified by:
createCache
in interfaceIgniteClient
- 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 interfaceIgniteClient
- 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
-
createCache
public <K,V> ClientCache<K,V> createCache(ClientCacheConfiguration cfg) throws ClientException
Creates a cache with the specified configuration.- Specified by:
createCache
in interfaceIgniteClient
- Type Parameters:
K
- Type of the cache key.V
- Type of the cache value.- Parameters:
cfg
- Cache configuration.- Returns:
- Resulting cache.
- Throws:
ClientException
-
createCacheAsync
public <K,V> IgniteClientFuture<ClientCache<K,V>> createCacheAsync(ClientCacheConfiguration cfg) throws ClientException
Creates a cache with the specified configuration.- Specified by:
createCacheAsync
in interfaceIgniteClient
- Type Parameters:
K
- Type of the cache key.V
- Type of the cache value.- Parameters:
cfg
- Cache configuration.- Returns:
- a Future representing pending completion of the operation, which wraps the resulting cache.
- Throws:
ClientException
-
binary
public IgniteBinary binary()
- Specified by:
binary
in interfaceIgniteClient
- Returns:
- Instance of
IgniteBinary
interface.
-
query
public FieldsQueryCursor<List<?>> query(SqlFieldsQuery qry)
Execute SQL query and get cursor to iterate over results.- Specified by:
query
in interfaceIgniteClient
- Parameters:
qry
- SQL query.- Returns:
- Cursor.
-
transactions
public ClientTransactions transactions()
Gets client transactions facade.- Specified by:
transactions
in interfaceIgniteClient
- Returns:
- Client transactions facade.
-
compute
public ClientCompute compute()
Gets compute facade over all cluster nodes started in server mode.- Specified by:
compute
in interfaceIgniteClient
- 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 returnedClientCompute
instance will only include nodes from this cluster group.- Specified by:
compute
in interfaceIgniteClient
- Parameters:
grp
- Cluster group.- Returns:
- Compute instance over given cluster group.
-
cluster
public ClientCluster cluster()
Gets client cluster facade.- Specified by:
cluster
in interfaceIgniteClient
- Returns:
- Client cluster facade.
-
services
public ClientServices services()
Getsservices
facade over all cluster nodes started in server mode.- Specified by:
services
in interfaceIgniteClient
- Returns:
- Services facade over all cluster nodes started in server mode.
-
services
public ClientServices services(ClientClusterGroup grp)
Getsservices
facade over nodes within the cluster group. All operations on the returnedClientServices
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 interfaceIgniteClient
- 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 andcreate
flag istrue
.- Specified by:
atomicLong
in interfaceIgniteClient
- Parameters:
name
- Name of atomic long.initVal
- Initial value for atomic long. Ignored ifcreate
flag isfalse
.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 andcreate
flag istrue
.- Specified by:
atomicLong
in interfaceIgniteClient
- Parameters:
name
- Name of atomic long.cfg
- Configuration.initVal
- Initial value for atomic long. Ignored ifcreate
flag isfalse
.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 andcfg
is notnull
.- Specified by:
set
in interfaceIgniteClient
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceIgniteClient
-
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)
SetsSmartLifecycle
phase during which the current bean will be initialized. Note, underlying Ignite client will be closed during handling ofDisposableBean
sinceIgniteClient
implementsAutoCloseable
interface.- Parameters:
phase
-SmartLifecycle
phase.- Returns:
this
for chaining.
-
-