Package de.anomic.server

Examples of de.anomic.server.serverObjects


import de.anomic.server.serverSwitch;

public class YMarks {
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
       
        if(isAdmin || isAuthUser) {
          prop.put("login", 1);
          String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
          prop.putHTML("user", bmk_user.substring(0,1).toUpperCase() + bmk_user.substring(1));
         
        } else {
          prop.put("login", 0);
        }
       
        return prop;
  }
View Full Code Here


public class Table_API_p {
   
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
       
        prop.put("showexec", 0);
        prop.put("showtable", 0);
       
        int startRecord = 0;
        int maximumRecords = 25;
        Pattern query = QueryParams.catchall_pattern;
        if (post != null && post.containsKey("startRecord")) startRecord = post.getInt("startRecord", 0);
        if (post != null && post.containsKey("maximumRecords")) maximumRecords = post.getInt("maximumRecords", 0);
        if (post != null && post.containsKey("query") && !post.get("query", "").isEmpty()) {
            query = Pattern.compile(".*" + post.get("query", "") + ".*");
            startRecord = 0;
            maximumRecords = 1000;
        }
        final boolean inline = (post != null && post.getBoolean("inline",false));

        prop.put("inline", (inline) ? 1 : 0);
       
        Pattern typefilter = QueryParams.catchall_pattern;
        if (post != null && post.containsKey("filter") && post.get("filter", "").length() > 0) {
            typefilter = Pattern.compile(post.get("filter", ".*"));
        }
       
