├── .gitignore ├── README.adoc ├── pom.xml └── src ├── main ├── asciidoc │ └── java │ │ └── index.adoc ├── java │ ├── examples │ │ ├── Examples.java │ │ └── package-info.java │ └── io │ │ └── vertx │ │ └── spi │ │ └── cluster │ │ └── ignite │ │ ├── IgniteClusterManager.java │ │ ├── impl │ │ ├── AsyncMapImpl.java │ │ ├── AsyncMultiMapImpl.java │ │ ├── ChoosableIterableImpl.java │ │ └── MapImpl.java │ │ └── package-info.java └── resources │ ├── META-INF │ └── services │ │ └── io.vertx.core.spi.cluster.ClusterManager │ └── default-ignite.xml └── test ├── java └── io │ └── vertx │ └── test │ └── core │ ├── IgniteAsyncMultiMapTest.java │ ├── IgniteClusterWideMapTest.java │ ├── IgniteClusteredEventbusTest.java │ ├── IgniteClusteredSharedCounterTest.java │ ├── IgniteComplexHATest.java │ ├── IgniteHATest.java │ └── IgnitesClusteredAsynchronousLockTest.java └── resources ├── ignite.xml └── vertx-default-jul-logging.properties.t /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .gradle 3 | .idea 4 | .classpath 5 | .project 6 | .settings 7 | .yardoc 8 | .yardopts 9 | build 10 | target 11 | out 12 | *.iml 13 | *.ipr 14 | *.iws 15 | .vertx 16 | test-output 17 | src/scratchpad 18 | test-results 19 | test-tmp 20 | *.class 21 | *.swp 22 | 23 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | *NOTE:* Project is part of Vert.x stack now and code base is moved to 2 | https://github.com/vert-x3/vertx-ignite[vertx-ignite] repository under https://github.com/vert-x3[vert-x3] 3 | organization. 4 | 5 | = Apache Ignite Cluster Manager 6 | 7 | This is a cluster manager implementation for Vert.x that uses http://ignite.apache.org/index.html[Apache Ignite]. 8 | 9 | Vert.x cluster manager is pluggable component. So you can replace default Vert.x cluster manager by this implementation. 10 | 11 | Please see the in source asciidoc documentation or the main documentation on the web-site for a full description 12 | of this component: 13 | 14 | * Web-site docs 15 | * link:src/main/asciidoc/java/index.adoc[in-source docs] 16 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.vertx 9 | vertx-ext-parent 10 | 20 11 | 12 | 13 | vertx-ignite 14 | 3.2.1 15 | 16 | Vert.x Ignite Cluster Manager 17 | 18 | 19 | 3.2.1 20 | 1.5.0.final 21 | 22 | ${project.basedir}/src/main/asciidoc 23 | 24 | 25 | 26 | 27 | 28 | io.vertx 29 | vertx-dependencies 30 | ${stack.version} 31 | pom 32 | import 33 | 34 | 35 | 36 | 37 | 38 | 39 | io.vertx 40 | vertx-core 41 | 42 | 43 | org.apache.ignite 44 | ignite-core 45 | ${ignite.version} 46 | 47 | 48 | org.apache.ignite 49 | ignite-spring 50 | ${ignite.version} 51 | 52 | 53 | org.springframework 54 | spring-aop 55 | 56 | 57 | org.springframework 58 | spring-tx 59 | 60 | 61 | org.springframework 62 | spring-jdbc 63 | 64 | 65 | 66 | 67 | 68 | io.vertx 69 | vertx-docgen 70 | provided 71 | 72 | 73 | io.vertx 74 | vertx-codetrans 75 | provided 76 | 77 | 78 | io.vertx 79 | vertx-codegen 80 | true 81 | 82 | 83 | io.vertx 84 | vertx-lang-groovy 85 | true 86 | 87 | 88 | io.vertx 89 | vertx-lang-ruby 90 | true 91 | 92 | 93 | io.vertx 94 | vertx-lang-js 95 | true 96 | 97 | 98 | io.vertx 99 | vertx-rx-java 100 | true 101 | 102 | 103 | 104 | junit 105 | junit 106 | 4.12 107 | test 108 | 109 | 110 | io.vertx 111 | vertx-core 112 | test-jar 113 | test 114 | 115 | 116 | 117 | 118 | 119 | 120 | maven-compiler-plugin 121 | 122 | 123 | default-compile 124 | 125 | 126 | io.vertx.docgen.JavaDocGenProcessor 127 | 128 | 129 | -Adocgen.output=${asciidoc.dir}/$lang 130 | -Amaven.groupId=${project.groupId} 131 | -Amaven.artifactId=${project.artifactId} 132 | -Amaven.version=${project.version} 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | org.apache.maven.plugins 141 | maven-surefire-plugin 142 | ${maven.surefire.plugin.version} 143 | 144 | false 145 | 146 | PARANOID 147 | ${project.build.directory} 148 | ${project.version} 149 | 150 | 151 | -Xmx4096M 152 | 1 153 | true 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /src/main/asciidoc/java/index.adoc: -------------------------------------------------------------------------------- 1 | = Apache Ignite Cluster Manager for Vert.x 2 | 3 | This is a cluster manager implementation for Vert.x that uses http://ignite.apache.org/index.html[Apache Ignite]. 4 | 5 | In Vert.x a cluster manager is used for various functions including: 6 | 7 | * Discovery and group membership of Vert.x nodes in a cluster 8 | * Maintaining cluster wide topic subscriber lists (so we know which nodes are interested in which event bus 9 | addresses) 10 | * Distributed Map support 11 | * Distributed Locks 12 | * Distributed Counters 13 | 14 | Cluster managers *do not* handle the event bus inter-node transport, this is done directly by Vert.x with TCP 15 | connections. 16 | 17 | Vert.x cluster manager is a pluggable component, so you can pick the one you want, or the one that is the most 18 | adapted to your environment. So you can replace default Vert.x cluster manager by this implementation. 19 | 20 | == Using Ignite cluster manager 21 | 22 | If the jar is on your classpath then Vert.x will automatically detect this and use it as the cluster manager. 23 | Please make sure you don’t have any other cluster managers on your classpath or Vert.x might choose the wrong one. 24 | 25 | Alternatively, you can configure the following system property to instruct vert.x to use this cluster manager: 26 | `-Dvertx.clusterManagerFactory=io.vertx.spi.cluster.ignite.IgniteClusterManager` 27 | 28 | ### Using Vert.x from command line 29 | 30 | `vertx-ignite-3.2.1.jar` should be in the `lib` directory of the Vert.x installation. 31 | 32 | ### Using Vert.x in Maven or Gradle project 33 | 34 | Add a dependency to the artifact. 35 | 36 | * Maven (in your `pom.xml`): 37 | 38 | [source,xml,subs="+attributes"] 39 | ---- 40 | 41 | io.vertx 42 | vertx-ignite 43 | 3.2.1 44 | 45 | ---- 46 | 47 | * Gradle (in your `build.gradle` file): 48 | 49 | [source,groovy,subs="+attributes"] 50 | ---- 51 | compile 'io.vertx:vertx-ignite:3.2.1' 52 | ---- 53 | 54 | ### Programmatically specifying cluster manager 55 | 56 | You can also specify the cluster manager programmatically. In order to do this just specify it on the options 57 | when you are creating your Vert.x instance, for example: 58 | 59 | [source,java] 60 | ---- 61 | ClusterManager clusterManager = new IgniteClusterManager(); 62 | 63 | VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 64 | Vertx.clusteredVertx(options, res -> { 65 | if (res.succeeded()) { 66 | Vertx vertx = res.result(); 67 | } else { 68 | // failed! 69 | } 70 | }); 71 | ---- 72 | 73 | == Configuring cluster manager 74 | 75 | === Using configuration file 76 | 77 | The cluster manager is configured by a file `default-ignite.xml` which is packaged inside the jar. 78 | 79 | If you want to override this configuration you can provide `ignite.xml` file on your classpath and this will be 80 | used instead. 81 | 82 | The xml file is a Ignite configuration file and is described in details in 83 | https://apacheignite.readme.io/docs[Apache Ignite documentation]. 84 | 85 | ### Configuring programmatically 86 | 87 | You can also specify configuration programmatically: 88 | 89 | [source,java] 90 | ---- 91 | IgniteConfiguration cfg = new IgniteConfiguration(); 92 | // Configuration code (omitted) 93 | 94 | ClusterManager clusterManager = new IgniteClusterManager(cfg); 95 | 96 | VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 97 | Vertx.clusteredVertx(options, res -> { 98 | if (res.succeeded()) { 99 | Vertx vertx = res.result(); 100 | } else { 101 | // failed! 102 | } 103 | }); 104 | ---- 105 | 106 | === Discovery and network transport configuration 107 | 108 | The default configuration uses `TcpDiscoveryMulticastIpFinder` so you must have multicast enabled on your network. 109 | For cases when multicast is disabled `TcpDiscoveryVmIpFinder` should be used with pre-configured list of IP addresses. 110 | Please see http://apacheignite.readme.io/docs/cluster-config[Cluster Configuration] section 111 | at Apache Ignite documentation for details. 112 | 113 | == Trouble shooting clustering 114 | 115 | If the default multicast configuration is not working here are some common causes: 116 | 117 | === Multicast not enabled on the machine. 118 | 119 | By default the cluster manager is using `TcpDiscoveryMulticastIpFinder`, so IP multicasting is required, 120 | on some systems, multicast route(s) need to be added to the routing table otherwise, the default route will be used. 121 | 122 | Note that some systems don't consult the routing table for IP multicast routing, only for unicast routing 123 | 124 | MacOS example: 125 | 126 | ---- 127 | # Adds a multicast route for 224.0.0.1-231.255.255.254 128 | sudo route add -net 224.0.0.0/5 127.0.0.1 129 | 130 | # Adds a multicast route for 232.0.0.1-239.255.255.254 131 | sudo route add -net 232.0.0.0/5 192.168.1.3 132 | ---- 133 | 134 | Please google for more information. 135 | 136 | === Using wrong network interface 137 | 138 | If you have more than one network interface on your machine (and this can also be the case if you are running 139 | VPN software on your machine), then Apache Ignite may be using the wrong one. 140 | 141 | To tell Ignite to use a specific interface you can provide the IP address of the interface to the 142 | bean of `IgniteConfiguration` type using `localHost` property. For example: 143 | 144 | ---- 145 | 146 | 147 | 148 | ---- 149 | 150 | When running Vert.x is in clustered mode, you should also make sure that Vert.x knows about the correct interface. 151 | When running at the command line this is done by specifying the `cluster-host` option: 152 | 153 | ---- 154 | vertx run myverticle.js -cluster -cluster-host your-ip-address 155 | ---- 156 | 157 | Where `your-ip-address` is the same IP address you specified in the Apache Ignite configuration. 158 | 159 | If using Vert.x programmatically you can specify this using `link:../../apidocs/io/vertx/core/VertxOptions.html#setClusterHost-java.lang.String-[setClusterHost]`. 160 | 161 | === Using a VPN 162 | 163 | This is a variation of the above case. VPN software often works by creating a virtual network interface which often 164 | doesn't support multicast. If you have a VPN running and you do not specify the correct interface to use in both the 165 | Ignite configuration and to Vert.x then the VPN interface may be chosen instead of the correct interface. 166 | 167 | So, if you have a VPN running you may have to configure both the Ignite and Vert.x to use the correct interface as 168 | described in the previous section. 169 | 170 | === When multicast is not available 171 | 172 | In some cases you may not be able to use multicast as it might not be available in your environment. In that case 173 | you should configure another transport using corresponding IP finder, e.g. `TcpDiscoveryVmIpFinder` to use TCP sockets, 174 | or `TcpDiscoveryS3IpFinder` to use Amazon S3. 175 | 176 | For more information on available Ignite transports and how to configure them please consult the 177 | https://apacheignite.readme.io/docs/clustering[Ignite Clustering] documentation. 178 | 179 | === Enabling logging 180 | 181 | When trouble-shooting clustering issues it's often useful to get some logging output from Ignite 182 | to see if it's forming a cluster properly. You can do this (when using the default JUL logging) by adding a file 183 | called `vertx-default-jul-logging.properties` on your classpath. This is a standard java.util.loging (JUL) 184 | configuration file. Inside it set: 185 | 186 | ---- 187 | org.apache.ignite.level=INFO 188 | ---- 189 | 190 | and also 191 | 192 | ---- 193 | java.util.logging.ConsoleHandler.level=INFO 194 | java.util.logging.FileHandler.level=INFO 195 | ---- -------------------------------------------------------------------------------- /src/main/java/examples/Examples.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import io.vertx.core.Vertx; 4 | import io.vertx.core.VertxOptions; 5 | import io.vertx.core.spi.cluster.ClusterManager; 6 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 7 | import org.apache.ignite.configuration.IgniteConfiguration; 8 | 9 | /** 10 | * @author Clement Escoffier 11 | */ 12 | public class Examples { 13 | 14 | public void example1() { 15 | ClusterManager clusterManager = new IgniteClusterManager(); 16 | 17 | VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 18 | Vertx.clusteredVertx(options, res -> { 19 | if (res.succeeded()) { 20 | Vertx vertx = res.result(); 21 | } else { 22 | // failed! 23 | } 24 | }); 25 | } 26 | 27 | public void example2() { 28 | IgniteConfiguration cfg = new IgniteConfiguration(); 29 | // Configuration code (omitted) 30 | 31 | ClusterManager clusterManager = new IgniteClusterManager(cfg); 32 | 33 | VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 34 | Vertx.clusteredVertx(options, res -> { 35 | if (res.succeeded()) { 36 | Vertx vertx = res.result(); 37 | } else { 38 | // failed! 39 | } 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | @Source 19 | package examples; 20 | 21 | import io.vertx.docgen.Source; -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/IgniteClusterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.spi.cluster.ignite; 19 | 20 | import io.vertx.core.AsyncResult; 21 | import io.vertx.core.Handler; 22 | import io.vertx.core.Vertx; 23 | import io.vertx.core.VertxException; 24 | import io.vertx.core.logging.Logger; 25 | import io.vertx.core.logging.LoggerFactory; 26 | import io.vertx.core.shareddata.AsyncMap; 27 | import io.vertx.core.shareddata.Counter; 28 | import io.vertx.core.shareddata.Lock; 29 | import io.vertx.core.spi.cluster.AsyncMultiMap; 30 | import io.vertx.core.spi.cluster.ClusterManager; 31 | import io.vertx.core.spi.cluster.NodeListener; 32 | import io.vertx.spi.cluster.ignite.impl.AsyncMapImpl; 33 | import io.vertx.spi.cluster.ignite.impl.AsyncMultiMapImpl; 34 | import io.vertx.spi.cluster.ignite.impl.MapImpl; 35 | import org.apache.ignite.Ignite; 36 | import org.apache.ignite.IgniteAtomicLong; 37 | import org.apache.ignite.IgniteCache; 38 | import org.apache.ignite.IgniteCheckedException; 39 | import org.apache.ignite.IgniteQueue; 40 | import org.apache.ignite.Ignition; 41 | import org.apache.ignite.cluster.ClusterNode; 42 | import org.apache.ignite.configuration.CacheConfiguration; 43 | import org.apache.ignite.configuration.CollectionConfiguration; 44 | import org.apache.ignite.configuration.IgniteConfiguration; 45 | import org.apache.ignite.events.DiscoveryEvent; 46 | import org.apache.ignite.internal.IgnitionEx; 47 | import org.apache.ignite.internal.util.typedef.F; 48 | 49 | import java.io.InputStream; 50 | import java.util.List; 51 | import java.util.Map; 52 | import java.util.Objects; 53 | import java.util.UUID; 54 | import java.util.concurrent.TimeUnit; 55 | import java.util.stream.Collectors; 56 | 57 | import static org.apache.ignite.events.EventType.*; 58 | 59 | /** 60 | * Apache Ignite based cluster manager. 61 | */ 62 | public class IgniteClusterManager implements ClusterManager { 63 | 64 | private static final Logger log = LoggerFactory.getLogger(IgniteClusterManager.class); 65 | 66 | // Default Ignite configuration file 67 | private static final String DEFAULT_CONFIG_FILE = "default-ignite.xml"; 68 | 69 | // User defined Ignite configuration file 70 | private static final String CONFIG_FILE = "ignite.xml"; 71 | 72 | public static final String VERTX_CACHE_TEMPLATE_NAME = "*"; 73 | 74 | private static final String VERTX_NODE_PREFIX = "vertx.ignite.node."; 75 | 76 | private Vertx vertx; 77 | 78 | private IgniteConfiguration cfg; 79 | private Ignite ignite; 80 | 81 | private String nodeID; 82 | private NodeListener nodeListener; 83 | 84 | private volatile boolean active; 85 | 86 | private final Object monitor = new Object(); 87 | 88 | private CollectionConfiguration collectionCfg; 89 | 90 | /** 91 | * Default constructor. Cluster manager will get configuration from classpath. 92 | */ 93 | @SuppressWarnings("unused") 94 | public IgniteClusterManager() { 95 | } 96 | 97 | /** 98 | * Creates cluster manager instance with given Ignite configuration. 99 | * Use this constructor in order to configure cluster manager programmatically. 100 | * 101 | * @param cfg {@code IgniteConfiguration} instance. 102 | */ 103 | @SuppressWarnings("unused") 104 | public IgniteClusterManager(IgniteConfiguration cfg) { 105 | this.cfg = cfg; 106 | } 107 | 108 | @Override 109 | public void setVertx(Vertx vertx) { 110 | this.vertx = vertx; 111 | } 112 | 113 | @Override 114 | public void nodeListener(NodeListener nodeListener) { 115 | this.nodeListener = nodeListener; 116 | } 117 | 118 | @Override 119 | public void getAsyncMultiMap(String name, Handler>> handler) { 120 | vertx.executeBlocking( 121 | fut -> fut.complete(new AsyncMultiMapImpl<>(this.>getCache(name), vertx)), handler 122 | ); 123 | } 124 | 125 | @Override 126 | public void getAsyncMap(String name, Handler>> handler) { 127 | vertx.executeBlocking( 128 | fut -> fut.complete(new AsyncMapImpl<>(getCache(name), vertx)), handler 129 | ); 130 | } 131 | 132 | @Override 133 | public Map getSyncMap(String name) { 134 | return new MapImpl<>(getCache(name)); 135 | } 136 | 137 | @Override 138 | public void getLockWithTimeout(String name, long timeout, Handler> handler) { 139 | vertx.executeBlocking(fut -> { 140 | IgniteQueue queue = getQueue(name); 141 | 142 | boolean locked = false; 143 | try { 144 | locked = queue.offer(true, timeout, TimeUnit.MILLISECONDS); 145 | } catch (Exception e) { 146 | fut.fail(new VertxException("Error during getting lock " + name, e)); 147 | } 148 | 149 | if (locked) { 150 | fut.complete(new LockImpl(name)); 151 | } else { 152 | fut.fail(new VertxException("Timed out waiting to get lock " + name)); 153 | } 154 | }, handler); 155 | } 156 | 157 | @Override 158 | public void getCounter(String name, Handler> handler) { 159 | vertx.executeBlocking(fut -> fut.complete(new CounterImpl(ignite.atomicLong(name, 0, true))), handler); 160 | } 161 | 162 | @Override 163 | public String getNodeID() { 164 | return nodeID; 165 | } 166 | 167 | @Override 168 | public List getNodes() { 169 | return ignite.cluster().nodes().stream() 170 | .map(IgniteClusterManager::nodeId).collect(Collectors.toList()); 171 | } 172 | 173 | @Override 174 | public void join(Handler> handler) { 175 | synchronized (monitor) { 176 | vertx.executeBlocking(fut -> { 177 | if (!active) { 178 | active = true; 179 | 180 | ignite = cfg == null ? Ignition.start(loadConfiguration()) : Ignition.start(cfg); 181 | nodeID = nodeId(ignite.cluster().localNode()); 182 | 183 | for (CacheConfiguration cacheCfg : ignite.configuration().getCacheConfiguration()) { 184 | if (cacheCfg.getName().equals(VERTX_CACHE_TEMPLATE_NAME)) { 185 | collectionCfg = new CollectionConfiguration(); 186 | collectionCfg.setAtomicityMode(cacheCfg.getAtomicityMode()); 187 | collectionCfg.setBackups(cacheCfg.getBackups()); 188 | break; 189 | } 190 | } 191 | 192 | if (collectionCfg == null) { 193 | collectionCfg = new CollectionConfiguration(); 194 | } 195 | 196 | ignite.events().localListen(event -> { 197 | if (!active) { 198 | return false; 199 | } 200 | 201 | if (nodeListener != null) { 202 | vertx.executeBlocking(f -> { 203 | if (isActive()) { 204 | switch (event.type()) { 205 | case EVT_NODE_JOINED: 206 | nodeListener.nodeAdded(nodeId(((DiscoveryEvent) event).eventNode())); 207 | break; 208 | case EVT_NODE_LEFT: 209 | case EVT_NODE_FAILED: 210 | nodeListener.nodeLeft(nodeId(((DiscoveryEvent) event).eventNode())); 211 | break; 212 | } 213 | } 214 | fut.complete(); 215 | }, null); 216 | } 217 | 218 | return true; 219 | }, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED); 220 | 221 | fut.complete(); 222 | } 223 | }, handler); 224 | } 225 | } 226 | 227 | @Override 228 | public void leave(Handler> handler) { 229 | synchronized (monitor) { 230 | vertx.executeBlocking(fut -> { 231 | if (active) { 232 | active = false; 233 | try { 234 | ignite.close(); 235 | } catch (Exception e) { 236 | log.error(e); 237 | } 238 | } 239 | 240 | fut.complete(); 241 | }, handler); 242 | } 243 | } 244 | 245 | @Override 246 | public boolean isActive() { 247 | return active; 248 | } 249 | 250 | private IgniteConfiguration loadConfiguration() { 251 | ClassLoader ctxClsLoader = Thread.currentThread().getContextClassLoader(); 252 | 253 | InputStream is = null; 254 | 255 | if (ctxClsLoader != null) { 256 | is = ctxClsLoader.getResourceAsStream(CONFIG_FILE); 257 | } 258 | 259 | if (is == null) { 260 | is = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE); 261 | 262 | if (is == null) { 263 | is = getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE); 264 | log.info("Using default configuration."); 265 | } 266 | } 267 | 268 | try { 269 | IgniteConfiguration cfg = F.first(IgnitionEx.loadConfigurations(is).get1()); 270 | UUID nodeId = UUID.randomUUID(); 271 | cfg.setNodeId(nodeId); 272 | cfg.setGridName(VERTX_NODE_PREFIX + nodeId); 273 | 274 | return cfg; 275 | } catch (IgniteCheckedException e) { 276 | log.error("Configuration loading error:", e); 277 | throw new RuntimeException(e); 278 | } 279 | } 280 | 281 | private IgniteCache getCache(String name) { 282 | return ignite.getOrCreateCache(name); 283 | } 284 | 285 | private IgniteQueue getQueue(String name) { 286 | return ignite.queue(name, 1, collectionCfg); 287 | } 288 | 289 | private static String nodeId(ClusterNode node) { 290 | return node.id().toString(); 291 | } 292 | 293 | private class LockImpl implements Lock { 294 | private final String name; 295 | 296 | private LockImpl(String name) { 297 | this.name = name; 298 | } 299 | 300 | @Override 301 | public void release() { 302 | IgniteQueue queue = getQueue(name); 303 | Boolean locked = queue.poll(); 304 | 305 | if (!locked) { 306 | throw new VertxException("Inconsistent lock state " + name); 307 | } 308 | } 309 | } 310 | 311 | private class CounterImpl implements Counter { 312 | private final IgniteAtomicLong cnt; 313 | 314 | private CounterImpl(IgniteAtomicLong cnt) { 315 | this.cnt = cnt; 316 | } 317 | 318 | @Override 319 | public void get(Handler> handler) { 320 | Objects.requireNonNull(handler, "handler"); 321 | vertx.executeBlocking(fut -> fut.complete(cnt.get()), handler); 322 | } 323 | 324 | @Override 325 | public void incrementAndGet(Handler> handler) { 326 | Objects.requireNonNull(handler, "handler"); 327 | vertx.executeBlocking(fut -> fut.complete(cnt.incrementAndGet()), handler); 328 | } 329 | 330 | @Override 331 | public void getAndIncrement(Handler> handler) { 332 | Objects.requireNonNull(handler, "handler"); 333 | vertx.executeBlocking(fut -> fut.complete(cnt.getAndIncrement()), handler); 334 | } 335 | 336 | @Override 337 | public void decrementAndGet(Handler> handler) { 338 | Objects.requireNonNull(handler, "handler"); 339 | vertx.executeBlocking(fut -> fut.complete(cnt.decrementAndGet()), handler); 340 | } 341 | 342 | @Override 343 | public void addAndGet(long value, Handler> handler) { 344 | Objects.requireNonNull(handler, "handler"); 345 | vertx.executeBlocking(fut -> fut.complete(cnt.addAndGet(value)), handler); 346 | } 347 | 348 | @Override 349 | public void getAndAdd(long value, Handler> handler) { 350 | Objects.requireNonNull(handler, "handler"); 351 | vertx.executeBlocking(fut -> fut.complete(cnt.getAndAdd(value)), handler); 352 | } 353 | 354 | @Override 355 | public void compareAndSet(long expected, long value, Handler> handler) { 356 | Objects.requireNonNull(handler, "handler"); 357 | vertx.executeBlocking(fut -> fut.complete(cnt.compareAndSet(expected, value)), handler); 358 | } 359 | } 360 | } 361 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/impl/AsyncMapImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.spi.cluster.ignite.impl; 19 | 20 | import io.vertx.core.AsyncResult; 21 | import io.vertx.core.Future; 22 | import io.vertx.core.Handler; 23 | import io.vertx.core.Vertx; 24 | import io.vertx.core.shareddata.AsyncMap; 25 | import java.util.function.Consumer; 26 | import org.apache.ignite.IgniteCache; 27 | import org.apache.ignite.lang.IgniteFuture; 28 | 29 | /** 30 | * Async wrapper for {@link MapImpl}. 31 | */ 32 | public class AsyncMapImpl implements AsyncMap { 33 | 34 | private final Vertx vertx; 35 | private final IgniteCache cache; 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param map {@link MapImpl} instance. 41 | * @param vertx {@link Vertx} instance. 42 | */ 43 | public AsyncMapImpl(IgniteCache cache, Vertx vertx) { 44 | this.vertx = vertx; 45 | this.cache = cache; 46 | } 47 | 48 | @Override 49 | public void get(K key, Handler> handler) { 50 | execute(cache -> cache.get(key), handler); 51 | } 52 | 53 | @Override 54 | public void put(K key, V value, Handler> handler) { 55 | execute(cache -> cache.put(key, value), handler); 56 | } 57 | 58 | @Override 59 | public void put(K key, V value, long timeout, Handler> handler) { 60 | executeWithTimeout(cache -> cache.put(key, value), handler, timeout); 61 | } 62 | 63 | @Override 64 | public void putIfAbsent(K key, V value, Handler> handler) { 65 | execute(cache -> cache.getAndPutIfAbsent(key, value), handler); 66 | } 67 | 68 | @Override 69 | public void putIfAbsent(K key, V value, long timeout, Handler> handler) { 70 | executeWithTimeout(cache -> cache.putIfAbsent(key, value), handler, timeout); 71 | } 72 | 73 | @Override 74 | public void remove(K key, Handler> handler) { 75 | execute(cache -> cache.getAndRemove(key), handler); 76 | } 77 | 78 | @Override 79 | public void removeIfPresent(K key, V value, Handler> handler) { 80 | execute(cache -> cache.remove(key, value), handler); 81 | } 82 | 83 | @Override 84 | public void replace(K key, V value, Handler> handler) { 85 | execute(cache -> cache.getAndReplace(key, value), handler); 86 | } 87 | 88 | @Override 89 | public void replaceIfPresent(K key, V oldValue, V newValue, Handler> handler) { 90 | execute(cache -> cache.replace(key, oldValue, newValue), handler); 91 | } 92 | 93 | @Override 94 | public void clear(Handler> handler) { 95 | execute(IgniteCache::clear, handler); 96 | } 97 | 98 | @Override 99 | public void size(Handler> handler) { 100 | execute(IgniteCache::size, handler); 101 | } 102 | 103 | private void execute(Consumer> cacheOp, Handler> handler) { 104 | executeWithTimeout(cacheOp, handler, -1); 105 | } 106 | 107 | private void executeWithTimeout(Consumer> cacheOp, 108 | Handler> handler, long timeout) { 109 | try { 110 | IgniteCache cache = this.cache.withAsync(); 111 | cacheOp.accept(cache); 112 | IgniteFuture future = cache.future(); 113 | 114 | if (timeout >= 0) { 115 | vertx.executeBlocking(f -> future.get(timeout), handler); 116 | } else { 117 | future.listen(fut -> vertx.executeBlocking( 118 | f -> f.complete(future.get()), handler) 119 | ); 120 | } 121 | } catch (Exception e) { 122 | handler.handle(Future.failedFuture(e)); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/impl/AsyncMultiMapImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.spi.cluster.ignite.impl; 19 | 20 | import io.vertx.core.AsyncResult; 21 | import io.vertx.core.Future; 22 | import io.vertx.core.Handler; 23 | import io.vertx.core.Vertx; 24 | import io.vertx.core.VertxException; 25 | import io.vertx.core.spi.cluster.AsyncMultiMap; 26 | import io.vertx.core.spi.cluster.ChoosableIterable; 27 | import org.apache.ignite.IgniteCache; 28 | import org.apache.ignite.lang.IgniteFuture; 29 | 30 | import javax.cache.Cache; 31 | import java.util.ArrayList; 32 | import java.util.Collections; 33 | import java.util.List; 34 | import java.util.function.Consumer; 35 | import java.util.function.Function; 36 | import java.util.function.UnaryOperator; 37 | 38 | /** 39 | * MultiMap implementation. 40 | */ 41 | public class AsyncMultiMapImpl implements AsyncMultiMap { 42 | 43 | private final IgniteCache> cache; 44 | private final Vertx vertx; 45 | 46 | public AsyncMultiMapImpl(IgniteCache> cache, Vertx vertx) { 47 | this.cache = cache; 48 | this.vertx = vertx; 49 | } 50 | 51 | @Override 52 | public void add(K key, V value, Handler> handler) { 53 | execute(cache -> cache.invoke(key, (entry, arguments) -> { 54 | List values = entry.getValue(); 55 | 56 | if (values == null) 57 | values = new ArrayList<>(); 58 | 59 | values.add(value); 60 | entry.setValue(values); 61 | return null; 62 | }), handler); 63 | } 64 | 65 | @Override 66 | public void get(K key, Handler>> handler) { 67 | execute( 68 | cache -> cache.get(key), 69 | (List list) -> new ChoosableIterableImpl<>(list == null ? Collections.emptyList() : list), 70 | handler 71 | ); 72 | } 73 | 74 | @Override 75 | public void remove(K key, V value, Handler> handler) { 76 | execute(cache -> cache.invoke(key, (entry, arguments) -> { 77 | List values = entry.getValue(); 78 | 79 | if (values != null) { 80 | boolean removed = values.remove(value); 81 | 82 | if (values.isEmpty()) { 83 | entry.remove(); 84 | } else { 85 | entry.setValue(values); 86 | } 87 | 88 | return removed; 89 | } 90 | 91 | return false; 92 | }), handler); 93 | } 94 | 95 | @Override 96 | public void removeAllForValue(V value, Handler> handler) { 97 | vertx.executeBlocking(fut -> { 98 | for (Cache.Entry> entry : cache) { 99 | cache.withAsync().invoke(entry.getKey(), (e, args) -> { 100 | List values = e.getValue(); 101 | 102 | if (values != null) { 103 | values.remove(value); 104 | 105 | if (values.isEmpty()) { 106 | e.remove(); 107 | } else { 108 | e.setValue(values); 109 | } 110 | } 111 | 112 | return null; 113 | }); 114 | } 115 | 116 | fut.complete(); 117 | }, handler); 118 | } 119 | 120 | private void execute(Consumer>> cacheOp, Handler> handler) { 121 | execute(cacheOp, UnaryOperator.identity(), handler); 122 | } 123 | 124 | private void execute(Consumer>> cacheOp, 125 | Function mapper, Handler> handler) { 126 | try { 127 | IgniteCache> cache = this.cache.withAsync(); 128 | cacheOp.accept(cache); 129 | IgniteFuture future = cache.future(); 130 | future.listen(fut -> vertx.executeBlocking(f -> f.complete(mapper.apply(future.get())), handler)); 131 | } catch (Exception e) { 132 | handler.handle(Future.failedFuture(e)); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/impl/ChoosableIterableImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.spi.cluster.ignite.impl; 19 | 20 | import io.vertx.core.spi.cluster.ChoosableIterable; 21 | 22 | import java.util.Collection; 23 | import java.util.Iterator; 24 | import java.util.Objects; 25 | 26 | /** 27 | * ChoosableIterable implementation. 28 | */ 29 | class ChoosableIterableImpl implements ChoosableIterable { 30 | 31 | private final Collection col; 32 | private Iterator iter; 33 | 34 | public ChoosableIterableImpl(Collection col) { 35 | this.col = Objects.requireNonNull(col, "col"); 36 | } 37 | 38 | @Override 39 | public boolean isEmpty() { 40 | return col.isEmpty(); 41 | } 42 | 43 | @Override 44 | public Iterator iterator() { 45 | return col.iterator(); 46 | } 47 | 48 | @Override 49 | public T choose() { 50 | if (col.isEmpty()) 51 | return null; 52 | 53 | if (iter == null || !iter.hasNext()) { 54 | iter = col.iterator(); 55 | } 56 | 57 | return iter.hasNext() ? iter.next() : null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/impl/MapImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.spi.cluster.ignite.impl; 19 | 20 | import org.apache.ignite.IgniteCache; 21 | 22 | import javax.cache.Cache; 23 | import java.util.AbstractMap; 24 | import java.util.ArrayList; 25 | import java.util.Collection; 26 | import java.util.HashSet; 27 | import java.util.Map; 28 | import java.util.Set; 29 | 30 | /** 31 | * Represents Apache Ignite cache as {@link java.util.Map} interface implementation. 32 | */ 33 | public class MapImpl implements Map { 34 | 35 | private final IgniteCache cache; 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param cache Ignite cache instance. 41 | */ 42 | public MapImpl(IgniteCache cache) { 43 | this.cache = cache; 44 | } 45 | 46 | IgniteCache getCache() { 47 | return cache; 48 | } 49 | 50 | @Override 51 | public int size() { 52 | return cache.size(); 53 | } 54 | 55 | @Override 56 | public boolean isEmpty() { 57 | return cache.size() == 0; 58 | } 59 | 60 | @Override 61 | @SuppressWarnings("unchecked") 62 | public boolean containsKey(Object key) { 63 | return cache.containsKey((K) key); 64 | } 65 | 66 | @Override 67 | public boolean containsValue(Object value) { 68 | for (Cache.Entry entry : cache) { 69 | if (entry.getValue().equals(value)) 70 | return true; 71 | } 72 | 73 | return false; 74 | } 75 | 76 | @Override 77 | @SuppressWarnings("unchecked") 78 | public V get(Object key) { 79 | return cache.get((K) key); 80 | } 81 | 82 | @Override 83 | public V put(K key, V value) { 84 | return cache.getAndPut(key, value); 85 | } 86 | 87 | @Override 88 | @SuppressWarnings("unchecked") 89 | public V remove(Object key) { 90 | return cache.getAndRemove((K) key); 91 | } 92 | 93 | @Override 94 | public void putAll(Map map) { 95 | cache.putAll(map); 96 | } 97 | 98 | @Override 99 | public void clear() { 100 | cache.clear(); 101 | } 102 | 103 | @Override 104 | public Set keySet() { 105 | Set res = new HashSet<>(); 106 | 107 | for (Cache.Entry entry : cache) { 108 | res.add(entry.getKey()); 109 | } 110 | 111 | return res; 112 | } 113 | 114 | @Override 115 | public Collection values() { 116 | Collection res = new ArrayList<>(); 117 | 118 | for (Cache.Entry entry : cache) { 119 | res.add(entry.getValue()); 120 | } 121 | 122 | return res; 123 | } 124 | 125 | @Override 126 | public Set> entrySet() { 127 | Set> res = new HashSet<>(); 128 | 129 | for (Cache.Entry entry : cache) { 130 | res.add(new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue())); 131 | } 132 | 133 | return res; 134 | } 135 | 136 | @Override 137 | public V putIfAbsent(K key, V value) { 138 | return cache.getAndPutIfAbsent(key, value); 139 | } 140 | 141 | @Override 142 | @SuppressWarnings("unchecked") 143 | public boolean remove(Object key, Object value) { 144 | return cache.remove((K) key, (V) value); 145 | } 146 | 147 | @Override 148 | public boolean replace(K key, V oldValue, V newValue) { 149 | return cache.replace(key, oldValue, newValue); 150 | } 151 | 152 | @Override 153 | public V replace(K key, V value) { 154 | return cache.getAndReplace(key, value); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/spi/cluster/ignite/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | /** 19 | * = Apache Ignite Cluster Manager for Vert.x 20 | * 21 | * This is a cluster manager implementation for Vert.x that uses http://ignite.apache.org/index.html[Apache Ignite]. 22 | * 23 | * In Vert.x a cluster manager is used for various functions including: 24 | * 25 | * * Discovery and group membership of Vert.x nodes in a cluster 26 | * * Maintaining cluster wide topic subscriber lists (so we know which nodes are interested in which event bus 27 | * addresses) 28 | * * Distributed Map support 29 | * * Distributed Locks 30 | * * Distributed Counters 31 | * 32 | * Cluster managers *do not* handle the event bus inter-node transport, this is done directly by Vert.x with TCP 33 | * connections. 34 | * 35 | * Vert.x cluster manager is a pluggable component, so you can pick the one you want, or the one that is the most 36 | * adapted to your environment. So you can replace default Vert.x cluster manager by this implementation. 37 | * 38 | * == Using Ignite cluster manager 39 | * 40 | * If the jar is on your classpath then Vert.x will automatically detect this and use it as the cluster manager. 41 | * Please make sure you don’t have any other cluster managers on your classpath or Vert.x might choose the wrong one. 42 | * 43 | * Alternatively, you can configure the following system property to instruct vert.x to use this cluster manager: 44 | * `-Dvertx.clusterManagerFactory=io.vertx.spi.cluster.ignite.IgniteClusterManager` 45 | * 46 | * ### Using Vert.x from command line 47 | * 48 | * `vertx-ignite-${maven.version}.jar` should be in the `lib` directory of the Vert.x installation. 49 | * 50 | * ### Using Vert.x in Maven or Gradle project 51 | * 52 | * Add a dependency to the artifact. 53 | * 54 | * * Maven (in your `pom.xml`): 55 | * 56 | * [source,xml,subs="+attributes"] 57 | * ---- 58 | * 59 | * ${maven.groupId} 60 | * ${maven.artifactId} 61 | * ${maven.version} 62 | * 63 | * ---- 64 | * 65 | * * Gradle (in your `build.gradle` file): 66 | * 67 | * [source,groovy,subs="+attributes"] 68 | * ---- 69 | * compile '${maven.groupId}:${maven.artifactId}:${maven.version}' 70 | * ---- 71 | * 72 | * ### Programmatically specifying cluster manager 73 | * 74 | * You can also specify the cluster manager programmatically. In order to do this just specify it on the options 75 | * when you are creating your Vert.x instance, for example: 76 | * 77 | * [source,java] 78 | * ---- 79 | * ClusterManager clusterManager = new IgniteClusterManager(); 80 | * 81 | * VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 82 | * Vertx.clusteredVertx(options, res -> { 83 | * if (res.succeeded()) { 84 | * Vertx vertx = res.result(); 85 | * } else { 86 | * // failed! 87 | * } 88 | * }); 89 | * ---- 90 | * 91 | * == Configuring cluster manager 92 | * 93 | * === Using configuration file 94 | * 95 | * The cluster manager is configured by a file `default-ignite.xml` which is packaged inside the jar. 96 | * 97 | * If you want to override this configuration you can provide `ignite.xml` file on your classpath and this will be 98 | * used instead. 99 | * 100 | * The xml file is a Ignite configuration file and is described in details in 101 | * https://apacheignite.readme.io/docs[Apache Ignite documentation]. 102 | * 103 | * ### Configuring programmatically 104 | * 105 | * You can also specify configuration programmatically: 106 | * 107 | * [source,java] 108 | * ---- 109 | * IgniteConfiguration cfg = new IgniteConfiguration(); 110 | * // Configuration code (omitted) 111 | * 112 | * ClusterManager clusterManager = new IgniteClusterManager(cfg); 113 | * 114 | * VertxOptions options = new VertxOptions().setClusterManager(clusterManager); 115 | * Vertx.clusteredVertx(options, res -> { 116 | * if (res.succeeded()) { 117 | * Vertx vertx = res.result(); 118 | * } else { 119 | * // failed! 120 | * } 121 | * }); 122 | * ---- 123 | * 124 | * === Discovery and network transport configuration 125 | * 126 | * The default configuration uses `TcpDiscoveryMulticastIpFinder` so you must have multicast enabled on your network. 127 | * For cases when multicast is disabled `TcpDiscoveryVmIpFinder` should be used with pre-configured list of IP addresses. 128 | * Please see http://apacheignite.readme.io/docs/cluster-config[Cluster Configuration] section 129 | * at Apache Ignite documentation for details. 130 | * 131 | * == Trouble shooting clustering 132 | * 133 | * If the default multicast configuration is not working here are some common causes: 134 | * 135 | * === Multicast not enabled on the machine. 136 | * 137 | * By default the cluster manager is using `TcpDiscoveryMulticastIpFinder`, so IP multicasting is required, 138 | * on some systems, multicast route(s) need to be added to the routing table otherwise, the default route will be used. 139 | * 140 | * Note that some systems don't consult the routing table for IP multicast routing, only for unicast routing 141 | * 142 | * MacOS example: 143 | * 144 | * ---- 145 | * # Adds a multicast route for 224.0.0.1-231.255.255.254 146 | * sudo route add -net 224.0.0.0/5 127.0.0.1 147 | * 148 | * # Adds a multicast route for 232.0.0.1-239.255.255.254 149 | * sudo route add -net 232.0.0.0/5 192.168.1.3 150 | * ---- 151 | * 152 | * Please google for more information. 153 | * 154 | * === Using wrong network interface 155 | * 156 | * If you have more than one network interface on your machine (and this can also be the case if you are running 157 | * VPN software on your machine), then Apache Ignite may be using the wrong one. 158 | * 159 | * To tell Ignite to use a specific interface you can provide the IP address of the interface to the 160 | * bean of `IgniteConfiguration` type using `localHost` property. For example: 161 | * 162 | * ---- 163 | * 164 | * 165 | * 166 | * ---- 167 | * 168 | * When running Vert.x is in clustered mode, you should also make sure that Vert.x knows about the correct interface. 169 | * When running at the command line this is done by specifying the `cluster-host` option: 170 | * 171 | * ---- 172 | * vertx run myverticle.js -cluster -cluster-host your-ip-address 173 | * ---- 174 | * 175 | * Where `your-ip-address` is the same IP address you specified in the Apache Ignite configuration. 176 | * 177 | * If using Vert.x programmatically you can specify this using {@link io.vertx.core.VertxOptions#setClusterHost(java.lang.String)}. 178 | * 179 | * === Using a VPN 180 | * 181 | * This is a variation of the above case. VPN software often works by creating a virtual network interface which often 182 | * doesn't support multicast. If you have a VPN running and you do not specify the correct interface to use in both the 183 | * Ignite configuration and to Vert.x then the VPN interface may be chosen instead of the correct interface. 184 | * 185 | * So, if you have a VPN running you may have to configure both the Ignite and Vert.x to use the correct interface as 186 | * described in the previous section. 187 | * 188 | * === When multicast is not available 189 | * 190 | * In some cases you may not be able to use multicast as it might not be available in your environment. In that case 191 | * you should configure another transport using corresponding IP finder, e.g. `TcpDiscoveryVmIpFinder` to use TCP sockets, 192 | * or `TcpDiscoveryS3IpFinder` to use Amazon S3. 193 | * 194 | * For more information on available Ignite transports and how to configure them please consult the 195 | * https://apacheignite.readme.io/docs/clustering[Ignite Clustering] documentation. 196 | * 197 | * === Enabling logging 198 | * 199 | * When trouble-shooting clustering issues it's often useful to get some logging output from Ignite 200 | * to see if it's forming a cluster properly. You can do this (when using the default JUL logging) by adding a file 201 | * called `vertx-default-jul-logging.properties` on your classpath. This is a standard java.util.loging (JUL) 202 | * configuration file. Inside it set: 203 | * 204 | * ---- 205 | * org.apache.ignite.level=INFO 206 | * ---- 207 | * 208 | * and also 209 | * 210 | * ---- 211 | * java.util.logging.ConsoleHandler.level=INFO 212 | * java.util.logging.FileHandler.level=INFO 213 | * ---- 214 | */ 215 | @Document(fileName = "index.adoc") 216 | package io.vertx.spi.cluster.ignite; 217 | 218 | import io.vertx.docgen.Document; -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/io.vertx.core.spi.cluster.ClusterManager: -------------------------------------------------------------------------------- 1 | io.vertx.spi.cluster.ignite.IgniteClusterManager -------------------------------------------------------------------------------- /src/main/resources/default-ignite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | 33 | 34 | 35 | 36 | 47 | 48 | 49 | 50 | 58 | 59 | 60 | 61 | 74 | 75 | 76 | 77 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteAsyncMultiMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteAsyncMultiMapTest extends AsyncMultiMapTest { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteClusterWideMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteClusterWideMapTest extends ClusterWideMapTestDifferentNodes { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteClusteredEventbusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteClusteredEventbusTest extends ClusteredEventBusTest { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteClusteredSharedCounterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteClusteredSharedCounterTest extends ClusteredSharedCounterTest { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteComplexHATest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteComplexHATest extends ComplexHATest { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgniteHATest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgniteHATest extends HATest { 24 | 25 | @Override 26 | protected ClusterManager getClusterManager() { 27 | return new IgniteClusterManager(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/test/core/IgnitesClusteredAsynchronousLockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The original author or authors 3 | * --------------------------------- 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Apache License v2.0 which accompanies this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * 12 | * The Apache License v2.0 is available at 13 | * http://www.opensource.org/licenses/apache2.0.php 14 | * 15 | * You may elect to redistribute this code under either of these licenses. 16 | */ 17 | 18 | package io.vertx.test.core; 19 | 20 | import io.vertx.core.spi.cluster.ClusterManager; 21 | import io.vertx.spi.cluster.ignite.IgniteClusterManager; 22 | 23 | public class IgnitesClusteredAsynchronousLockTest extends ClusteredAsynchronousLockTest { 24 | @Override 25 | protected ClusterManager getClusterManager() { 26 | return new IgniteClusterManager(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/resources/ignite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | 25 | 127.0.0.1:47500..47549 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/test/resources/vertx-default-jul-logging.properties.t: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015 The original author or authors 2 | # --------------------------------- 3 | # 4 | # All rights reserved. This program and the accompanying materials 5 | # are made available under the terms of the Eclipse Public License v1.0 6 | # and Apache License v2.0 which accompanies this distribution. 7 | # 8 | # The Eclipse Public License is available at 9 | # http://www.eclipse.org/legal/epl-v10.html 10 | # 11 | # The Apache License v2.0 is available at 12 | # http://www.opensource.org/licenses/apache2.0.php 13 | # 14 | # You may elect to redistribute this code under either of these licenses. 15 | 16 | handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler 17 | java.util.logging.SimpleFormatter.format=%5$s %6$s\n 18 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 19 | java.util.logging.ConsoleHandler.level=INFO 20 | java.util.logging.FileHandler.level=INFO 21 | java.util.logging.FileHandler.formatter=io.vertx.core.logging.impl.VertxLoggerFormatter 22 | 23 | # Put the log in the system temporary directory 24 | java.util.logging.FileHandler.pattern=%t/vertx.log 25 | 26 | .level=INFO 27 | io.vertx.level=INFO 28 | org.apache.ignite.level=INFO 29 | io.netty.util.internal.PlatformDependent.level=SEVERE --------------------------------------------------------------------------------