Package de.anomic.server

Examples of de.anomic.server.serverCore


       
        // check port
        final boolean reconnect;
        if (!(env.getConfigLong("port", port) == port)) {
            // validate port
            final serverCore theServerCore = (serverCore) env.getThread("10_httpd");
            env.setConfig("port", port);
           
            // redirect the browser to the new port
            reconnect = true;
           
            // renew upnp port mapping
            if (upnp) {
                UPnP.addPortMapping();
            }
           
            String host = null;
            if (header.containsKey(HeaderFramework.HOST)) {
                host = header.get(HeaderFramework.HOST);
                final int idx = host.indexOf(':');
                if (idx != -1) host = host.substring(0,idx);
            } else {
                host = Domains.myPublicLocalIP().getHostAddress();
            }
           
            prop.put("reconnect", "1");
            prop.put("reconnect_host", host);
            prop.put("nextStep_host", host);
            prop.put("reconnect_port", port);
            prop.put("nextStep_port", port);
            prop.put("reconnect_sslSupport", theServerCore.withSSL() ? "1" : "0");
            prop.put("nextStep_sslSupport", theServerCore.withSSL() ? "1" : "0");
           
            // generate new shortcut (used for Windows)
            //yacyAccessible.setNewPortBat(Integer.parseInt(port));
            //yacyAccessible.setNewPortLink(Integer.parseInt(port));
           
            // force reconnection in 7 seconds
            theServerCore.reconnect(7000);
        } else {
            reconnect = false;
            prop.put("reconnect", "0");
        }