        String pk;
        if (post != null && post.containsKey("repeat_select") && ((pk = post.get("pk")) != null)) try {
            final String action = post.get("repeat_select", "off");
            if (action.equals("on")) {
                Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes());
                if (row != null) {
                    row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 7);
                    row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days");
                    WorkTables.calculateAPIScheduler(row, false);
                    sb.tables.update(WorkTables.TABLE_API_NAME, row);
                }
            }
        } catch (IOException e) {
            Log.logException(e);
        } catch (RowSpaceExceededException e) {
            Log.logException(e);
        }
       
        if (post != null && post.containsKey("repeat_time") && ((pk = post.get("pk")) != null)) try {
            final String action = post.get("repeat_time", "off");
            final Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes());
            if (row != null) {
                if ("off".equals(action)) {
                    row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 0);
                } else {
                    row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, Integer.parseInt(action));
                }
                WorkTables.calculateAPIScheduler(row, false);
                sb.tables.update(WorkTables.TABLE_API_NAME, row);
            }
        } catch (IOException e) {
            Log.logException(e);
        } catch (RowSpaceExceededException e) {
            Log.logException(e);
        }
       
        if (post != null && post.containsKey("repeat_unit") && ((pk = post.get("pk")) != null)) try {
            final String action = post.get("repeat_unit", "seldays");
            final Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes());
            if (row != null) {
                int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 1);
                row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, action.substring(3));
                if (action.equals("selminutes") && time > 0 && time < 10) row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 10);
                if (action.equals("selminutes") && time > 50) row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 50);
                if (action.equals("selhours") && time > 23) row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 23);
                if (action.equals("seldays") && time > 30) row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 30);
                WorkTables.calculateAPIScheduler(row, false);
                sb.tables.update(WorkTables.TABLE_API_NAME, row);
            }
        } catch (IOException e) {
            Log.logException(e);
        } catch (RowSpaceExceededException e) {
            Log.logException(e);
        }
       
        if (post != null && !post.get("deleterows", "").isEmpty()) {
            for (final Map.Entry<String, String> entry: post.entrySet()) {
                if (entry.getValue().startsWith("mark_")) {
                    try {
                        sb.tables.delete(WorkTables.TABLE_API_NAME, entry.getValue().substring(5).getBytes());
                    } catch (IOException e) {
                        Log.logException(e);
                    }
                }
            }
        }

        if (post != null && !post.get("execrows", "").isEmpty()) {
            // create a time-ordered list of events to execute
            final Set<String> pks = new TreeSet<String>();
            for (final Map.Entry<String, String> entry: post.entrySet()) {
                if (entry.getValue().startsWith("mark_")) {
                    pks.add(entry.getValue().substring(5));
                }
            }
           
            // now call the api URLs and store the result status
            final Map<String, Integer> l = sb.tables.execAPICalls("localhost", (int) sb.getConfigLong("port", 8090), sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, ""), pks);
           
            // construct result table
            prop.put("showexec", l.size() > 0 ? 1 : 0);
           
            final Iterator<Map.Entry<String, Integer>> resultIterator = l.entrySet().iterator();
            Map.Entry<String, Integer> record;
            int count = 0;
            boolean dark = true;
            while (resultIterator.hasNext()) {
                record = resultIterator.next();
                if (record == null) continue;
                prop.put("showexec_list_" + count + "_dark", ((dark) ? 1 : 0) ); dark=!dark;
                prop.put("showexec_list_" + count + "_status", record.getValue());
                prop.put("showexec_list_" + count + "_url", record.getKey());
                count++;
            }
            prop.put("showexec_list", count);
        }
       
        // generate table
        prop.put("showtable", 1);
        prop.put("showtable_inline", inline ? 1 : 0);
       
        // insert rows
        final List<Tables.Row> table = new ArrayList<Tables.Row>(maximumRecords);
        int count = 0;
        int tablesize = 0;
        try {
            tablesize = sb.tables.size(WorkTables.TABLE_API_NAME);
            final Iterator<Tables.Row> plainIterator = sb.tables.iterator(WorkTables.TABLE_API_NAME);
            final Iterator<Tables.Row> mapIterator = sb.tables.orderBy(plainIterator, -1, WorkTables.TABLE_API_COL_DATE_RECORDING).iterator();
            Tables.Row r;
            boolean dark = true;
            boolean scheduledactions = false;
            int c = 0;
            String type, comment;
            // first prepare a list
            while (mapIterator.hasNext()) {
                r = mapIterator.next();
                if (r == null) continue;
                type = UTF8.String(r.get(WorkTables.TABLE_API_COL_TYPE));
                if (!typefilter.matcher(type).matches()) continue;
                comment = UTF8.String(r.get(WorkTables.TABLE_API_COL_COMMENT));
                if (!query.matcher(comment).matches()) continue;
                if (c >= startRecord) table.add(r);
                c++;
                if (table.size() >= maximumRecords) break;
            }
            // then work on the list
            for (final Tables.Row row: table) {
                final Date now = new Date();
                final Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, now) : null;
                final Date date_recording = row.get(WorkTables.TABLE_API_COL_DATE_RECORDING, date);
                final Date date_last_exec = row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date);
                final Date date_next_exec = row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, (Date) null);
                final int callcount = row.get(WorkTables.TABLE_API_COL_APICALL_COUNT, 1);
                final String unit = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days");
                final int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 0);
                prop.put("showtable_list_" + count + "_inline", inline ? 1 : 0);
                prop.put("showtable_list_" + count + "_dark", dark ? 1 : 0); dark=!dark;
                prop.put("showtable_list_" + count + "_pk", UTF8.String(row.getPK()));
                prop.put("showtable_list_" + count + "_count", count);
                prop.put("showtable_list_" + count + "_callcount", callcount);
                prop.put("showtable_list_" + count + "_dateRecording", date_recording == null ? "-" : DateFormat.getDateTimeInstance().format(date_recording));
                prop.put("showtable_list_" + count + "_dateLastExec",  date_last_exec == null ? "-" : DateFormat.getDateTimeInstance().format(date_last_exec));
                prop.put("showtable_list_" + count + "_dateNextExec",  date_next_exec == null ? "-" : DateFormat.getDateTimeInstance().format(date_next_exec));
                prop.put("showtable_list_" + count + "_selectedMinutes", unit.equals("minutes") ? 1 : 0);
                prop.put("showtable_list_" + count + "_selectedHours", unit.equals("hours") ? 1 : 0);
                prop.put("showtable_list_" + count + "_selectedDays", (unit.length() == 0 || unit.equals("days")) ? 1 : 0);
                prop.put("showtable_list_" + count + "_repeatTime", time);
                prop.put("showtable_list_" + count + "_type", row.get(WorkTables.TABLE_API_COL_TYPE));
                prop.put("showtable_list_" + count + "_comment", row.get(WorkTables.TABLE_API_COL_COMMENT));
                prop.putHTML("showtable_list_" + count + "_inline_url", "http://" + sb.myPublicIP() + ":" + sb.getConfig("port", "8090") + UTF8.String(row.get(WorkTables.TABLE_API_COL_URL)));

                if (time == 0) {
                    prop.put("showtable_list_" + count + "_scheduler", 0);
                    prop.put("showtable_list_" + count + "_scheduler_pk", UTF8.String(row.getPK()));
                } else {
                    scheduledactions = true;
                    prop.put("showtable_list_" + count + "_scheduler", 1);
                    prop.put("showtable_list_" + count + "_scheduler_pk", UTF8.String(row.getPK()));
                    prop.put("showtable_list_" + count + "_scheduler_scale_" + 0 + "_time", "off");
                    prop.put("showtable_list_" + count + "_scheduler_selectedMinutes", 0);
                    prop.put("showtable_list_" + count + "_scheduler_selectedHours", 0);
                    prop.put("showtable_list_" + count + "_scheduler_selectedDays", 0);
                    if (unit.equals("minutes")) {
                        for (int i = 1; i <= 5 ; i++) {
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_time", i * 10);
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_selected", 0);
                        }
                        prop.put("showtable_list_" + count + "_scheduler_scale_" + (time / 10) + "_selected", 1);
                        prop.put("showtable_list_" + count + "_scheduler_scale", 6);
                        prop.put("showtable_list_" + count + "_scheduler_selectedMinutes", 1);
                    } else if (unit.equals("hours")) {
                        for (int i = 1; i <= 23 ; i++) {
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_time", i);
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_selected", 0);
                        }
                        prop.put("showtable_list_" + count + "_scheduler_scale_" + time + "_selected", 1);
                        prop.put("showtable_list_" + count + "_scheduler_scale", 24);
                        prop.put("showtable_list_" + count + "_scheduler_selectedHours", 1);
                    } else {
                        for (int i = 1; i <= 30 ; i++) {
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_time", i);
                            prop.put("showtable_list_" + count + "_scheduler_scale_" + i + "_selected", 0);
                        }
                        prop.put("showtable_list_" + count + "_scheduler_scale_" + time + "_selected", 1);
                        prop.put("showtable_list_" + count + "_scheduler_scale", 31);
                        prop.put("showtable_list_" + count + "_scheduler_selectedDays", 1);
                    }
                }
                prop.put("showtable_list_" + count + "_scheduler_inline", inline ? "true" : "false");
                prop.put("showtable_list_" + count + "_scheduler_filter", typefilter.pattern());
                prop.put("showtable_list_" + count + "_scheduler_query", query.pattern());
                prop.put("showtable_list_" + count + "_scheduler_startRecord", startRecord);
                prop.put("showtable_list_" + count + "_scheduler_maximumRecords", maximumRecords);
                count++;
            }
            if (scheduledactions) {
                prop.put("showschedulerhint", 1);
                prop.put("showschedulerhint_tfminutes", sb.getConfigLong(SwitchboardConstants.CLEANUP_BUSYSLEEP, 300000) / 60000);
            } else {
                prop.put("showschedulerhint", 0);
            }
        } catch (IOException e) {
            Log.logException(e);
        }
        prop.put("showtable_list", count);
        prop.put("showtable_num", count);
       
        // write navigation details
        prop.put("showtable_startRecord", startRecord);
        prop.put("showtable_maximumRecords", maximumRecords);
        prop.put("showtable_inline", (inline) ? 1 : 0);
        prop.put("showtable_filter", typefilter.pattern());
        prop.put("showtable_query", query.pattern().replaceAll("\\.\\*", ""));
        if (tablesize >= 50) {
            prop.put("showtable_navigation", 1);
            prop.put("showtable_navigation_startRecord", startRecord);
            prop.put("showtable_navigation_to", Math.min(tablesize, startRecord + maximumRecords));
            prop.put("showtable_navigation_of", tablesize);
            prop.put("showtable_navigation_left", startRecord == 0 ? 0 : 1);
            prop.put("showtable_navigation_left_startRecord", Math.max(0, startRecord - maximumRecords));
            prop.put("showtable_navigation_left_maximumRecords", maximumRecords);
            prop.put("showtable_navigation_left_inline", (inline) ? 1 : 0);
            prop.put("showtable_navigation_left_filter", typefilter.pattern());
            prop.put("showtable_navigation_left", startRecord == 0 ? 0 : 1);
            prop.put("showtable_navigation_filter", typefilter.pattern());
            prop.put("showtable_navigation_right", startRecord + maximumRecords >= tablesize ? 0 : 1);
            prop.put("showtable_navigation_right_startRecord", Math.min(tablesize - maximumRecords, startRecord + maximumRecords));
            prop.put("showtable_navigation_right_maximumRecords", maximumRecords);
            prop.put("showtable_navigation_right_inline", (inline) ? 1 : 0);
            prop.put("showtable_navigation_right_filter", typefilter.pattern());
        } else {
            prop.put("showtable_navigation", 0);
        }
       
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class ConfigHTCache_p {

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws IOException {
        // return variable that accumulates replacements
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();

        if (post != null && post.containsKey("set")) {
            // proxyCache - check and create the directory
            final String oldProxyCachePath = env.getConfig(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT);
            String newProxyCachePath = post.get("HTCachePath", SwitchboardConstants.HTCACHE_PATH_DEFAULT);
            newProxyCachePath = newProxyCachePath.replace('\\', '/');
            if (newProxyCachePath.endsWith("/")) {
                newProxyCachePath = newProxyCachePath.substring(0, newProxyCachePath.length() - 1);
            }
            env.setConfig(SwitchboardConstants.HTCACHE_PATH, newProxyCachePath);
            final File cache = env.getDataPath(SwitchboardConstants.HTCACHE_PATH, oldProxyCachePath);
            if (!cache.isDirectory() && !cache.isFile()) {
                cache.mkdirs();
            }

            // proxyCacheSize
            final int newProxyCacheSize = Math.max(post.getInt("maxCacheSize", 64), 4);
            env.setConfig(SwitchboardConstants.PROXY_CACHE_SIZE, newProxyCacheSize);
            Cache.setMaxCacheSize(newProxyCacheSize * 1024 * 1024);               
        }
       
        if (post != null && post.containsKey("deletecomplete")) {
            if ("on".equals(post.get("deleteCache", ""))) {
                Cache.clear();
            }
            if ("on".equals(post.get("deleteRobots", ""))) {
                sb.robots.clear();
            }
            if ("on".equals(post.get("deleteSearchFl", ""))) {
              sb.tables.clear(WorkTables.TABLE_SEARCH_FAILURE_NAME);
            }
        }

        prop.put("HTCachePath", env.getConfig(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT));
        prop.put("actualCacheSize", (Cache.getActualCacheSize() / 1024 / 1024));
        prop.put("maxCacheSize", env.getConfigLong(SwitchboardConstants.PROXY_CACHE_SIZE, 64));
        // return rewrite properties
        return prop;
    }
View Full Code Here

     * @param env the serverSwitch object holding all runtime-data
     * @return the rewrite-properties for the template
     */
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {

        final serverObjects prop = new serverObjects();
        final Switchboard sb = (Switchboard) env;

        // get segment
        Segment indexSegment = null;
        if (post != null && post.containsKey("segment")) {
            final String segmentName = post.get("segment");
            if (sb.indexSegments.segmentExist(segmentName)) {
                indexSegment = sb.indexSegments.segment(segmentName);
            }
        } else {
            // take default segment
            indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);
        }

        if (post == null) {
            // send back usage example
            prop.put("mode", "0");

            // get the http host header
            final String hostSocket = header.get(HeaderFramework.CONNECTION_PROP_HOST);

            //String host = hostSocket;
            int port = 80;
            final int pos = hostSocket.indexOf(":");
            if (pos != -1) {
                port = Integer.parseInt(hostSocket.substring(pos + 1));
                //host = hostSocket.substring(0, pos);
            }

            prop.put("mode_host", "localhost");
            prop.put("mode_port", port);

            return prop;
        }
        prop.put("mode", "1");

        // get the URL
        String crawlingStart = post.get("url",null);
        try {
            crawlingStart = URLDecoder.decode(crawlingStart, "UTF-8");
        } catch (final UnsupportedEncodingException e) {
            Log.logException(e);
        }

        // get the browser title
        final String title = post.get("title",null);

        // get other parameters if set
        final String crawlingMustMatch  = post.get("mustmatch", CrawlProfile.MATCH_ALL);
        final String crawlingMustNotMatch  = post.get("mustnotmatch", CrawlProfile.MATCH_NEVER);
        final int CrawlingDepth      = post.getInt("crawlingDepth", 0);
        final boolean crawlDynamic   = post.get("crawlingQ", "").equals("on");
        final boolean indexText      = post.get("indexText", "on").equals("on");
        final boolean indexMedia     = post.get("indexMedia", "on").equals("on");
        final boolean storeHTCache   = post.get("storeHTCache", "").equals("on");
        final boolean remoteIndexing = post.get("crawlOrder", "").equals("on");
        final boolean xsstopw        = post.get("xsstopw", "").equals("on");
        final boolean xdstopw        = post.get("xdstopw", "").equals("on");
        final boolean xpstopw        = post.get("xpstopw", "").equals("on");

        prop.put("mode_url", (crawlingStart == null) ? "unknown" : crawlingStart);
        prop.putHTML("mode_title", (title == null) ? "unknown" : title);

        if (crawlingStart != null) {
            crawlingStart = crawlingStart.trim();
            try {crawlingStart = new DigestURI(crawlingStart).toNormalform(true, true);} catch (final MalformedURLException e1) {}

            // check if url is proper
            DigestURI crawlingStartURL = null;
            try {
                crawlingStartURL = new DigestURI(crawlingStart);
            } catch (final MalformedURLException e) {
                prop.put("mode_status", "1");
                prop.put("mode_code", "1");
                return prop;
            }

            final byte[] urlhash = crawlingStartURL.hash();
            indexSegment.urlMetadata().remove(urlhash);
            sb.crawlQueues.noticeURL.removeByURLHash(urlhash);
            sb.crawlQueues.errorURL.remove(urlhash);

            // create crawling profile
            CrawlProfile pe = null;
            try {
                pe = new CrawlProfile(
                        crawlingStartURL.getHost(),
                        crawlingStartURL,
                        crawlingMustMatch,
                        crawlingMustNotMatch,
                        CrawlingDepth,
                        60 * 24 * 30, // recrawlIfOlder (minutes); here: one month
                        -1, // domMaxPages, if negative: no count restriction
                        crawlDynamic,
                        indexText,
                        indexMedia,
                        storeHTCache,
                        remoteIndexing,
                        xsstopw,
                        xdstopw,
                        xpstopw,
                        CacheStrategy.IFFRESH);
                sb.crawler.putActive(pe.handle().getBytes(), pe);
            } catch (final Exception e) {
                // mist
                prop.put("mode_status", "2");//Error with url
                prop.put("mode_code", "2");
                prop.putHTML("mode_status_error", e.getMessage());
                return prop;
            }

            // stack URL
            String reasonString = null;
            reasonString = sb.crawlStacker.stackCrawl(new Request(
                    sb.peers.mySeed().hash.getBytes(),
                    crawlingStartURL,
                    null,
                    (title==null)?"CRAWLING-ROOT":title,
                    new Date(),
                    pe.handle(),
                    0,
                    0,
                    0,
                    0
                ));

            // validate rejection reason
            if (reasonString == null) {
                prop.put("mode_status", "0");//start msg
                prop.put("mode_code", "0");
            } else {
                prop.put("mode_status", "3");//start msg
                prop.put("mode_code","3");
                prop.putHTML("mode_status_error", reasonString);
            }
        }

        return prop;
    }
