io.ciera.tool.CoreTool Maven / Gradle / Ivy
package io.ciera.tool;
import io.ciera.runtime.summit.application.ApplicationExecutor;
import io.ciera.runtime.summit.application.IApplication;
import io.ciera.runtime.summit.application.ILogger;
import io.ciera.runtime.summit.application.tasks.GenericExecutionTask;
import io.ciera.runtime.summit.application.tasks.HaltExecutionTask;
import io.ciera.runtime.summit.components.IComponent;
import io.ciera.runtime.summit.exceptions.XtumlException;
import io.ciera.tool.Core;
import io.ciera.tool.CoreSqlLoader;
import java.util.Arrays;
public class CoreTool implements IApplication {
private IComponent>[] components;
private ApplicationExecutor[] executors;
public CoreTool() {
components = new IComponent>[1];
executors = new ApplicationExecutor[1];
}
@Override
public void run() {
for (ApplicationExecutor executor : executors) {
executor.run();
}
}
@Override
public void setup( String[] args, ILogger logger ) {
for ( int i = 0; i < executors.length; i++ ) {
if ( null != logger ) {
executors[i] = new ApplicationExecutor( "CoreToolExecutor" + i, args, logger );
}
else {
executors[i] = new ApplicationExecutor( "CoreToolExecutor" + i, args );
}
}
components[0] = new Core(this, executors[0], 0);
components[0].addLoader("Sql", new CoreSqlLoader((Core)components[0]));
}
public Core Core() {
return (Core)components[0];
}
@Override
public void initialize() {
for ( IComponent> component : components ) {
component.getRunContext().execute( new GenericExecutionTask() {
@Override
public void run() throws XtumlException {
component.initialize();
}
});
}
}
@Override
public void start() {
if (1 == executors.length) {
executors[0].run();
}
else {
for ( ApplicationExecutor executor : executors ) {
executor.start();
}
}
}
@Override
public void printVersions() {
io.ciera.runtime.Version.printVersion();
for ( IComponent> c : components ) {
System.out.printf("%s: %s (%s)", c.getClass().getName(), c.getVersion(), c.getVersionDate());
System.out.println();
}
}
@Override
public void stop() {
for ( ApplicationExecutor executor : executors ) {
executor.execute(new HaltExecutionTask());
}
}
public static void main( String[] args ) {
IApplication app = new CoreTool();
app.setup( args, null );
if ( Arrays.asList(args).contains("-v") || Arrays.asList(args).contains("--version") ) {
app.printVersions();
}
else {
app.initialize();
app.start();
}
}
}