org.gridgain.client.router.impl.GridRouterCommandLineStartup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gridgain-hadoop2 Show documentation
Show all versions of gridgain-hadoop2 Show documentation
Java-based middleware for in-memory processing of big data in a distributed environment.
/*
Copyright (C) GridGain Systems. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* _________ _____ __________________ _____
* __ ____/___________(_)______ /__ ____/______ ____(_)_______
* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
*/
package org.gridgain.client.router.impl;
import org.gridgain.client.router.*;
import org.gridgain.grid.*;
import org.gridgain.grid.lang.*;
import org.gridgain.grid.logger.*;
import org.gridgain.grid.util.typedef.*;
import org.gridgain.grid.util.typedef.internal.*;
import org.jetbrains.annotations.*;
import org.springframework.beans.*;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
import org.springframework.context.*;
import org.springframework.context.support.*;
import org.springframework.core.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
/**
* Loader class for router.
*/
public class GridRouterCommandLineStartup {
/** Ant-augmented version number. */
private static final String VER = /*@java.version*/"ent-x.x.x";
/** Ant-augmented build number. */
private static final long BUILD = /*@java.build*/0;
/** Ant-augmented revision hash. */
private static final String REV_HASH = /*@java.revision*/"DEV";
/** Ant-augmented copyright blurb. */
private static final String COPYRIGHT = /*@java.copyright*/"Copyright (C) 2013 GridGain Systems.";
/** Logger. */
@SuppressWarnings("FieldCanBeLocal")
private GridLogger log;
/** TCP router. */
private GridTcpRouterImpl tcpRouter;
/** HTTP router. */
private GridHttpRouterImpl httpRouter;
/**
* Search given context for required configuration and starts router.
*
* @param ctx Context to extract configuration from.
*/
public void start(ListableBeanFactory ctx) {
log = getBean(ctx, GridLogger.class);
if (log == null) {
U.error(log, "Failed to find logger definition in application context. Stopping the router.");
return;
}
GridTcpRouterConfiguration tcpCfg = getBean(ctx, GridTcpRouterConfiguration.class);
if (tcpCfg == null)
U.warn(log, "TCP router startup skipped (configuration not found).");
else {
tcpRouter = new GridTcpRouterImpl(tcpCfg);
try {
tcpRouter.start();
}
catch (GridException e) {
U.error(log, "Failed to start TCP router on port " + tcpCfg.getPort() + ": " + e.getMessage(), e);
tcpRouter = null;
}
}
GridHttpRouterConfiguration httpCfg = getBean(ctx, GridHttpRouterConfiguration.class);
if (httpCfg == null)
U.warn(log, "HTTP router startup skipped (configuration not found).");
else {
httpRouter = new GridHttpRouterImpl(httpCfg);
try {
httpRouter.start();
}
catch (GridException e) {
U.error(log, "Failed to start HTTP router. See log above for details.", e);
httpRouter = null;
}
}
}
/**
* Stops router.
*/
public void stop() {
if (tcpRouter != null)
tcpRouter.stop();
if (httpRouter != null)
httpRouter.stop();
}
/**
* Wrapper method to run router from command-line.
*
* @param args Command-line arguments.
* @throws GridException If failed.
*/
public static void main(String[] args) throws GridException {
String buildDate = new SimpleDateFormat("yyyyMMdd").format(new Date(BUILD));
String rev = REV_HASH.length() > 8 ? REV_HASH.substring(0, 8) : REV_HASH;
String ver = "ver. " + VER + '#' + buildDate + "-sha1:" + rev;
X.println(
" _____ _ _______ _ ",
" / ___/____(_)___/ / ___/___ _(_)___ ",
"/ (_ // __/ // _ / (_ // _ `/ // _ \\ ",
"\\___//_/ /_/ \\_,_/\\___/ \\_,_/_//_//_/",
" ",
"GridGain Router Command Line Loader",
ver,
COPYRIGHT,
" "
);
if (args.length < 1) {
X.error("Missing XML configuration path.");
System.exit(1);
}
String cfgPath = args[0];
URL cfgUrl = U.resolveGridGainUrl(cfgPath);
if (cfgUrl == null) {
X.error("Spring XML file not found (is GRIDGAIN_HOME set?): " + cfgPath);
System.exit(1);
}
boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
GridBiTuple
© 2015 - 2025 Weber Informatics LLC | Privacy Policy