View Full Code Here

public class Threaddump_p {

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
     
      serverObjects prop = new serverObjects();
      Switchboard sb = (Switchboard) env;
     
      final StringBuilder buffer = new StringBuilder(1000);
     
      final boolean plain = post != null && post.getBoolean("plain", false);
      final int sleep = (post == null) ? 0 : post.getInt("sleep", 0); // a sleep before creation of a thread dump can be used for profiling
      if (sleep > 0) try {Thread.sleep(sleep);} catch (final InterruptedException e) {}
      prop.put("dump", "1");
      // Thread dump
      final Date dt = new Date();
      final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();
      Runtime runtime = Runtime.getRuntime();
     
      ThreadDump.bufferappend(buffer, plain, "************* Start Thread Dump " + dt + " *******************");
      ThreadDump.bufferappend(buffer, plain, "");
      ThreadDump.bufferappend(buffer, plain, "YaCy Version: " + versionstring);
      ThreadDump.bufferappend(buffer, plain, "Assigned&nbsp;&nbsp;&nbsp;Memory = " + (runtime.maxMemory()));
      ThreadDump.bufferappend(buffer, plain, "Used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory = " + (runtime.totalMemory() - runtime.freeMemory()));
      ThreadDump.bufferappend(buffer, plain, "Available&nbsp;&nbsp;Memory = " + (runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory()));
      ThreadDump.bufferappend(buffer, plain, "");
      ThreadDump.bufferappend(buffer, plain, "");
     
