Search in sources :

Example 6 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class IgniteAwareApplicationService method main.

/**
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    log.info("Starting Application... [params=" + args[0] + "]");
    String[] params = args[0].split(",");
    IgniteServiceType svcType = IgniteServiceType.valueOf(params[0]);
    Class<?> clazz = Class.forName(params[1]);
    String cfgPath = params[2];
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = params.length > 3 ? mapper.readTree(Base64.getDecoder().decode(params[3])) : mapper.createObjectNode();
    IgniteAwareApplication app = (IgniteAwareApplication) clazz.getConstructor().newInstance();
    app.cfgPath = cfgPath;
    if (svcType == IgniteServiceType.NODE) {
        log.info("Starting Ignite node...");
        IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgs = IgnitionEx.loadConfiguration(cfgPath);
        IgniteConfiguration cfg = cfgs.get1();
        try (Ignite ignite = Ignition.start(cfg)) {
            app.ignite = ignite;
            app.start(jsonNode);
        } finally {
            log.info("Ignite instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.THIN_CLIENT) {
        log.info("Starting thin client...");
        ClientConfiguration cfg = IgnitionEx.loadSpringBean(cfgPath, "thin.client.cfg");
        try (IgniteClient client = Ignition.startClient(cfg)) {
            app.client = client;
            app.start(jsonNode);
        } finally {
            log.info("Thin client instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.NONE)
        app.start(jsonNode);
    else
        throw new IllegalArgumentException("Unknown service type " + svcType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext) Ignite(org.apache.ignite.Ignite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Aggregations

IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridSpringResourceContext (org.apache.ignite.internal.processors.resource.GridSpringResourceContext)6 Ignite (org.apache.ignite.Ignite)3 IgniteException (org.apache.ignite.IgniteException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 ServletContext (javax.servlet.ServletContext)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)1