Skip to content

Embedding Doradus In Another Application

JoeWinter edited this page Mar 20, 2015 · 3 revisions

[Table of Contents](https://github.com/dell-oss/Doradus/wiki/Doradus Administration: Table-of-Contents) | [Previous](https://github.com/dell-oss/Doradus/wiki/Best Practices) | [Next](https://github.com/dell-oss/Doradus/wiki/Deployment Guidelines)
Installing and Running Doradus: Embedding Doradus In Another Application


Some applications may want to embed Doradus in the same JVM process. One way to do this is to call the static `main` method, passing a `String[]` that provides runtime arguments. Example:
import com.dell.doradus.core.DoradusServer;
...
String[] args = new String[] {"-restport", "5711"};
DoradusServer.main(args);

This example overrides the doradus.yaml parameter restport, setting it to 5711. When main() is called, Doradus starts all internal services and the storage_services configured in doradus.yaml. However, main() does not return until the process receives a shutdown signal (e.g., Ctrl-C or System.exit() is called).

Alternatively, Doradus can be started with the method startEmbedded(), which returns as soon as all internal services are initialized and started. This method accepts the same args parameter as main() plus a second String[] that allows the selective initialization of services. Example:

String[] args = new String[] {"-restport", "5711"};
String[] services = new String[] {OLAPService.class.getName(), RESTService.class.getName()};
DoradusServer.startEmbedded(args, services);

This example also overrides the restport parameter, and it starts Doradus with the OLAP storage service and the REST service. Other optional services, such as the Task Manager service, are not initialized. Regardless of the services requested, Doradus always initializes required internal services such as the DB service (persistence layer) and schema service. See the doradus.yaml file for the list of optional services that may be requested through the services parameter.

The full package name of each service must be passed in the services parameter. At least one storage service must be initialized otherwise startEmbedded() will throw a RuntimeException. If multiple storage services are provided, the first one becomes the default for new applications created via the same Doradus instance that do not explicitly declare a storage service.

Note that multiple Doradus instances can be launched for the same Cassandra cluster with different service sets. For example, a direct-load application could embed Doradus, initializing only the storage service that it requires, while another stand-alone instance of Doradus can be executed with full services.

When Doradus is started with the startEmbedded() method, it returns as soon as all requested services are initialized and running. Doradus can be gracefully shutdown by calling the shutDown method. Example:

DoradusServer.shutDown(); // gracefully shutdown and return

Alternatively, Doradus can be gracefully shutdown and terminate the JVM process by calling stopServer. Example:

DordusServer.stopServer(null); // gracefully shutdown and call System.exit()

The parameter passed to stopServer() is a String[], but it is ignored.

Clone this wiki locally