      int multipleCount = 100;
      File appPath = sb.getAppPath();
        if (post != null && post.containsKey("multipleThreaddump")) {
          multipleCount = post.getInt("count", multipleCount);
            final ArrayList<Map<Thread,StackTraceElement[]>> traces = new ArrayList<Map<Thread,StackTraceElement[]>>();
            for (int i = 0; i < multipleCount; i++) {
                try {
                    traces.add(ThreadDump.getAllStackTraces());
                } catch (OutOfMemoryError e) {
                    break;
                }
            }
            ThreadDump.appendStackTraceStats(appPath, buffer, traces, plain);
        } else {
            // write a thread dump to standard error output
            File logFile = new File("yacy.log");
            if (ThreadDump.canProduceLockedBy(logFile)) {
                try {
                    new ThreadDump(logFile).appendBlockTraces(buffer, plain);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (OS.canExecUnix) {
                ThreadDump.bufferappend(buffer, plain, "this thread dump function can find threads that lock others, to enable this function start YaCy with 'startYACY.sh -l'");
                ThreadDump.bufferappend(buffer, plain, "");
            }
           
            // generate a single thread dump
            final Map<Thread,StackTraceElement[]> stackTraces = ThreadDump.getAllStackTraces();
            new ThreadDump(appPath, stackTraces, plain, Thread.State.BLOCKED).appendStackTraces(buffer, plain, Thread.State.BLOCKED);
            new ThreadDump(appPath, stackTraces, plain, Thread.State.RUNNABLE).appendStackTraces(buffer, plain, Thread.State.RUNNABLE);
            new ThreadDump(appPath, stackTraces, plain, Thread.State.TIMED_WAITING).appendStackTraces(buffer, plain, Thread.State.TIMED_WAITING);
            new ThreadDump(appPath, stackTraces, plain, Thread.State.WAITING).appendStackTraces(buffer, plain, Thread.State.WAITING);
            new ThreadDump(appPath, stackTraces, plain, Thread.State.NEW).appendStackTraces(buffer, plain, Thread.State.NEW);
            new ThreadDump(appPath, stackTraces, plain, Thread.State.TERMINATED).appendStackTraces(buffer, plain, Thread.State.TERMINATED);
        }
       
        ThreadDump.bufferappend(buffer, plain, "************* End Thread Dump " + dt + " *******************");
   
      prop.put("plain_count", multipleCount);
      prop.put("plain_content", buffer.toString());
      prop.put("plain", (plain) ? 1 : 0);
     
         return prop;    // return from serverObjects respond()
    }   
View Full Code Here


public class WatchWebStructure_p {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();

        String color_text    = "888888";
        String color_back    = "FFFFFF";
        String color_dot     = "11BB11";
        String color_line    = "222222";
        String color_lineend = "333333";
       
        int width = 1024;
        int height = 576;
        int depth = 3;
        int nodes = 500; // maximum number of host nodes that are painted
        int time = -1;
        String host = "auto";
        String besthost;
       
        if (post != null) {
            width         = post.getInt("width", 1024);
            height        = post.getInt("height", 576);
            depth         = post.getInt("depth", 3);
            nodes         = post.getInt("nodes", width * height * 100 / 1024 / 576);
            time          = post.getInt("time", -1);
            host          = post.get("host", "auto");
            color_text    = post.get("colortext",    color_text);
            color_back    = post.get("colorback",    color_back);
            color_dot     = post.get("colordot",     color_dot);
            color_line    = post.get("colorline",    color_line);
            color_lineend = post.get("colorlineend", color_lineend);
        }
       
        if (host.equals("auto")) {
          // try to find the host from the crawl profiles
          CrawlProfile e;
            for (byte[] handle: sb.crawler.getActive()) {
                e = sb.crawler.getActive(handle);
                if (e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_PROXY) ||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_REMOTE) ||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_TEXT||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_TEXT) ||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA) ||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA) ||
                    e.name().equals(CrawlSwitchboard.CRAWL_PROFILE_SURROGATE))
                   continue;
                host = e.name();
                break; // take the first one
            }
        }
       
        // find start point
        if (host == null ||
            host.length() == 0 ||
            host.equals("auto") ||
            sb.webStructure.referencesCount(DigestURI.hosthash6(host)) == 0) {
            // find domain with most references
            besthost = sb.webStructure.hostWithMaxReferences();
        } else {
            besthost = host;
        }
       
        prop.putHTML("host", host);
        prop.putHTML("besthost", besthost);
        prop.put("depth", depth);
        prop.put("depthi", Math.min(8, depth + 1));
        prop.put("depthd", Math.max(0, depth - 1));
        prop.put("nodes", nodes);
        prop.put("nodesi", Math.min(1000, nodes + 100));
        prop.put("nodesd", Math.max(100, nodes - 100));
        prop.put("time", time);
        prop.put("timei", (time > 9000) ? -1 : ((time < 0) ? -1 : Math.min(9999, time + 1000)));
        prop.put("timed", (time < 0) ? 9000 : Math.max(1000, time - 1000));
        prop.put("width", width);
        prop.put("height", height);

        prop.put("colortext",    color_text);
        prop.put("colorback",    color_back);
        prop.put("colordot",     color_dot);
        prop.put("colorline",    color_line);
        prop.put("colorlineend", color_lineend);
        return prop;
    }
