Search in sources :

Example 1 with HeaderFunction

use of de.dytanic.cloudnet.logging.util.HeaderFunction in project CloudNet by Dytanic.

the class CloudBootstrap method main.

public static synchronized void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
    System.setProperty("file.encoding", "UTF-8");
    System.setProperty("java.net.preferIPv4Stack", "true");
    System.setProperty("io.netty.noPreferDirect", "true");
    System.setProperty("client.encoding.override", "UTF-8");
    System.setProperty("io.netty.maxDirectMemory", "0");
    System.setProperty("io.netty.leakDetectionLevel", "DISABLED");
    System.setProperty("io.netty.recycler.maxCapacity", "0");
    System.setProperty("io.netty.recycler.maxCapacity.default", "0");
    OptionParser optionParser = new OptionParser();
    optionParser.allowsUnrecognizedOptions();
    optionParser.acceptsAll(Arrays.asList("version", "v"));
    optionParser.acceptsAll(Arrays.asList("help", "?"));
    optionParser.acceptsAll(Arrays.asList("notifyWrappers"));
    optionParser.acceptsAll(Arrays.asList("disable-autoupdate"));
    optionParser.accepts("debug");
    optionParser.accepts("noconsole");
    optionParser.accepts("ssl");
    optionParser.accepts("systemTimer");
    optionParser.accepts("disable-statistics");
    optionParser.accepts("disable-modules");
    optionParser.accepts("installWrapper");
    optionParser.accepts("onlyConsole");
    OptionSet optionSet = optionParser.parse(args);
    List<String> consolePreInit = new CopyOnWriteArrayList<>();
    if (optionSet.has("help") || optionSet.has("?")) {
        HelpService helpService = new HelpService();
        helpService.getDescriptions().put("help", new ServiceDescription[] { new ServiceDescription("--help | --?", "This is the main argument to get all information about other parameters") });
        helpService.getDescriptions().put("ssl", new ServiceDescription[] { new ServiceDescription("--ssl", "Allows SSL encryption via a system-contained certificate or an open SSL certificate") });
        helpService.getDescriptions().put("debug", new ServiceDescription[] { new ServiceDescription("--debug", "Enables the debug mode, for extra consoles issues with more information, nothing is for people with interest in alto many consoles issues") });
        helpService.getDescriptions().put("noconsole", new ServiceDescription[] { new ServiceDescription("--noconsole", "Disables the console, for the rest of the service run time") });
        helpService.getDescriptions().put("notifyWrappers", new ServiceDescription[] { new ServiceDescription("--notifyWrappers", "Unites all the consoles that issued all wrapper instances to the master instance") });
        helpService.getDescriptions().put("disable-autoupdate", new ServiceDescription[] { new ServiceDescription("--disable-autoupdate", "Disabled the autoupdate function of cloudnet 2") });
        helpService.getDescriptions().put("version", new ServiceDescription[] { new ServiceDescription("--version | --v", "Displays the current version of CloudNet used") });
        helpService.getDescriptions().put("systemTimer", new ServiceDescription[] { new ServiceDescription("--systemTimer", "Time all informations of this instance into a custom log file") });
        helpService.getDescriptions().put("disable-statistics", new ServiceDescription[] { new ServiceDescription("--disable-statistics", "Disables the statistic service from cloudnet") });
        helpService.getDescriptions().put("disable-modules", new ServiceDescription[] { new ServiceDescription("--disable-modules", "Modules doesn't working in the \"/modules\" directory") });
        helpService.getDescriptions().put("installWrapper", new ServiceDescription[] { new ServiceDescription("--installWrapper", "Install a local wrapper automatic") });
        System.out.println(helpService.toString());
        return;
    }
    if (optionSet.has("systemTimer"))
        new SystemTimer();
    if (optionSet.has("version")) {
        System.out.println("CloudNet-Core RezSyM Version " + CloudBootstrap.class.getPackage().getImplementationVersion() + "-" + CloudBootstrap.class.getPackage().getSpecificationVersion());
        return;
    }
    CloudLogger cloudNetLogging = new CloudLogger();
    if (optionSet.has("debug"))
        cloudNetLogging.setDebugging(true);
    cloudNetLogging.getHandler().add(new ICloudLoggerHandler() {

        @Override
        public void handleConsole(String input) {
            if (!CloudNet.RUNNING)
                consolePreInit.add(input);
        }
    });
    new HeaderFunction();
    CloudConfig coreConfig = new CloudConfig(cloudNetLogging.getReader());
    CloudNet cloudNetCore = new CloudNet(coreConfig, cloudNetLogging, optionSet, consolePreInit, Arrays.asList(args));
    if (!cloudNetCore.bootstrap())
        System.exit(0);
    if (!optionSet.has("noconsole")) {
        System.out.println("Use the command \"help\" for further information!");
        String commandLine;
        try {
            while (true) while ((commandLine = cloudNetLogging.getReader().readLine()) != null && CloudNet.RUNNING) {
                String dispatcher = cloudNetCore.getDbHandlers().getCommandDispatcherDatabase().findDispatcher(commandLine);
                if (dispatcher != null) {
                    try {
                        if (!cloudNetCore.getCommandManager().dispatchCommand(dispatcher)) {
                            continue;
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (!cloudNetCore.getCommandManager().dispatchCommand(commandLine)) {
                    System.out.println("Command not found. Use the command \"help\" for further information!");
                }
            }
        } catch (Exception ex) {
        }
    } else {
        while (true) NetworkUtils.sleepUninterruptedly(Long.MAX_VALUE);
    }
}
Also used : ServiceDescription(de.dytanic.cloudnet.help.ServiceDescription) CloudConfig(de.dytanic.cloudnetcore.CloudConfig) OptionParser(joptsimple.OptionParser) ICloudLoggerHandler(de.dytanic.cloudnet.logging.handler.ICloudLoggerHandler) HeaderFunction(de.dytanic.cloudnet.logging.util.HeaderFunction) CloudNet(de.dytanic.cloudnetcore.CloudNet) OptionSet(joptsimple.OptionSet) CloudLogger(de.dytanic.cloudnet.logging.CloudLogger) HelpService(de.dytanic.cloudnet.help.HelpService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SystemTimer(de.dytanic.cloudnet.lib.SystemTimer)

Example 2 with HeaderFunction

use of de.dytanic.cloudnet.logging.util.HeaderFunction in project CloudNet by Dytanic.

the class CloudBootstrap method main.

public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
    System.setProperty("file.encoding", "UTF-8");
    System.setProperty("java.net.preferIPv4Stack", "true");
    System.setProperty("io.netty.noPreferDirect", "true");
    System.setProperty("client.encoding.override", "UTF-8");
    System.setProperty("io.netty.maxDirectMemory", "0");
    System.setProperty("io.netty.leakDetectionLevel", "DISABLED");
    System.setProperty("io.netty.recycler.maxCapacity", "0");
    System.setProperty("io.netty.recycler.maxCapacity.default", "0");
    OptionParser optionParser = new OptionParser();
    optionParser.allowsUnrecognizedOptions();
    optionParser.acceptsAll(Arrays.asList("version", "v"));
    optionParser.acceptsAll(Arrays.asList("help", "?"));
    optionParser.accepts("disable-queue");
    optionParser.accepts("ssl");
    optionParser.accepts("systemTimer");
    optionParser.accepts("noconsole");
    optionParser.accepts("systemTimer");
    optionParser.accepts("debug");
    optionParser.accepts("disable-autoupdate");
    optionParser.accepts("disallow_bukkit_download");
    OptionSet optionSet = optionParser.parse(args);
    if (optionSet.has("help") || optionSet.has("?")) {
        HelpService helpService = new HelpService();
        helpService.getDescriptions().put("help", new ServiceDescription[] { new ServiceDescription("--help | --?", "This is the main argument to get all information about other parameters") });
        helpService.getDescriptions().put("ssl", new ServiceDescription[] { new ServiceDescription("--ssl", "Allows SSL encryption via a system-contained certificate or an open SSL certificate") });
        helpService.getDescriptions().put("noconsole", new ServiceDescription[] { new ServiceDescription("--noconsole", "Disables the console, for the rest of the service run time") });
        helpService.getDescriptions().put("disable-autoupdate", new ServiceDescription[] { new ServiceDescription("--disable-autoupdate", "Disabled the autoupdate function of cloudnet 2") });
        helpService.getDescriptions().put("version", new ServiceDescription[] { new ServiceDescription("--version | --v", "Displays the current version of CloudNet used") });
        helpService.getDescriptions().put("systemTimer", new ServiceDescription[] { new ServiceDescription("--systemTimer", "Time all informations of this instance into a custom log file") });
        System.out.println(helpService.toString());
        return;
    }
    if (optionSet.has("systemTimer")) {
        new SystemTimer();
    }
    if (optionSet.has("version") || optionSet.has("v")) {
        System.out.println("CloudNet-Wrapper RezSyM Version " + CloudBootstrap.class.getPackage().getImplementationVersion() + "-" + CloudBootstrap.class.getPackage().getSpecificationVersion());
        return;
    }
    /*==============================================*/
    try {
        FileUtils.deleteDirectory(new File("temp"));
    } catch (Exception ex) {
    }
    if (Files.exists(Paths.get("local"))) {
        try {
            FileUtils.deleteDirectory(new File("local/cache"));
        } catch (Exception ex) {
        }
    }
    /*==============================================*/
    CloudLogger cloudNetLogging = new CloudLogger();
    if (optionSet.has("debug"))
        cloudNetLogging.setDebugging(true);
    new HeaderFunction();
    CloudNetWrapperConfig cloudNetWrapperConfig = new CloudNetWrapperConfig(cloudNetLogging.getReader());
    CloudNetWrapper cloudNetWrapper = new CloudNetWrapper(optionSet, cloudNetWrapperConfig, cloudNetLogging);
    if (!cloudNetWrapper.bootstrap()) {
        System.exit(0);
    }
    if (!optionSet.has("noconsole")) {
        System.out.println("Use the command \"help\" for further information!");
        String commandLine;
        while (true) try {
            while ((commandLine = cloudNetLogging.getReader().readLine()) != null) {
                if (!cloudNetWrapper.getCommandManager().dispatchCommand(commandLine)) {
                    System.out.println("Command not found. Use the command \"help\" for further information!");
                }
            }
        } catch (Exception ex) {
        }
    } else {
        while (true) NetworkUtils.sleepUninterruptedly(Long.MAX_VALUE);
    }
}
Also used : CloudNetWrapper(de.dytanic.cloudnetwrapper.CloudNetWrapper) ServiceDescription(de.dytanic.cloudnet.help.ServiceDescription) OptionParser(joptsimple.OptionParser) HeaderFunction(de.dytanic.cloudnet.logging.util.HeaderFunction) CloudNetWrapperConfig(de.dytanic.cloudnetwrapper.CloudNetWrapperConfig) OptionSet(joptsimple.OptionSet) File(java.io.File) CloudLogger(de.dytanic.cloudnet.logging.CloudLogger) HelpService(de.dytanic.cloudnet.help.HelpService) SystemTimer(de.dytanic.cloudnet.lib.SystemTimer)

Aggregations

HelpService (de.dytanic.cloudnet.help.HelpService)2 ServiceDescription (de.dytanic.cloudnet.help.ServiceDescription)2 SystemTimer (de.dytanic.cloudnet.lib.SystemTimer)2 CloudLogger (de.dytanic.cloudnet.logging.CloudLogger)2 HeaderFunction (de.dytanic.cloudnet.logging.util.HeaderFunction)2 OptionParser (joptsimple.OptionParser)2 OptionSet (joptsimple.OptionSet)2 ICloudLoggerHandler (de.dytanic.cloudnet.logging.handler.ICloudLoggerHandler)1 CloudConfig (de.dytanic.cloudnetcore.CloudConfig)1 CloudNet (de.dytanic.cloudnetcore.CloudNet)1 CloudNetWrapper (de.dytanic.cloudnetwrapper.CloudNetWrapper)1 CloudNetWrapperConfig (de.dytanic.cloudnetwrapper.CloudNetWrapperConfig)1 File (java.io.File)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1