View Full Code Here


             */
            final String port = post.get("port");
            prop.putHTML("info_port", port);
            if (!env.getConfig("port", port).equals(port)) {
                // validation port
                final serverCore theServerCore = (serverCore) env.getThread("10_httpd");
                try {
                    final InetSocketAddress theNewAddress = theServerCore.generateSocketAddress(port);
                    final String hostName = Domains.getHostName(theNewAddress.getAddress());
                    prop.put("info_restart", "1");
                    prop.put("info_restart_ip",(hostName.equals("0.0.0.0"))? "localhost" : hostName);
                    prop.put("info_restart_port", theNewAddress.getPort());

                    env.setConfig("port", port);

                    theServerCore.reconnect(5000);
                } catch (final SocketException e) {
                    prop.put("info", "26");
                    return prop;
                }
            } else {
View Full Code Here

        //prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
        prop.put("trafficProxy", Formatter.bytesToString(ByteCount.getAccountCount(ByteCount.PROXY)));
        prop.put("trafficCrawler", Formatter.bytesToString(ByteCount.getAccountCount(ByteCount.CRAWLER)));

        // connection information
        final serverCore httpd = (serverCore) sb.getThread("10_httpd");
        prop.putNum("connectionsActive", httpd.getJobCount());
        prop.putNum("connectionsMax", httpd.getMaxSessionCount());
       
        // Queue information
        final int loaderJobCount = sb.crawlQueues.workerSize();
        final int loaderMaxCount = sb.getConfigInt(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX, 10);
        final int loaderPercent = (loaderMaxCount == 0) ? 0 : loaderJobCount * 100 / loaderMaxCount;
View Full Code Here

            // start main threads
            final String port = sb.getConfig("port", "8090");
            try {
                final HTTPDemon protocolHandler = new HTTPDemon(sb);
                final serverCore server = new serverCore(
                        timeout /*control socket timeout in milliseconds*/,
                        true /* block attacks (wrong protocol) */,
                        protocolHandler /*command class*/,
                        sb,
                        30000 /*command max length incl. GET args*/);
                server.setName("httpd:"+port);
                server.setPriority(Thread.MAX_PRIORITY);
                server.setObeyIntermission(false);

                // start the server
                sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", null, server, 0, 0, 0, 0);
                //server.start();

                // open the browser window
                final boolean browserPopUpTrigger = sb.getConfig(SwitchboardConstants.BROWSER_POP_UP_TRIGGER, "true").equals("true");
                if (browserPopUpTrigger) try {
                    final String  browserPopUpPage = sb.getConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "ConfigBasic.html");
                    //boolean properPW = (sb.getConfig("adminAccount", "").length() == 0) && (sb.getConfig(httpd.ADMIN_ACCOUNT_B64MD5, "").length() > 0);
                    //if (!properPW) browserPopUpPage = "ConfigBasic.html";
                    Browser.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage);
                } catch (final RuntimeException e) {
                    // cannot open browser. This may be normal in headless environments
                    //Log.logException(e);
                }

                // unlock yacyTray browser popup
                Tray.lockBrowserPopup = false;

                // Copy the shipped locales into DATA, existing files are overwritten
                final File locale_work   = sb.getDataPath("locale.work", "DATA/LOCALE/locales");
                final File locale_source = sb.getAppPath("locale.source", "locales");
                try{
                    final File[] locale_source_files = locale_source.listFiles();
                    mkdirsIfNeseccary(locale_work);
                    File target;
                    for (final File locale_source_file : locale_source_files) {
                      target = new File(locale_work, locale_source_file.getName());
                        if (locale_source_file.getName().endsWith(".lng")) {
                          if (target.exists()) delete(target);
                            FileUtils.copy(locale_source_file, target);
                        }
                    }
                    Log.logInfo("STARTUP", "Copied the default locales to " + locale_work.toString());
                }catch(final NullPointerException e){
                    Log.logSevere("STARTUP", "Nullpointer Exception while copying the default Locales");
                }

                //regenerate Locales from Translationlist, if needed
                final String lang = sb.getConfig("locale.language", "");
                if (!lang.equals("") && !lang.equals("default")) { //locale is used
                    String currentRev = "";
                    try{
                        final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang+"/version" ))));
                        currentRev = br.readLine();
                        br.close();
                    }catch(final IOException e){
                        //Error
                    }

                    if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?!
                        final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
                        final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang);
                        if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_work, lang + ".lng"), "html,template,inc", "locale")){ //translate it
                            //write the new Versionnumber
                            final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
                            bw.write(sb.getConfig("svnRevision", "Error getting Version"));
                            bw.close();
                        }
                    } catch (final IOException e) {}
                }
                // initialize number formatter with this locale
                Formatter.setLocale(lang);

                // registering shutdown hook
                Log.logConfig("STARTUP", "Registering Shutdown Hook");
                final Runtime run = Runtime.getRuntime();
                run.addShutdownHook(new shutdownHookThread(Thread.currentThread(), sb));

                // save information about available memory after all initializations
                //try {
                    sb.setConfig("memoryFreeAfterInitBGC", MemoryControl.free());
                    sb.setConfig("memoryTotalAfterInitBGC", MemoryControl.total());
                    System.gc();
                    sb.setConfig("memoryFreeAfterInitAGC", MemoryControl.free());
                    sb.setConfig("memoryTotalAfterInitAGC", MemoryControl.total());
                //} catch (ConcurrentModificationException e) {}

                // wait for server shutdown
                try {
                    sb.waitForShutdown();
                } catch (final Exception e) {
                    Log.logSevere("MAIN CONTROL LOOP", "PANIC: " + e.getMessage(),e);
                }
                // shut down
                if (RowCollection.sortingthreadexecutor != null) RowCollection.sortingthreadexecutor.shutdown();
                Log.logConfig("SHUTDOWN", "caught termination signal");
                server.terminate(false);
                server.interrupt();
                server.close();
                /*
                if (server.isAlive()) try {
                    // TODO only send request, don't read response (cause server is already down resulting in error)
                    final DigestURI u = new DigestURI((server.withSSL()?"https":"http")+"://localhost:" + serverCore.getPortNr(port), null);
                    Client.wget(u.toString(), null, 10000); // kick server
                    Log.logConfig("SHUTDOWN", "sent termination signal to server socket");
                } catch (final IOException ee) {
                    Log.logConfig("SHUTDOWN", "termination signal to server socket missed (server shutdown, ok)");
                }
                */
//                Client.closeAllConnections();
//                MultiThreadedHttpConnectionManager.shutdownAll();

                // idle until the processes are down
                if (server.isAlive()) {
                    //Thread.sleep(2000); // wait a while
                    server.interrupt();
//                    MultiThreadedHttpConnectionManager.shutdownAll();
                }
//                MultiThreadedHttpConnectionManager.shutdownAll();
                Log.logConfig("SHUTDOWN", "server has terminated");
                sb.close();