View Full Code Here

public class IndexCreateParserErrors_p {
   
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
        prop.put("rejected", "0");
        int showRejectedCount = 100;
       
        if (post != null) {
           
            if (post.containsKey("clearRejected")) {
                sb.crawlQueues.errorURL.clearStack();
            }
            if (post.containsKey("moreRejected")) {
                showRejectedCount = post.getInt("showRejected", 10);
            }
        }
        boolean dark;
       

        prop.put("indexing-queue", "0"); //is empty
       
        // failure cases
        if (sb.crawlQueues.errorURL.stackSize() != 0) {
            if (showRejectedCount > sb.crawlQueues.errorURL.stackSize()) showRejectedCount = sb.crawlQueues.errorURL.stackSize();
            prop.put("rejected", "1");
            prop.putNum("rejected_num", sb.crawlQueues.errorURL.stackSize());
            if (showRejectedCount != sb.crawlQueues.errorURL.stackSize()) {
                prop.put("rejected_only-latest", "1");
                prop.putNum("rejected_only-latest_num", showRejectedCount);
                prop.put("rejected_only-latest_newnum", ((int) (showRejectedCount * 1.5)));
            }else{
                prop.put("rejected_only-latest", "0");
            }
            dark = true;
            DigestURI url;
            byte[] initiatorHash, executorHash;
            yacySeed initiatorSeed, executorSeed;
            int j=0;
            ArrayList<ZURL.Entry> l = sb.crawlQueues.errorURL.list(showRejectedCount);
            ZURL.Entry entry;
            for (int i = l.size() - 1; i >= 0; i--) {
                entry = l.get(i);
                if (entry == null) continue;
                url = entry.url();
                if (url == null) continue;
               
                initiatorHash = entry.initiator();
                executorHash = entry.executor();
                initiatorSeed = (initiatorHash == null) ? null : sb.peers.getConnected(ASCII.String(initiatorHash));
                executorSeed = (executorHash == null) ? null : sb.peers.getConnected(ASCII.String(executorHash));
                prop.putHTML("rejected_list_"+j+"_initiator", ((initiatorSeed == null) ? "proxy" : initiatorSeed.getName()));
                prop.putHTML("rejected_list_"+j+"_executor", ((executorSeed == null) ? "proxy" : executorSeed.getName()));
                prop.putHTML("rejected_list_"+j+"_url", url.toNormalform(false, true));
                prop.putHTML("rejected_list_"+j+"_failreason", entry.anycause());
                prop.put("rejected_list_"+j+"_dark", dark ? "1" : "0");
                dark = !dark;
                j++;
            }
            prop.put("rejected_list", j);
        }

