Package org.apache.ignite.spi
Class IgniteSpiAdapter
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- All Implemented Interfaces:
IgniteSpi
- Direct Known Subclasses:
AdaptiveLoadBalancingSpi,AlwaysFailoverSpi,CacheCheckpointSpi,FifoQueueCollisionSpi,IsolatedDiscoverySpi,JdbcCheckpointSpi,JmxMetricExporterSpi,JobStealingCollisionSpi,JobStealingFailoverSpi,KeystoreEncryptionSpi,LocalDeploymentSpi,MemoryEventStorageSpi,NeverFailoverSpi,NoopCheckpointSpi,NoopCollisionSpi,NoopEncryptionSpi,NoopEventStorageSpi,NoopIndexingSpi,NoopMetricExporterSpi,NoopTracingSpi,OpenCensusTracingSpi,PriorityQueueCollisionSpi,org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter,RoundRobinLoadBalancingSpi,SharedFsCheckpointSpi,org.apache.ignite.spi.communication.tcp.internal.TcpCommunicationConfigInitializer,TcpDiscoverySpi,UriDeploymentSpi,WeightedRandomLoadBalancingSpi,ZookeeperDiscoverySpi
public abstract class IgniteSpiAdapter extends Object implements IgniteSpi
This class provides convenient adapter for SPI implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected IgniteigniteIgnite instance.protected StringigniteInstanceNameIgnite instance name.protected IgniteLoggerlog
-
Constructor Summary
Constructors Modifier Constructor Description protectedIgniteSpiAdapter()Creates new adapter and initializes it from the current (this) class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddTimeoutObject(IgniteSpiTimeoutObject obj)protected voidassertParameter(boolean cond, String condDesc)Throws exception with uniform error message if given parameter's assertion condition isfalse.protected voidcheckConfigurationConsistency0(IgniteSpiContext spiCtx, ClusterNode node, boolean starting)Method which is called in the end of checkConfigurationConsistency() method.longclientFailureDetectionTimeout()Returns client failure detection timeout set to use for network related operations.protected StringconfigInfo(String name, Object val)Gets uniformed string for configuration parameter.protected StringcreateSpiAttributeName(String attrName)Creates new name for the given attribute.longfailureDetectionTimeout()Returns failure detection timeout set to use for network related operations.booleanfailureDetectionTimeoutEnabled()Checks whether failure detection timeout is enabled for thisIgniteSpi.voidfailureDetectionTimeoutEnabled(boolean enabled)Enables or disables failure detection timeout.protected List<String>getConsistentAttributeNames()Returns back a list of attributes that should be consistent for this SPI.org.apache.ignite.internal.util.IgniteExceptionRegistrygetExceptionRegistry()Gets Exception registry.protected ClusterNodegetLocalNode()StringgetName()Gets SPI name.Map<String,Object>getNodeAttributes()This method is called before SPI starts (before methodIgniteSpi.spiStart(String)is called).IgniteSpiContextgetSpiContext()Gets SPI context.Igniteignite()Gets ignite instance.protected voidinitFailureDetectionTimeout()Initiates and checks failure detection timeout value.Collection<Object>injectables()This method returns SPI internal instances that need to be injected as well.protected voidinjectResources(Ignite ignite)Inject ignite instance.protected booleanisNodeStopping()voidonBeforeStart()This method is called by built-in managers implementation to avoid repeating SPI start attempts.voidonClientDisconnected(IgniteFuture<?> reconnectFut)Client node disconnected callback.voidonClientReconnected(boolean clusterRestarted)Client node reconnected callback.voidonContextDestroyed()Callback invoked prior to stopping grid before SPI context is destroyed.protected voidonContextDestroyed0()Method to be called in the beginning of onContextDestroyed() method.voidonContextInitialized(IgniteSpiContext spiCtx)Callback invoked when SPI context is initialized.protected voidonContextInitialized0(IgniteSpiContext spiCtx)Method to be called in the end of onContextInitialized method.protected <T extends IgniteSpiManagementMBean>
voidregisterMBean(String igniteInstanceName, T impl, Class<T> mbeanItf)Registers SPI MBean.protected voidremoveTimeoutObject(IgniteSpiTimeoutObject obj)IgniteSpiAdaptersetName(String name)Sets SPI name.booleanstarted()Checks ifonBeforeStart()has been called on this SPI instance.protected StringstartInfo()Gets uniformly formatted message for SPI start.protected voidstartStopwatch()Starts startup stopwatch.protected StringstopInfo()Gets uniformly format message for SPI stop.protected voidunregisterMBean()Unregisters MBean.
-
-
-
Field Detail
-
log
@LoggerResource protected IgniteLogger log
-
ignite
protected Ignite ignite
Ignite instance.
-
igniteInstanceName
protected String igniteInstanceName
Ignite instance name.
-
-
Constructor Detail
-
IgniteSpiAdapter
protected IgniteSpiAdapter()
Creates new adapter and initializes it from the current (this) class. SPI name will be initialized to the simple name of the class (seeClass.getSimpleName()).
-
-
Method Detail
-
startStopwatch
protected void startStopwatch()
Starts startup stopwatch.
-
onBeforeStart
public final void onBeforeStart()
This method is called by built-in managers implementation to avoid repeating SPI start attempts.
-
started
public final boolean started()
Checks ifonBeforeStart()has been called on this SPI instance.- Returns:
TrueifonBeforeStart()has already been called.
-
getLocalNode
protected ClusterNode getLocalNode()
- Returns:
- Local node.
-
getName
public String getName()
Gets SPI name.
-
ignite
public Ignite ignite()
Gets ignite instance.- Returns:
- Ignite instance.
-
setName
@IgniteSpiConfiguration(optional=true) public IgniteSpiAdapter setName(String name)
Sets SPI name.- Parameters:
name- SPI name.- Returns:
thisfor chaining.
-
onContextInitialized
public final void onContextInitialized(IgniteSpiContext spiCtx) throws IgniteSpiException
Callback invoked when SPI context is initialized. SPI implementation may store SPI context for future access.This method is invoked after
IgniteSpi.spiStart(String)method is completed, so SPI should be fully functional at this point. Use this method for post-start initialization, such as subscribing a discovery listener, sending a message to remote node, etc...- Specified by:
onContextInitializedin interfaceIgniteSpi- Parameters:
spiCtx- Spi context.- Throws:
IgniteSpiException- If context initialization failed (grid will be stopped).
-
onContextInitialized0
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException
Method to be called in the end of onContextInitialized method.- Parameters:
spiCtx- SPI context.- Throws:
IgniteSpiException- In case of errors.
-
onContextDestroyed
public final void onContextDestroyed()
Callback invoked prior to stopping grid before SPI context is destroyed. Once this method is complete, grid will begin shutdown sequence. Use this callback for de-initialization logic that may involve SPI context. Note that invoking SPI context after this callback is complete is considered illegal and may produce unknown results.If
IgniteSpiAdapteris used for SPI implementation, then it will replace actual context with dummy no-op context which is usually good-enough since grid is about to shut down.- Specified by:
onContextDestroyedin interfaceIgniteSpi
-
onClientDisconnected
public void onClientDisconnected(IgniteFuture<?> reconnectFut)
Client node disconnected callback.- Specified by:
onClientDisconnectedin interfaceIgniteSpi- Parameters:
reconnectFut- Future that will be completed when client reconnected.
-
onClientReconnected
public void onClientReconnected(boolean clusterRestarted)
Client node reconnected callback.- Specified by:
onClientReconnectedin interfaceIgniteSpi- Parameters:
clusterRestarted-Trueif all cluster nodes restarted while client was disconnected.
-
injectResources
@IgniteInstanceResource protected void injectResources(Ignite ignite)
Inject ignite instance.- Parameters:
ignite- Ignite instance.
-
onContextDestroyed0
protected void onContextDestroyed0()
Method to be called in the beginning of onContextDestroyed() method.
-
injectables
public Collection<Object> injectables()
This method returns SPI internal instances that need to be injected as well. Usually these will be instances provided to SPI externally by user, e.g. during SPI configuration.- Returns:
- Internal SPI objects that also need to be injected.
-
getSpiContext
public IgniteSpiContext getSpiContext()
Gets SPI context.- Returns:
- SPI context.
-
getExceptionRegistry
public org.apache.ignite.internal.util.IgniteExceptionRegistry getExceptionRegistry()
Gets Exception registry.- Returns:
- Exception registry.
-
getNodeAttributes
public Map<String,Object> getNodeAttributes() throws IgniteSpiException
This method is called before SPI starts (before methodIgniteSpi.spiStart(String)is called). It allows SPI implementation to add attributes to a local node. Kernal collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.- Specified by:
getNodeAttributesin interfaceIgniteSpi- Returns:
- Map of local node attributes this SPI wants to add.
- Throws:
IgniteSpiException- Throws in case of any error.
-
assertParameter
protected final void assertParameter(boolean cond, String condDesc) throws IgniteSpiExceptionThrows exception with uniform error message if given parameter's assertion condition isfalse.- Parameters:
cond- Assertion condition to check.condDesc- Description of failed condition. Note that this description should include JavaBean name of the property (not a variable name) as well condition in Java syntax like, for example:... assertParameter(dirPath != null, "dirPath != null"); ...Note that in case when variable name is the same as JavaBean property you can just copy Java condition expression into description as a string.- Throws:
IgniteSpiException- Thrown if given condition isfalse
-
startInfo
protected final String startInfo()
Gets uniformly formatted message for SPI start.- Returns:
- Uniformly formatted message for SPI start.
-
stopInfo
protected final String stopInfo()
Gets uniformly format message for SPI stop.- Returns:
- Uniformly format message for SPI stop.
-
configInfo
protected final String configInfo(String name, Object val)
Gets uniformed string for configuration parameter.- Parameters:
name- Parameter name.val- Parameter value.- Returns:
- Uniformed string for configuration parameter.
-
registerMBean
protected final <T extends IgniteSpiManagementMBean> void registerMBean(String igniteInstanceName, T impl, Class<T> mbeanItf) throws IgniteSpiException
Registers SPI MBean. Note that SPI can only register one MBean.- Type Parameters:
T- Type of the MBean- Parameters:
igniteInstanceName- Ignite instance name. If null, then name will be empty.impl- MBean implementation.mbeanItf- MBean interface (ifnull, then standard JMX naming conventions are used.- Throws:
IgniteSpiException- If registration failed.
-
unregisterMBean
protected final void unregisterMBean() throws IgniteSpiExceptionUnregisters MBean.- Throws:
IgniteSpiException- If bean could not be unregistered.
-
isNodeStopping
protected final boolean isNodeStopping()
- Returns:
Trueif node is stopping.
-
checkConfigurationConsistency0
protected void checkConfigurationConsistency0(IgniteSpiContext spiCtx, ClusterNode node, boolean starting) throws IgniteSpiException
Method which is called in the end of checkConfigurationConsistency() method. May be overriden in SPIs.- Parameters:
spiCtx- SPI context.node- Remote node.starting- If this node is starting or not.- Throws:
IgniteSpiException- in case of errors.
-
getConsistentAttributeNames
protected List<String> getConsistentAttributeNames()
Returns back a list of attributes that should be consistent for this SPI. Consistency means that remote node has to have the same attribute with the same value.- Returns:
- List or attribute names.
-
createSpiAttributeName
protected String createSpiAttributeName(String attrName)
Creates new name for the given attribute. Name contains SPI name prefix.- Parameters:
attrName- SPI attribute name.- Returns:
- New name with SPI name prefix.
-
addTimeoutObject
protected void addTimeoutObject(IgniteSpiTimeoutObject obj)
- Parameters:
obj- Timeout object.- See Also:
IgniteSpiContext.addTimeoutObject(IgniteSpiTimeoutObject)
-
removeTimeoutObject
protected void removeTimeoutObject(IgniteSpiTimeoutObject obj)
- Parameters:
obj- Timeout object.- See Also:
IgniteSpiContext.removeTimeoutObject(IgniteSpiTimeoutObject)
-
initFailureDetectionTimeout
protected void initFailureDetectionTimeout()
Initiates and checks failure detection timeout value.
-
failureDetectionTimeoutEnabled
public void failureDetectionTimeoutEnabled(boolean enabled)
Enables or disables failure detection timeout.- Parameters:
enabled-trueif enable,falseotherwise.
-
failureDetectionTimeoutEnabled
public boolean failureDetectionTimeoutEnabled()
Checks whether failure detection timeout is enabled for thisIgniteSpi.- Returns:
trueif enabled,falseotherwise.
-
clientFailureDetectionTimeout
public long clientFailureDetectionTimeout()
Returns client failure detection timeout set to use for network related operations.- Returns:
- client failure detection timeout in milliseconds or
0if the timeout is disabled.
-
failureDetectionTimeout
public long failureDetectionTimeout()
Returns failure detection timeout set to use for network related operations.- Returns:
- failure detection timeout in milliseconds or
0if the timeout is disabled.
-
-