View Full Code Here

        //prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
        prop.put("trafficProxy", Formatter.bytesToString(ByteCount.getAccountCount(ByteCount.PROXY)));
        prop.put("trafficCrawler", Formatter.bytesToString(ByteCount.getAccountCount(ByteCount.CRAWLER)));

        // connection information
        final serverCore httpd = (serverCore) sb.getThread("10_httpd");
        prop.putNum("connectionsActive", httpd.getJobCount());
        prop.putNum("connectionsMax", httpd.getMaxSessionCount());

        // Queue information
        final int loaderJobCount = sb.crawlQueues.workerSize();
        final int loaderMaxCount = sb.getConfigInt(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX, 10);
        final int loaderPercent = (loaderMaxCount == 0) ? 0 : loaderJobCount * 100 / loaderMaxCount;
View Full Code Here

             */
            final String port = post.get("port");
            prop.putHTML("info_port", port);
            if (!env.getConfig("port", port).equals(port)) {
                // validation port
                final serverCore theServerCore = (serverCore) env.getThread("10_httpd");
                try {
                    final InetSocketAddress theNewAddress = theServerCore.generateSocketAddress(port);
                    final String hostName = Domains.getHostName(theNewAddress.getAddress());
                    prop.put("info_restart", "1");
                    prop.put("info_restart_ip",(hostName.equals("0.0.0.0"))? "localhost" : hostName);
                    prop.put("info_restart_port", theNewAddress.getPort());

                    env.setConfig("port", port);

                    theServerCore.reconnect(5000);
                } catch (final SocketException e) {
                    prop.put("info", "26");
                    return prop;
                }
            } else {
View Full Code Here

        // check port
        final boolean reconnect;
        if (!(env.getConfigLong("port", port) == port)) {
            // validate port
            final serverCore theServerCore = (serverCore) env.getThread("10_httpd");
            env.setConfig("port", port);

            // redirect the browser to the new port
            reconnect = true;

            // renew upnp port mapping
            if (upnp) {
                UPnP.addPortMapping();
            }

            String host = null;
            if (header.containsKey(HeaderFramework.HOST)) {
                host = header.get(HeaderFramework.HOST);
                final int idx = host.indexOf(':',0);
                if (idx != -1) host = host.substring(0,idx);
            } else {
                host = Domains.myPublicLocalIP().getHostAddress();
            }

            prop.put("reconnect", "1");
            prop.put("reconnect_host", host);
            prop.put("nextStep_host", host);
            prop.put("reconnect_port", port);
            prop.put("nextStep_port", port);
            prop.put("reconnect_sslSupport", theServerCore.withSSL() ? "1" : "0");
            prop.put("nextStep_sslSupport", theServerCore.withSSL() ? "1" : "0");

            // generate new shortcut (used for Windows)
            //yacyAccessible.setNewPortBat(Integer.parseInt(port));
            //yacyAccessible.setNewPortLink(Integer.parseInt(port));

            // force reconnection in 7 seconds
            theServerCore.reconnect(7000);
        } else {
            reconnect = false;
            prop.put("reconnect", "0");
        }
View Full Code Here

            // start main threads
            final String port = sb.getConfig("port", "8090");
            try {
                final HTTPDemon protocolHandler = new HTTPDemon(sb);
                final serverCore server = new serverCore(
                        timeout /*control socket timeout in milliseconds*/,
                        true /* block attacks (wrong protocol) */,
                        protocolHandler /*command class*/,
                        sb,
                        30000 /*command max length incl. GET args*/);
                server.setName("httpd:"+port);
                server.setPriority(Thread.MAX_PRIORITY);
                server.setObeyIntermission(false);

                // start the server
                sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", null, server, 0, 0, 0, 0);
                //server.start();

                // open the browser window
                final boolean browserPopUpTrigger = sb.getConfig(SwitchboardConstants.BROWSER_POP_UP_TRIGGER, "true").equals("true");
                if (browserPopUpTrigger) try {
                    final String  browserPopUpPage = sb.getConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "ConfigBasic.html");
                    //boolean properPW = (sb.getConfig("adminAccount", "").length() == 0) && (sb.getConfig(httpd.ADMIN_ACCOUNT_B64MD5, "").length() > 0);
                    //if (!properPW) browserPopUpPage = "ConfigBasic.html";
                    Browser.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage);
                } catch (final Throwable e) {
                    // cannot open browser. This may be normal in headless environments
                    //Log.logException(e);
                }

                // unlock yacyTray browser popup
                Tray.lockBrowserPopup = false;

                // Copy the shipped locales into DATA, existing files are overwritten
                final File locale_work   = sb.getDataPath("locale.work", "DATA/LOCALE/locales");
                final File locale_source = sb.getAppPath("locale.source", "locales");
                try{
                    final File[] locale_source_files = locale_source.listFiles();
                    mkdirsIfNeseccary(locale_work);
                    File target;
                    for (final File locale_source_file : locale_source_files) {
                      target = new File(locale_work, locale_source_file.getName());
                        if (locale_source_file.getName().endsWith(".lng")) {
                          if (target.exists()) delete(target);
                            FileUtils.copy(locale_source_file, target);
                        }
                    }
                    Log.logInfo("STARTUP", "Copied the default locales to " + locale_work.toString());
                }catch(final NullPointerException e){
                    Log.logSevere("STARTUP", "Nullpointer Exception while copying the default Locales");
                }

                //regenerate Locales from Translationlist, if needed
                final String lang = sb.getConfig("locale.language", "");
                if (!lang.equals("") && !lang.equals("default")) { //locale is used
                    String currentRev = "";
                    try{
                        final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang+"/version" ))));
                        currentRev = br.readLine();
                        br.close();
                    }catch(final IOException e){
                        //Error
                    }

                    if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?!
                        final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
                        final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang);
                        if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_work, lang + ".lng"), "html,template,inc", "locale")){ //translate it
                            //write the new Versionnumber
                            final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
                            bw.write(sb.getConfig("svnRevision", "Error getting Version"));
                            bw.close();
                        }
                    } catch (final IOException e) {}
                }
                // initialize number formatter with this locale
                Formatter.setLocale(lang);

                // registering shutdown hook
                Log.logConfig("STARTUP", "Registering Shutdown Hook");
                final Runtime run = Runtime.getRuntime();
                run.addShutdownHook(new shutdownHookThread(Thread.currentThread(), sb));

                // save information about available memory after all initializations
                //try {
                    sb.setConfig("memoryFreeAfterInitBGC", MemoryControl.free());
                    sb.setConfig("memoryTotalAfterInitBGC", MemoryControl.total());
                    System.gc();
                    sb.setConfig("memoryFreeAfterInitAGC", MemoryControl.free());
                    sb.setConfig("memoryTotalAfterInitAGC", MemoryControl.total());
                //} catch (ConcurrentModificationException e) {}

                // wait for server shutdown
                try {
                    sb.waitForShutdown();
                } catch (final Exception e) {
                    Log.logSevere("MAIN CONTROL LOOP", "PANIC: " + e.getMessage(),e);
                }
                // shut down
                Array.terminate();
                Log.logConfig("SHUTDOWN", "caught termination signal");
                server.terminate(false);
                server.interrupt();
                server.close();
                /*
                if (server.isAlive()) try {
                    // TODO only send request, don't read response (cause server is already down resulting in error)
                    final DigestURI u = new DigestURI((server.withSSL()?"https":"http")+"://localhost:" + serverCore.getPortNr(port), null);
                    Client.wget(u.toString(), null, 10000); // kick server
                    Log.logConfig("SHUTDOWN", "sent termination signal to server socket");
                } catch (final IOException ee) {
                    Log.logConfig("SHUTDOWN", "termination signal to server socket missed (server shutdown, ok)");
                }
                */
//                Client.closeAllConnections();
//                MultiThreadedHttpConnectionManager.shutdownAll();

                // idle until the processes are down
                if (server.isAlive()) {
                    //Thread.sleep(2000); // wait a while
                    server.interrupt();
//                    MultiThreadedHttpConnectionManager.shutdownAll();
                }
//                MultiThreadedHttpConnectionManager.shutdownAll();
                Log.logConfig("SHUTDOWN", "server has terminated");
                sb.close();
View Full Code Here

TOP

Related Classes of de.anomic.server.serverCore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.