        // return rewrite properties
        return prop;
    }
View Full Code Here

     * @param env the serverSwitch object holding all runtime-data
     * @return the rewrite-properties for the template
     */
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
       
        final serverObjects prop = new serverObjects();
       
        final boolean yacyonly = env.getConfigBool(SwitchboardConstants.PROXY_YACY_ONLY, false);
       
        // get the http host header
        final String hostSocket = header.get(HeaderFramework.CONNECTION_PROP_HOST);
       
        String host = hostSocket;
        int port = 80;
        final int pos = hostSocket.indexOf(":");       
        if (pos != -1) {
            port = Integer.parseInt(hostSocket.substring(pos + 1));
            host = hostSocket.substring(0, pos);
        }   
       
        prop.put("yacy", yacyonly ? "0" : "1");
        prop.put("yacy_host", host);
        prop.put("yacy_port", port);
       
        return prop;
    }
View Full Code Here

            rankingParameters.put(RankingProfile.YBR, "YaCy Block Rank;a higher ranking level prefers documents with a higher, statically assigned ranking value on domains. This is like a 'moderated ranking'. The ranking on domains (blocks) was computed using a link analyses on large link graphs.");
            rankingParameters.put(RankingProfile.LANGUAGE, "Preferred Language;a higher ranking level prefers documents with a language that matches the browser language.");
  }

    private static serverObjects defaultValues() {
        final serverObjects prop = new serverObjects();
        prop.put("search", "");
        prop.put("num-results", "0");
        prop.put("excluded", "0");
        prop.put("combine", "0");
        prop.put("resultbottomline", "0");
        prop.put("localCount", "10");
        prop.put("localWDist", "999");
        //prop.put("globalChecked", "checked");
        prop.put("globalChecked", "0");
        prop.put("postsortChecked", "1");
        prop.put("localTime", "6");
        prop.put("results", "");
        prop.put("urlmaskoptions", "0");
        prop.putHTML("urlmaskoptions_urlmaskfilter", ".*");
        prop.put("jumpToCursor", "1");
        return prop;
    }
