Skip to content

Commit

Permalink
Fix the "HA" example
Browse files Browse the repository at this point in the history
* Use Launcher
* Add IDE and command line instructions

Related to #89
  • Loading branch information
cescoffier committed Sep 30, 2015
1 parent c8425fc commit 22c3e0b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
24 changes: 18 additions & 6 deletions core-examples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,29 @@ This example demonstrates the high availability feature of vert.x. When enabled,
node when the original node dies abruptly.

link:src/main/java/io/vertx/example/core/verticle/ha/Server.java[The server]
link:src/main/java/io/vertx/example/core/verticle/ha/BareInstance.java[The bare instance]

To run this example, you need to have a working cluster. Configure Hazelcast and append the required `cluster-host`
to the commands if needed.

**In your IDE:**

* Start the server by executing the `main` method of the `Server` class
* Check that the http://localhost:8080 is served correctly
* Start the _bare_ instance by executing the `main` method of the `BareInstance` class

In a terminal, find the process related to the `Server` class execution and kill it using `kill -9`. The verticle is
deployed on the _bare_ instance. If you refresh the page, the message should be slightly different.

**In command line:**

To see the HA (high-availability) behavior you need three terminals.

In the first one launch:
First compile the project with `mvn clean package`

In the first terminal, go the the _core-examples` directory and launch:
----
vertx run Server.java -ha
vertx run io.vertx.example.core.ha.Server -ha -cp target/classes
----

Open a browser to http://localhost:8080. You should see something like:
Expand All @@ -297,13 +311,11 @@ Happily served by 97284@Macintosh.local

Be displayed id is OS and JVM specific, so you may have something completely different.

In the second terminal, launch
In the second terminal, go the the _core-examples` directory and launch:
----
vertx -ha
vertx bare -cp target/classes/
----

Don't specify the verticle name. This launches an empty vert.x instance (called _bare_).

In the third terminal, display the list of the Java process and kill the first one (smaller pid):

----
Expand Down
20 changes: 19 additions & 1 deletion core-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,25 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<!-- copy dependencies to ease the usage of the vertx command line -->
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.vertx.example.core.ha;

import io.vertx.core.Launcher;

/**
* Just start a bare instance of vert.x .
* It will receive the Server verticle when the process is killed.
*
* @author <a href="http://escoffier.me">Clement Escoffier</a>
*/
public class BareInstance {

public static void main(String[] args) {
Launcher.main(new String[]{"bare"});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.vertx.example.core.ha;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.example.util.ExampleRunner;
import io.vertx.example.util.Runner;
Expand All @@ -17,8 +19,7 @@ public class Server extends AbstractVerticle {

// Convenience method so you can run it in your IDE
public static void main(String[] args) {
ExampleRunner.runJavaExample("core-examples/src/main/java",
Server.class, new VertxOptions().setHAEnabled(true));
Launcher.main(new String[] { "run", Server.class.getName(), "-ha"});
}

@Override
Expand Down

0 comments on commit 22c3e0b

Please sign in to comment.