Class StandaloneSpiContext
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneSpiContext
-
- All Implemented Interfaces:
IgniteSpiContext
public class StandaloneSpiContext extends Object implements IgniteSpiContext
Dummy SPI context for offline utilities.
-
-
Constructor Summary
Constructors Constructor Description StandaloneSpiContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLocalEventListener(GridLocalEventListener lsnr, int... types)Adds an event listener for local events.voidaddLocalMessageListener(Object topic, IgniteBiPredicate<UUID,?> p)Register an local message listener to receive messages sent by remote nodes.voidaddMessageListener(GridMessageListener lsnr, String topic)Register a message listener to receive messages sent by remote nodes.voidaddMetricRegistryCreationListener(Consumer<ReadOnlyMetricRegistry> lsnr)Register listener which will be notified on metric registry creation.voidaddTimeoutObject(IgniteSpiTimeoutObject obj)SecuritySubjectauthenticatedSubject(UUID subjId)Gets security subject based on subject ID.Collection<SecuritySubject>authenticatedSubjects()Gets collection of authenticated subjects together with their permissions.booleancommunicationFailureResolveSupported()<K> booleancontainsKey(String cacheName, K key)Returnstrueif this cache contains a mapping for the specified key.voidderegisterPort(int port, IgnitePortProtocol proto)Deregisters closed port.voidderegisterPorts()Deregisters all closed ports.voidfailNode(UUID nodeId, @Nullable String warning)<K,V>
Vget(String cacheName, K key)Gets object from cache.ReadOnlyMetricRegistrygetOrCreateMetricRegistry(String name)Returns existing or newly created instance of metric registry with given name.booleanisEventRecordable(int... types)Checks whether all provided event types are recordable.booleanisStopping()ClusterNodelocalNode()Gets local grid node.MessageFactorymessageFactory()Gets message factory.MessageFormattermessageFormatter()Gets message formatter.Iterable<ReadOnlyMetricRegistry>metricRegistries()Returns all registered metric registries.@Nullable ClusterNodenode(UUID nodeId)Gets a node instance based on its ID.Map<String,Object>nodeAttributes()Collection<ClusterNode>nodes()Gets a collection of all grid nodes.intpartition(String cacheName, Object key)Calculates partition number for given key.booleanpingNode(UUID nodeId)Pings a remote node.<K,V>
Vput(String cacheName, K key, V val, long ttl)Puts object in cache.<K,V>
VputIfAbsent(String cacheName, K key, V val, long ttl)Puts object into cache if there was no previous object associated with given key.voidrecordEvent(Event evt)Records local event.voidregisterPort(int port, IgnitePortProtocol proto)Registers open port.Collection<ClusterNode>remoteNodes()Gets a collection of remote grid nodes.<K,V>
Vremove(String cacheName, K key)Removes object from cache.booleanremoveLocalEventListener(GridLocalEventListener lsnr)Removes local event listener.voidremoveLocalMessageListener(Object topic, IgniteBiPredicate<UUID,?> p)Removes a previously registered local message listener.booleanremoveMessageListener(GridMessageListener lsnr, String topic)Removes a previously registered message listener.voidremoveMetricRegistry(String name)Removes metric registry with given name.voidremoveTimeoutObject(IgniteSpiTimeoutObject obj)voidresolveCommunicationFailure(ClusterNode node, Exception err)voidsend(ClusterNode node, Serializable msg, String topic)Sends a message to a remote node.booleantryFailNode(UUID nodeId, @Nullable String warning)@Nullable IgniteNodeValidationResultvalidateNode(ClusterNode node)Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.@Nullable IgniteNodeValidationResultvalidateNode(ClusterNode node, DiscoveryDataBag discoData)
-
-
-
Method Detail
-
addLocalEventListener
public void addLocalEventListener(GridLocalEventListener lsnr, int... types)
Adds an event listener for local events.- Specified by:
addLocalEventListenerin interfaceIgniteSpiContext- Parameters:
lsnr- Event listener for local events.types- Optional types for which this listener will be notified. If no types are provided this listener will be notified for all local events.- See Also:
Event
-
addMessageListener
public void addMessageListener(GridMessageListener lsnr, String topic)
Register a message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined byCommunicationSpiimplementation used.This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can send messages by calling
IgniteSpiContext.send(org.apache.ignite.cluster.ClusterNode, Serializable, String)method.- Specified by:
addMessageListenerin interfaceIgniteSpiContext- Parameters:
lsnr- Message listener to register.topic- Topic to register listener for.
-
addLocalMessageListener
public void addLocalMessageListener(Object topic, IgniteBiPredicate<UUID,?> p)
Register an local message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined byCommunicationSpiimplementation used.- Specified by:
addLocalMessageListenerin interfaceIgniteSpiContext- Parameters:
topic- Topic to subscribe to.p- Message predicate.
-
recordEvent
public void recordEvent(Event evt)
Records local event.- Specified by:
recordEventin interfaceIgniteSpiContext- Parameters:
evt- Local grid event to record.
-
registerPort
public void registerPort(int port, IgnitePortProtocol proto)Registers open port.- Specified by:
registerPortin interfaceIgniteSpiContext- Parameters:
port- Port.proto- Protocol.
-
deregisterPort
public void deregisterPort(int port, IgnitePortProtocol proto)Deregisters closed port.- Specified by:
deregisterPortin interfaceIgniteSpiContext- Parameters:
port- Port.proto- Protocol.
-
deregisterPorts
public void deregisterPorts()
Deregisters all closed ports.- Specified by:
deregisterPortsin interfaceIgniteSpiContext
-
get
public <K,V> V get(String cacheName, K key)
Gets object from cache.- Specified by:
getin interfaceIgniteSpiContext- Type Parameters:
K- Key type.V- Value type.- Parameters:
cacheName- Cache name.key- Object key.- Returns:
- Cached object.
-
put
public <K,V> V put(String cacheName, K key, V val, long ttl)
Puts object in cache.- Specified by:
putin interfaceIgniteSpiContext- Type Parameters:
K- Key type.V- Value type.- Parameters:
cacheName- Cache name.key- Object key.val- Cached object.ttl- Time to live,0means the entry will never expire.- Returns:
- Previous value associated with specified key, possibly
null.
-
putIfAbsent
public <K,V> V putIfAbsent(String cacheName, K key, V val, long ttl)
Puts object into cache if there was no previous object associated with given key.- Specified by:
putIfAbsentin interfaceIgniteSpiContext- Type Parameters:
K- Cache key type.V- Cache value type.- Parameters:
cacheName- Cache name.key- Cache key.val- Cache value.ttl- Time to live.- Returns:
- Either existing value or
nullif there was no value for given key.
-
remove
public <K,V> V remove(String cacheName, K key)
Removes object from cache.- Specified by:
removein interfaceIgniteSpiContext- Type Parameters:
K- Key type.V- Value type.- Parameters:
cacheName- Cache name.key- Object key.- Returns:
- Previous value associated with specified key, possibly
null.
-
containsKey
public <K> boolean containsKey(String cacheName, K key)
Returnstrueif this cache contains a mapping for the specified key.- Specified by:
containsKeyin interfaceIgniteSpiContext- Type Parameters:
K- Key type.- Parameters:
cacheName- Cache name.key- Object key.- Returns:
trueif this cache contains a mapping for the specified key.
-
partition
public int partition(String cacheName, Object key)
Calculates partition number for given key.- Specified by:
partitionin interfaceIgniteSpiContext- Parameters:
cacheName- Cache name.key- Key.- Returns:
- Partition.
-
nodes
public Collection<ClusterNode> nodes()
Gets a collection of all grid nodes. Remote nodes are discovered via underlyingDiscoverySpiimplementation used. UnlikeIgniteSpiContext.remoteNodes(), this method does include local grid node.- Specified by:
nodesin interfaceIgniteSpiContext- Returns:
- Collection of remote grid nodes.
- See Also:
IgniteSpiContext.localNode(),IgniteSpiContext.remoteNodes(),DiscoverySpi
-
localNode
public ClusterNode localNode()
Gets local grid node. Instance of local node is provided by underlyingDiscoverySpiimplementation used.- Specified by:
localNodein interfaceIgniteSpiContext- Returns:
- Local grid node.
- See Also:
DiscoverySpi
-
node
@Nullable public @Nullable ClusterNode node(UUID nodeId)
Gets a node instance based on its ID.- Specified by:
nodein interfaceIgniteSpiContext- Parameters:
nodeId- ID of a node to get.- Returns:
- Node for a given ID or
nullis such not has not been discovered. - See Also:
DiscoverySpi
-
remoteNodes
public Collection<ClusterNode> remoteNodes()
Gets a collection of remote grid nodes. Remote nodes are discovered via underlyingDiscoverySpiimplementation used. UnlikeIgniteSpiContext.nodes(), this method does not include local grid node.- Specified by:
remoteNodesin interfaceIgniteSpiContext- Returns:
- Collection of remote grid nodes.
- See Also:
IgniteSpiContext.localNode(),IgniteSpiContext.nodes(),DiscoverySpi
-
pingNode
public boolean pingNode(UUID nodeId)
Pings a remote node. The underlying communication is provided viaDiscoverySpi.pingNode(UUID)implementation.Discovery SPIs usually have some latency in discovering failed nodes. Hence, communication to remote nodes may fail at times if an attempt was made to establish communication with a failed node. This method can be used to check if communication has failed due to node failure or due to some other reason.
- Specified by:
pingNodein interfaceIgniteSpiContext- Parameters:
nodeId- ID of a node to ping.- Returns:
trueif node for a given ID is alive,falseotherwise.- See Also:
DiscoverySpi
-
removeLocalEventListener
public boolean removeLocalEventListener(GridLocalEventListener lsnr)
Removes local event listener.- Specified by:
removeLocalEventListenerin interfaceIgniteSpiContext- Parameters:
lsnr- Local event listener to remove.- Returns:
trueif listener was removed,falseotherwise.
-
isEventRecordable
public boolean isEventRecordable(int... types)
Checks whether all provided event types are recordable.- Specified by:
isEventRecordablein interfaceIgniteSpiContext- Parameters:
types- Event types to check.- Returns:
- Whether or not all provided event types are recordable..
-
removeLocalMessageListener
public void removeLocalMessageListener(Object topic, IgniteBiPredicate<UUID,?> p)
Removes a previously registered local message listener.- Specified by:
removeLocalMessageListenerin interfaceIgniteSpiContext- Parameters:
topic- Topic to unsubscribe from.p- Message predicate.
-
removeMessageListener
public boolean removeMessageListener(GridMessageListener lsnr, String topic)
Removes a previously registered message listener.- Specified by:
removeMessageListenerin interfaceIgniteSpiContext- Parameters:
lsnr- Message listener to remove.topic- Topic to unregister listener for.- Returns:
trueof message listener was removed,falseif it was not previously registered.
-
send
public void send(ClusterNode node, Serializable msg, String topic)
Sends a message to a remote node. The underlying communication mechanism is defined byCommunicationSpiimplementation used.- Specified by:
sendin interfaceIgniteSpiContext- Parameters:
node- Node to send a message to.msg- Message to send.topic- Topic to send message to.
-
validateNode
@Nullable public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node)
Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.- Specified by:
validateNodein interfaceIgniteSpiContext- Parameters:
node- Joining node.- Returns:
- Validation result or
nullin case of success.
-
validateNode
@Nullable public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node, DiscoveryDataBag discoData)
- Specified by:
validateNodein interfaceIgniteSpiContext- Parameters:
node- Node.discoData- Disco data.- Returns:
- Validation result or
nullin case of success.
-
authenticatedSubjects
public Collection<SecuritySubject> authenticatedSubjects()
Gets collection of authenticated subjects together with their permissions.- Specified by:
authenticatedSubjectsin interfaceIgniteSpiContext- Returns:
- Collection of authenticated subjects.
-
authenticatedSubject
public SecuritySubject authenticatedSubject(UUID subjId)
Gets security subject based on subject ID.- Specified by:
authenticatedSubjectin interfaceIgniteSpiContext- Parameters:
subjId- Subject ID.- Returns:
- Authorized security subject.
-
messageFormatter
public MessageFormatter messageFormatter()
Gets message formatter.- Specified by:
messageFormatterin interfaceIgniteSpiContext- Returns:
- Message formatter.
-
messageFactory
public MessageFactory messageFactory()
Gets message factory.- Specified by:
messageFactoryin interfaceIgniteSpiContext- Returns:
- Message factory.
-
isStopping
public boolean isStopping()
- Specified by:
isStoppingin interfaceIgniteSpiContext- Returns:
Trueif node started shutdown sequence.
-
tryFailNode
public boolean tryFailNode(UUID nodeId, @Nullable @Nullable String warning)
- Specified by:
tryFailNodein interfaceIgniteSpiContext- Parameters:
nodeId- Node ID.warning- Warning to be shown on all cluster nodes.- Returns:
- If node was failed.
-
failNode
public void failNode(UUID nodeId, @Nullable @Nullable String warning)
- Specified by:
failNodein interfaceIgniteSpiContext- Parameters:
nodeId- Node ID.warning- Warning to be shown on all cluster nodes.
-
addTimeoutObject
public void addTimeoutObject(IgniteSpiTimeoutObject obj)
- Specified by:
addTimeoutObjectin interfaceIgniteSpiContext- Parameters:
obj- Timeout object.
-
removeTimeoutObject
public void removeTimeoutObject(IgniteSpiTimeoutObject obj)
- Specified by:
removeTimeoutObjectin interfaceIgniteSpiContext- Parameters:
obj- Timeout object.
-
nodeAttributes
public Map<String,Object> nodeAttributes()
- Specified by:
nodeAttributesin interfaceIgniteSpiContext- Returns:
- Current node attributes.
-
communicationFailureResolveSupported
public boolean communicationFailureResolveSupported()
- Specified by:
communicationFailureResolveSupportedin interfaceIgniteSpiContext- Returns:
Trueif cluster supports communication error resolving.
-
resolveCommunicationFailure
public void resolveCommunicationFailure(ClusterNode node, Exception err)
- Specified by:
resolveCommunicationFailurein interfaceIgniteSpiContext- Parameters:
node- Problem node.err- Error.
-
getOrCreateMetricRegistry
public ReadOnlyMetricRegistry getOrCreateMetricRegistry(String name)
Returns existing or newly created instance of metric registry with given name.- Specified by:
getOrCreateMetricRegistryin interfaceIgniteSpiContext- Parameters:
name- Metric registry name.- Returns:
- Existing or newly created instance of metric registry.
-
removeMetricRegistry
public void removeMetricRegistry(String name)
Removes metric registry with given name.- Specified by:
removeMetricRegistryin interfaceIgniteSpiContext- Parameters:
name- Metric registry name.
-
metricRegistries
public Iterable<ReadOnlyMetricRegistry> metricRegistries()
Returns all registered metric registries.- Specified by:
metricRegistriesin interfaceIgniteSpiContext- Returns:
- All registered metric registries.
-
addMetricRegistryCreationListener
public void addMetricRegistryCreationListener(Consumer<ReadOnlyMetricRegistry> lsnr)
Register listener which will be notified on metric registry creation.- Specified by:
addMetricRegistryCreationListenerin interfaceIgniteSpiContext- Parameters:
lsnr- Listener.
-
-