View Full Code Here

        SearchEventCache.cleanupEvents(true);
       
        // case if no values are requested
        if ((post == null) || (sb == null)) {
            // we create empty entries for template strings
            final serverObjects prop = defaultValues();
            final RankingProfile ranking;
            if(sb == null) ranking = new RankingProfile(ContentDomain.TEXT);
            else ranking = sb.getRanking();
            putRanking(prop, ranking, "local");
            return prop;
        }
       
        if (post.containsKey("EnterRanking")) {
            final RankingProfile ranking = new RankingProfile("local", post.toString());
            sb.setConfig("rankingProfile", crypt.simpleEncode(ranking.toExternalString()));
            final serverObjects prop = defaultValues();
            //prop.putAll(ranking.toExternalMap("local"));
            putRanking(prop, ranking, "local");
            return prop;
        }
       
        if (post.containsKey("ResetRanking")) {
            sb.setConfig("rankingProfile", "");
            final RankingProfile ranking = new RankingProfile(ContentDomain.TEXT);
            final serverObjects prop = defaultValues();
            //prop.putAll(ranking.toExternalMap("local"));
            putRanking(prop, ranking, "local");
            return prop;
        }
       
        final RankingProfile localRanking = new RankingProfile("local", post.toString());
        final serverObjects prop = new serverObjects();
        putRanking(prop, localRanking, "local");
        prop.putAll(localRanking.toExternalMap("local"));

        return prop;
    }
View Full Code Here

TOP

Related Classes of de.anomic.server.serverObjects

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.