├── .github
└── FUNDING.yml
├── conf
└── config.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── bin
├── stop_rabbitmq.sh
├── clear_parser_queues.sh
├── index_size.sh
├── clear_indexer_queues.sh
├── clear_all_queues.sh
├── install_hq.sh
├── distribute_config.sh
├── prepare_index.sh
├── delete_index.sh
├── stop_elasticsearch.py
├── stop.sh
├── update_all.sh
├── clear_crawler_queues.sh
├── stop_all.py
├── start_rabbitmq.py
├── start_elasticsearch.py
├── clear_loader_queues.sh
└── run_all.py
├── .idea
├── vcs.xml
├── modules.xml
└── yacy_grid_mcp.iml
├── .gitignore
├── .pydevproject
├── .settings
├── org.eclipse.buildship.core.prefs
└── org.eclipse.jdt.core.prefs
├── src
└── main
│ ├── resources
│ └── log4j.properties
│ └── java
│ ├── org
│ └── json
│ │ ├── JSONString.java
│ │ ├── JSONException.java
│ │ ├── JSONPointerException.java
│ │ ├── JSONPropertyIgnore.java
│ │ ├── JSONPropertyName.java
│ │ └── XMLParserConfiguration.java
│ └── net
│ └── yacy
│ └── grid
│ ├── json
│ ├── JsonFactory.java
│ ├── JsonObjectWithDefault.java
│ ├── JsonList.java
│ ├── JsonRandomAccessFile.java
│ ├── JsonLDNode.java
│ └── JsonTray.java
│ ├── http
│ ├── APIException.java
│ ├── APIHandler.java
│ ├── Log.java
│ ├── ServiceResponse.java
│ ├── ObjectAPIHandler.java
│ └── AbstractAPIHandler.java
│ ├── geo
│ ├── LocationSource.java
│ ├── AbstractGeoPoint.java
│ ├── GeoPoint.java
│ └── IntegerGeoPoint.java
│ ├── tools
│ ├── GitTool.java
│ ├── SpaceExceededException.java
│ ├── MapTools.java
│ ├── ClassProvider.java
│ ├── CommonPattern.java
│ ├── IO.java
│ ├── Compression.java
│ ├── CacheMap.java
│ ├── HashARC.java
│ ├── ARC.java
│ ├── ComparableARC.java
│ ├── KeyList.java
│ ├── TimeoutMatcher.java
│ ├── MapUtil.java
│ ├── Memory.java
│ ├── Swagger.java
│ ├── AnchorURL.java
│ └── Punycode.java
│ ├── core
│ ├── api
│ │ ├── info
│ │ │ ├── LogService.java
│ │ │ └── StatusService.java
│ │ └── vis
│ │ │ └── MapService.java
│ └── Core.java
│ └── graphics
│ ├── AnimationPlotter.java
│ ├── CircleTool.java
│ └── PrintTool.java
├── .project
├── .classpath
├── .travis.yml
├── README.md
├── gradlew.bat
└── gradlew
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: orbiter
2 | patreon: 0rb1t3r
3 |
--------------------------------------------------------------------------------
/conf/config.properties:
--------------------------------------------------------------------------------
1 | # YaCy Grid Peer configuration
2 |
3 | # the default port of this peer
4 | port = 8010
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yacy/yacy_grid_core/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/bin/stop_rabbitmq.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | ps aux | grep rabbitmq | grep -v 'grep' |awk '{print $2}' | cut -d/ -f 1 | xargs kill
3 |
--------------------------------------------------------------------------------
/bin/clear_parser_queues.sh:
--------------------------------------------------------------------------------
1 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=parser&queueName=yacyparser_00'
2 |
--------------------------------------------------------------------------------
/bin/index_size.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 |
4 | curl http://elastic:changeme@localhost:9200/web/_count
5 | echo
6 |
--------------------------------------------------------------------------------
/bin/clear_indexer_queues.sh:
--------------------------------------------------------------------------------
1 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=indexer&queueName=elasticsearch_00'
2 |
--------------------------------------------------------------------------------
/bin/clear_all_queues.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 |
4 | ./clear_crawler_queues.sh &
5 | ./clear_parser_queues.sh &
6 | ./clear_indexer_queues.sh &
7 | ./clear_loader_queues.sh
8 |
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | classes/
2 | target/
3 | data/
4 | /class/
5 | /.gradle/
6 | /build/
7 | .DS_Store
8 | .settings
9 | .idea/
10 | yacy_grid_mcp.eml
11 | yacy_grid_mcp.iml
12 | bin/ai/
13 | bin/log4j.properties
14 | bin/net/
15 | bin/org/
16 |
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bin/install_hq.sh:
--------------------------------------------------------------------------------
1 | cd ../data/apps/
2 | wget https://github.com/ElasticHQ/elasticsearch-HQ/archive/v3.5.0.tar.gz
3 | tar xfz v3.5.0.tar.gz
4 | cd elasticsearch-HQ-3.5.0/
5 | pip3 install -r requirements.txt
6 | pip3 install flask_socketio
7 | pip3 install apscheduler
8 | pip3 install eventlet
9 | python3 application.py
10 |
--------------------------------------------------------------------------------
/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | Default
4 | python 2.7
5 |
6 |
--------------------------------------------------------------------------------
/bin/distribute_config.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 | cd ..
4 | cp data/mcp-8100/conf/config.properties ../yacy_grid_crawler/data/crawler-8300/conf/
5 | cp data/mcp-8100/conf/config.properties ../yacy_grid_loader/data/loader-8200/conf/
6 | cp data/mcp-8100/conf/config.properties ../yacy_grid_parser/data/parser-8500/conf/
7 |
--------------------------------------------------------------------------------
/bin/prepare_index.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 | cd ../conf/mappings
4 | curl -XPUT http://elastic:changeme@localhost:9200/web -H 'Content-Type: application/json' --data-binary "@web.json"
5 | curl -XPUT http://elastic:changeme@localhost:9200/crawler -H 'Content-Type: application/json' --data-binary "@crawler.json"
6 | echo
7 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | build.commands=org.eclipse.jdt.core.javabuilder
2 | connection.arguments=
3 | connection.java.home=null
4 | connection.jvm.arguments=
5 | connection.project.dir=
6 | derived.resources=.gradle,build
7 | eclipse.preferences.version=1
8 | natures=org.eclipse.jdt.core.javanature
9 | project.path=\:
10 |
--------------------------------------------------------------------------------
/bin/delete_index.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 |
4 | # the following command is not good, because afterwards the index must be prepared with the mapping again
5 | #curl -XDELETE 'http://elastic:changeme@localhost:9200/web'
6 |
7 | curl -XPOST 'http://elastic:changeme@localhost:9200/web/_delete_by_query' -d '{
8 | "query" : {
9 | "match_all" : {}
10 | }
11 | }'
12 |
13 | echo
14 |
--------------------------------------------------------------------------------
/bin/stop_elasticsearch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 |
3 | import subprocess
4 |
5 | p = subprocess.Popen("ps aux | grep 'org.elasticsearch.bootstrap.Elasticsearch' | grep -v grep | awk '{print $2}' | cut -d/ -f 1", shell=True, stdout=subprocess.PIPE)
6 | pid = p.stdout.read()
7 |
8 | if pid:
9 | print('killing elasticsearch, pid = ' + pid)
10 | subprocess.call('kill ' + pid, shell=True)
11 | else:
12 | print('elasticsearch was not running')
13 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Set root logger level to DEBUG and its only appender to A1.
2 | log4j.rootLogger=A1
3 |
4 | # A1 is set to be a ConsoleAppender.
5 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
6 |
7 | # A1 uses PatternLayout.
8 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
10 |
11 | log4j.logger.org.eclipse.jetty = INFO
12 | log4j.logger.org.apache.http = INFO
--------------------------------------------------------------------------------
/.idea/yacy_grid_mcp.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/bin/stop.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 | cd ../data
4 | KILLFILE="mcp-8100.kill"
5 | PIDFILE="mcp-8100.pid"
6 |
7 | # first method to terminate the process
8 | if [ -f "$KILLFILE" ];
9 | then
10 | rm $KILLFILE
11 | echo "termination requested, waiting.."
12 | # this can take 10 seconds..
13 | sleep 10
14 | fi
15 |
16 | # second method to terminate the process
17 | if [ -f "$PIDFILE" ];
18 | then
19 | fuser -k $PIDFILE
20 | fi
21 |
22 | # check if file does not exist any more which would be a sign that this has terminated
23 | if [ ! -f "$PIDFILE" ];
24 | then
25 | echo "process terminated"
26 | fi
27 |
28 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #
2 | #Tue Jan 10 22:46:12 CET 2017
3 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
4 | org.eclipse.jdt.core.compiler.compliance=1.8
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
7 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
8 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
9 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
10 | eclipse.preferences.version=1
11 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
12 | org.eclipse.jdt.core.compiler.source=1.8
13 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
14 |
--------------------------------------------------------------------------------
/bin/update_all.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | cd "`dirname $0`"
3 |
4 | cd ..
5 | echo updating `pwd`
6 | git pull origin master
7 | ./gradlew assemble
8 |
9 | cd ../yacy_grid_crawler
10 | echo updating `pwd`
11 | git submodule foreach git pull origin master
12 | git pull origin master
13 | ./gradlew assemble
14 |
15 | cd ../yacy_grid_loader
16 | echo updating `pwd`
17 | git submodule foreach git pull origin master
18 | git pull origin master
19 | ./gradlew assemble
20 |
21 | cd ../yacy_grid_parser
22 | echo updating `pwd`
23 | git submodule foreach git pull origin master
24 | git pull origin master
25 | ./gradlew assemble
26 |
27 | cd ../yacy_grid_search
28 | echo updating `pwd`
29 | git submodule foreach git pull origin master
30 | git pull origin master
31 | ./gradlew assemble
32 |
--------------------------------------------------------------------------------
/src/main/java/org/json/JSONString.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 | /**
3 | * The JSONString interface allows a toJSONString()
4 | * method so that a class can change the behavior of
5 | * JSONObject.toString(), JSONArray.toString(),
6 | * and JSONWriter.value(Object). The
7 | * toJSONString method will be used instead of the default behavior
8 | * of using the Object's toString() method and quoting the result.
9 | */
10 | public interface JSONString {
11 | /**
12 | * The toJSONString method allows a class to produce its own JSON
13 | * serialization.
14 | *
15 | * @return A strictly syntactically correct JSON text.
16 | */
17 | public String toJSONString();
18 | }
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | yacy_grid_core
4 | YaCy Grid Core
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 | org.python.pydev.PyDevBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.jdt.core.javanature
26 | org.eclipse.buildship.core.gradleprojectnature
27 | org.python.pydev.pythonNature
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/bin/clear_crawler_queues.sh:
--------------------------------------------------------------------------------
1 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_00'
2 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_01'
3 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_02'
4 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_03'
5 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_04'
6 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_05'
7 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_06'
8 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=crawler&queueName=webcrawler_07'
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | # Use node_js environnement
3 | language: java
4 |
5 | # Cache Gcloud SDK between commands
6 |
7 | cache:
8 | directories:
9 | - "$HOME/google-cloud-sdk/"
10 |
11 | # Install services
12 | services:
13 | - docker
14 |
15 | # Set env vars
16 | env:
17 | global:
18 | - GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json
19 | - PROJECT_NAME_STG=yacygrid
20 | - CLUSTER_NAME_STG=cluster-1
21 | - CLOUDSDK_COMPUTE_ZONE=us-central1-a
22 | - DOCKER_IMAGE_NAME=yacygridmcp
23 | - KUBE_DEPLOYMENT_NAME=yacygridmcp
24 | - KUBE_DEPLOYMENT_CONTAINER_NAME=yacygridmcp
25 | - NODE_ENV=CI
26 |
27 |
28 | script:
29 | - if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash; fi
30 | - source /home/travis/google-cloud-sdk/path.bash.inc
31 | - gcloud --quiet version
32 | - gcloud --quiet components update
33 | - gcloud --quiet components update kubectl
34 |
35 | branches:
36 | only:
37 | - master
38 | - development
39 |
--------------------------------------------------------------------------------
/bin/stop_all.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 |
3 | import os
4 | import socket
5 | import subprocess
6 | import signal
7 |
8 | path_apphome = os.path.dirname(os.path.abspath(__file__)) + '/..'
9 | os.chdir(path_apphome)
10 | # os.system('ls')
11 |
12 | def checkportopen(port):
13 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
14 | return sock.connect_ex(('127.0.0.1', port)) == 0
15 |
16 |
17 | if checkportopen(9200):
18 | print "killing elasticsearch"
19 | pid = subprocess.check_output(['fuser', path_apphome + '/data/mcp-8100/apps/elasticsearch/bin/nohup.out'])
20 | print 'pid is ', pid
21 | os.kill(int(pid), signal.SIGTERM)
22 |
23 |
24 | if checkportopen(2121):
25 | print "ftp server is running"
26 |
27 | if checkportopen(15672):
28 | print "rabbitmq is running"
29 |
30 | if checkportopen(8100):
31 | print "yacy_grid_mcp is running"
32 |
33 | if checkportopen(8200):
34 | print "yacy_grid_loader is running"
35 |
36 | if checkportopen(8300):
37 | print "yacy_grid_crawler is running"
38 |
39 | if checkportopen(8500):
40 | print "yacy_grid_parser is running"
41 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/json/JsonFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * JsonFactory
3 | * Copyright 02.10.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.json;
21 |
22 | import java.io.IOException;
23 |
24 | import org.json.JSONObject;
25 |
26 | public interface JsonFactory {
27 |
28 | public JSONObject getJSON() throws IOException;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/json/JSONException.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /**
4 | * The JSONException is thrown by the JSON.org classes when things are amiss.
5 | *
6 | * @author JSON.org
7 | * @version 2015-12-09
8 | */
9 | public class JSONException extends RuntimeException {
10 | /** Serialization ID */
11 | private static final long serialVersionUID = 0;
12 |
13 | /**
14 | * Constructs a JSONException with an explanatory message.
15 | *
16 | * @param message
17 | * Detail about the reason for the exception.
18 | */
19 | public JSONException(final String message) {
20 | super(message);
21 | }
22 |
23 | /**
24 | * Constructs a JSONException with an explanatory message and cause.
25 | *
26 | * @param message
27 | * Detail about the reason for the exception.
28 | * @param cause
29 | * The cause.
30 | */
31 | public JSONException(final String message, final Throwable cause) {
32 | super(message, cause);
33 | }
34 |
35 | /**
36 | * Constructs a new JSONException with the specified cause.
37 | *
38 | * @param cause
39 | * The cause.
40 | */
41 | public JSONException(final Throwable cause) {
42 | super(cause.getMessage(), cause);
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/http/APIException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * APIException
3 | * Copyright 19.05.2016 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.http;
21 |
22 | public class APIException extends Exception {
23 |
24 | private static final long serialVersionUID = -6974553774866005875L;
25 | private int statusCode = -1;
26 |
27 | public APIException(int statusCode, String message) {
28 | super(message);
29 | this.statusCode = statusCode;
30 | }
31 |
32 | public int getStatusCode() {
33 | return this.statusCode;
34 | }
35 | }
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/geo/LocationSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * LocationSource
3 | * Copyright 10.06.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.geo;
21 |
22 | public enum LocationSource {
23 |
24 | USER, // the (loklak) user has set the location, this is a hint that this is a rich tweet.
25 | REPORT, // location came from another source in identical way. This may be a IoT import.
26 | PLACE, // location came from translation of the given place name, which is in the context of messages an invisible meta-information.
27 | ANNOTATION; // location was detected and annotated from visible text content
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/json/JSONPointerException.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /*
4 | Copyright (c) 2002 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | /**
28 | * The JSONPointerException is thrown by {@link JSONPointer} if an error occurs
29 | * during evaluating a pointer.
30 | *
31 | * @author JSON.org
32 | * @version 2016-05-13
33 | */
34 | public class JSONPointerException extends JSONException {
35 | private static final long serialVersionUID = 8872944667561856751L;
36 |
37 | public JSONPointerException(String message) {
38 | super(message);
39 | }
40 |
41 | public JSONPointerException(String message, Throwable cause) {
42 | super(message, cause);
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/main/java/org/json/JSONPropertyIgnore.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /*
4 | Copyright (c) 2018 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import static java.lang.annotation.ElementType.METHOD;
28 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
29 |
30 | import java.lang.annotation.Documented;
31 | import java.lang.annotation.Retention;
32 | import java.lang.annotation.Target;
33 |
34 | @Documented
35 | @Retention(RUNTIME)
36 | @Target({METHOD})
37 | /**
38 | * Use this annotation on a getter method to override the Bean name
39 | * parser for Bean -> JSONObject mapping. If this annotation is
40 | * present at any level in the class hierarchy, then the method will
41 | * not be serialized from the bean into the JSONObject.
42 | */
43 | public @interface JSONPropertyIgnore { }
--------------------------------------------------------------------------------
/src/main/java/org/json/JSONPropertyName.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /*
4 | Copyright (c) 2018 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import static java.lang.annotation.ElementType.METHOD;
28 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
29 |
30 | import java.lang.annotation.Documented;
31 | import java.lang.annotation.Retention;
32 | import java.lang.annotation.Target;
33 |
34 | @Documented
35 | @Retention(RUNTIME)
36 | @Target({METHOD})
37 | /**
38 | * Use this annotation on a getter method to override the Bean name
39 | * parser for Bean -> JSONObject mapping. A value set to empty string ""
40 | * will have the Bean parser fall back to the default field name processing.
41 | */
42 | public @interface JSONPropertyName {
43 | /**
44 | * @return The name of the property as to be used in the JSON Object.
45 | */
46 | String value();
47 | }
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/geo/AbstractGeoPoint.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbstractGeoPoint
3 | * Copyright 03.06.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.geo;
21 |
22 | public abstract class AbstractGeoPoint implements GeoPoint {
23 |
24 | /**
25 | * compute the distance between two points using the Haversine Algorithm
26 | * https://en.wikipedia.org/wiki/Haversine_formula
27 | * @param othr the other point
28 | * @return the distance of this point and the other point in meter
29 | */
30 | public double distance(final GeoPoint othr) {
31 | return distance(this.lat(), this.lon(), othr.lat(), othr.lon());
32 | }
33 |
34 | public static double distance(final double lat1, final double lon1, final double lat2, final double lon2) {
35 | double dlat = (lat2 - lat1) * D2R; double dlon = (lon2 - lon1) * D2R;
36 | double a = Math.pow(Math.sin(dlat / 2.0d), 2.0d) +
37 | Math.cos(lat1 * D2R) * Math.cos(lat2 * D2R) * Math.pow(Math.sin(dlon / 2.0d), 2.0d);
38 | double c = 2.0d * Math.atan2(Math.sqrt(a), Math.sqrt(1.0d - a));
39 | return EQUATOR_EARTH_RADIUS * c;
40 | }
41 |
42 | static final double EQUATOR_EARTH_RADIUS = 6378137.0d;
43 | static final double D2R = (Math.PI / 180.0d);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/GitTool.java:
--------------------------------------------------------------------------------
1 | /**
2 | * GitTool
3 | * (C) 2018 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
4 | * first published 09.01.2018 on http://yacy.net
5 | *
6 | * This library is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * This library is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program in the file lgpl21.txt
18 | * If not, see .
19 | */
20 |
21 | package net.yacy.grid.tools;
22 |
23 | import java.io.File;
24 |
25 | import org.eclipse.jgit.api.Git;
26 | import org.eclipse.jgit.lib.Repository;
27 | import org.eclipse.jgit.revwalk.RevCommit;
28 |
29 | public class GitTool {
30 |
31 | public String name, message, branch;
32 |
33 | public GitTool() {
34 | File gitWorkDir = new File(".");
35 | try {
36 | Git git = Git.open(gitWorkDir);
37 | Iterable commits = git.log().all().call();
38 | Repository repo = git.getRepository();
39 | branch = repo.getBranch();
40 | RevCommit latestCommit = commits.iterator().next();
41 | name = latestCommit.getName();
42 | message = latestCommit.getFullMessage();
43 | } catch (Throwable e) {
44 | name = "";
45 | message = "";
46 | branch = "";
47 | }
48 | }
49 |
50 | public String toString() {
51 | return "branch " + branch + ": commit " + name + " " + message;
52 | }
53 |
54 | public static void main(String[] args) {
55 | System.out.println(new GitTool().toString());
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/core/api/info/LogService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * LogService
3 | * Copyright 02.01.2018 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.core.api.info;
21 |
22 | import java.util.List;
23 |
24 | import javax.servlet.http.HttpServletResponse;
25 |
26 | import net.yacy.grid.http.APIHandler;
27 | import net.yacy.grid.http.Log;
28 | import net.yacy.grid.http.ObjectAPIHandler;
29 | import net.yacy.grid.http.Query;
30 | import net.yacy.grid.http.ServiceResponse;
31 |
32 | /**
33 | * The Log Service
34 | * call http://localhost:8010/yacy/grid/core/info/log.txt
35 | */
36 | public class LogService extends ObjectAPIHandler implements APIHandler {
37 |
38 | private static final long serialVersionUID = -7095346222464124199L;
39 | public static final String NAME = "log";
40 |
41 | @Override
42 | public String getAPIPath() {
43 | return "/yacy/grid/core/info/" + NAME + ".txt";
44 | }
45 |
46 | @Override
47 | public ServiceResponse serviceImpl(Query post, HttpServletResponse response) {
48 | int count = post.get("count", 10000);
49 | final StringBuilder buffer = new StringBuilder(100000);
50 | List lines = Log.logAppender.getLines(count);
51 | for (int i = 0; i < lines.size(); i++) {
52 | buffer.append(lines.get(i)); // lines are stored with \n at end
53 | }
54 | return new ServiceResponse(buffer.toString());
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YaCy Grid Component: Core
2 |
3 | ## What is this?
4 | The YaCy Grid Core is a Leightweight Microservice Operating Environment.
5 | It includes:
6 | * a jetty-based web server
7 | * a very lightweight JSON library using the JSON-Java reference implementation
8 | * an infrastructure to implement servlets using these JSON classes
9 | * libraries for network communication and http clients
10 | * file-based storage classes for JSON objects
11 | * image-generating classes
12 | * a framework for time-series data including image graph generation
13 |
14 | This combination of a lightweight web server together with JSON, time series
15 | and graphics was arranged because most of API-implementing servers need the
16 | ability to easily implement a JSON API, handle network communication,
17 | be able to statify without the need of a database connection and also to
18 | support a telemetry service which makes it possible to monitor a large number
19 | of instances within a scalable microservice environment in an easy way.
20 |
21 | ## How to use this library?
22 | Right now we do not intend to publish the library as a jar file, instead we
23 | recommend to add this repository as a git submodule.
24 | If you have an existing project, do the following to add yacy_grid_core as
25 | as submodule:
26 | ```
27 | # open a shell and navigate to your project root path
28 | mkdir submodules
29 | cd submodules
30 | git submodule add https://github.com/yacy_yacy_grid_core
31 | ```
32 |
33 | Your project `` then can be checked out with
34 | ```
35 | git clone --recursive https://github.com/.git
36 | ```
37 |
38 | and an update to an already checked out project can be made with
39 | ```
40 | git pull origin master
41 | git submodule foreach git pull origin master
42 | ```
43 |
44 | ## How to compile and run yacy_grid_core
45 | Because this is a libaray and not an application there is not really a use
46 | running the program at all. However for demonstration purpose you can actually
47 | start the server without any usefull service.
48 |
49 | To build and run, do:
50 | ```
51 | gradle assemble
52 | gradle run
53 | ```
54 |
55 |
56 | ## What is the software license?
57 | LGPL 2.1 (C) by Michael Peter Christen
58 |
59 | Have fun!
60 | @0rb1t3r
61 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/SpaceExceededException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * SpaceExceededException
3 | * Copyright 14.01.2017 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.tools;
21 |
22 | import java.util.Date;
23 |
24 | public class SpaceExceededException extends Exception {
25 |
26 | private static final long serialVersionUID = 9059516027929222151L;
27 |
28 | private final String forUsage;
29 | private final long neededRAM, availableRAM, time;
30 |
31 | public SpaceExceededException(final long neededRAM, final String forUsage) {
32 | super(Long.toString(neededRAM) + " bytes needed for " + forUsage + ": " + Memory.available() + " free at " + (new Date()).toString());
33 | this.time = System.currentTimeMillis();
34 | this.availableRAM = Memory.available();
35 | this.neededRAM = neededRAM;
36 | this.forUsage = forUsage;
37 | }
38 |
39 | public SpaceExceededException(final long neededRAM, final String forUsage, final Throwable t) {
40 | super(Long.toString(neededRAM) + " bytes needed for " + forUsage + ": " + Memory.available() + " free at " + (new Date()).toString(), t);
41 | this.time = System.currentTimeMillis();
42 | this.availableRAM = Memory.available();
43 | this.neededRAM = neededRAM;
44 | this.forUsage = forUsage;
45 | }
46 |
47 | public String getUsage() {
48 | return this.forUsage;
49 | }
50 |
51 | public long getNeededRAM() {
52 | return this.neededRAM;
53 | }
54 |
55 | public long getAvailableRAM() {
56 | return this.availableRAM;
57 | }
58 |
59 | public long getTime() {
60 | return this.time;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/bin/start_rabbitmq.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 |
3 | # to run this script, erlang must be installed
4 | # Mac OS: brew install erlang
5 | # debian/ubuntu: apt-get install erlang
6 |
7 | import os
8 | import time
9 | import socket
10 | import urllib
11 | import subprocess
12 |
13 | #https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-generic-unix-3.7.14.tar.xz
14 |
15 | rabbitversion = 'rabbitmq-server-generic-unix-3.7.14'
16 | rabbitfilename = 'rabbitmq_server-3.7.14'
17 |
18 | path_apphome = os.path.dirname(os.path.abspath(__file__)) + '/..'
19 | os.chdir(path_apphome)
20 | # os.system('ls')
21 |
22 | def checkportopen(port):
23 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
24 | return sock.connect_ex(('127.0.0.1', port)) == 0
25 |
26 | def mkapps():
27 | if not os.path.isdir(path_apphome + '/data'): os.makedirs(path_apphome + '/data')
28 | if not os.path.isdir(path_apphome + '/data/apps'): os.makedirs(path_apphome + '/data/apps')
29 |
30 | if not checkportopen(5672):
31 | print('rabbitmq is not running')
32 | mkapps()
33 | if not os.path.isfile(path_apphome + '/data/apps/' + rabbitversion + '.tar.xz'):
34 | print('downloading ' + rabbitversion)
35 | downloadurl = 'https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/' + rabbitversion + '.tar.xz'
36 | downloadpath = path_apphome + '/data/apps/' + rabbitversion + '.tar.xz'
37 | print('Download URL is: ' + downloadurl + ', Path is ' + downloadpath)
38 | urllib.urlretrieve(downloadurl, downloadpath)
39 | rabbitpath = path_apphome + '/data/apps/rabbitmq'
40 | if not os.path.isdir(rabbitpath):
41 | print('decompressing ' + rabbitversion)
42 | os.system('tar xJf ' + path_apphome + '/data/apps/' + rabbitversion + '.tar.xz -C ' + path_apphome + '/data/apps/')
43 | os.rename(path_apphome + '/data/apps/' + rabbitfilename, rabbitpath)
44 | # run rabbitmq
45 | print('running rabbitmq')
46 | os.chdir(rabbitpath + '/sbin')
47 | subprocess.call('./rabbitmq-server &', shell=True)
48 | time.sleep(5)
49 | subprocess.call('./rabbitmq-plugins enable rabbitmq_management', shell=True)
50 | subprocess.call('./rabbitmqctl add_user anonymous yacy', shell=True)
51 | subprocess.call('./rabbitmqctl set_user_tags anonymous administrator', shell=True)
52 | subprocess.call('./rabbitmqctl set_permissions -p / anonymous ".*" ".*" ".*"', shell=True)
53 |
54 | print('to view the administration pages, open http://127.0.0.1:15672/')
55 | print('log in with anonymous:yacy')
56 |
--------------------------------------------------------------------------------
/bin/start_elasticsearch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 |
3 | import os
4 | import time
5 | import socket
6 | import urllib
7 | import subprocess
8 |
9 | elasticversion = 'elasticsearch-6.8.1'
10 |
11 | path_apphome = os.path.dirname(os.path.abspath(__file__)) + '/..'
12 | os.chdir(path_apphome)
13 | # os.system('ls')
14 |
15 | def checkportopen(port):
16 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17 | return sock.connect_ex(('127.0.0.1', port)) == 0
18 |
19 | def mkapps():
20 | if not os.path.isdir(path_apphome + '/data'): os.makedirs(path_apphome + '/data')
21 | if not os.path.isdir(path_apphome + '/data/apps'): os.makedirs(path_apphome + '/data/apps')
22 |
23 | if checkportopen(9200):
24 | print('elasticsearch is already running!')
25 | else:
26 | print('elasticsearch is not running')
27 | mkapps()
28 | if not os.path.isfile(path_apphome + '/data/apps/' + elasticversion + '.tar.gz'):
29 | print('downloading ' + elasticversion)
30 | urllib.urlretrieve ('https://artifacts.elastic.co/downloads/elasticsearch/' + elasticversion + '.tar.gz', path_apphome + '/data/apps/' + elasticversion + '.tar.gz')
31 | elasticpath = path_apphome + '/data/apps/elasticsearch'
32 | firstrun = False
33 | if not os.path.isdir(elasticpath):
34 | print('decompressing' + elasticversion)
35 | os.system('tar xfz ' + path_apphome + '/data/apps/' + elasticversion + '.tar.gz -C ' + path_apphome + '/data/apps/')
36 | os.rename(path_apphome + '/data/apps/' + elasticversion, elasticpath)
37 | os.system('sed -i "s/#network.host: 192.168.0.1/network.host: 0.0.0.0/g" ' + elasticpath + '/config/elasticsearch.yml')
38 | os.system('sed -i "s/#cluster.name: my-application/cluster.name: elasticsearch/g" ' + elasticpath + '/config/elasticsearch.yml')
39 | firstrun = True
40 | # run elasticsearch
41 | print('starting elasticsearch...')
42 | os.chdir(elasticpath + '/bin')
43 | if not os.path.isdir(elasticpath + '/data'): os.makedirs(elasticpath + '/data')
44 | logpath = elasticpath + '/log'
45 | if not os.path.isfile(logpath): os.system('touch ' + logpath)
46 | subprocess.call('./elasticsearch >> ' + logpath + ' &', shell=True)
47 | if firstrun:
48 | while not checkportopen(9200):
49 | print('waiting until elasticsearch is running...')
50 | time.sleep(3)
51 | print('elasticsearch is running at http://127.0.0.1:9200/')
52 | #print('preparing index...')
53 | #os.chdir(path_apphome)
54 | #subprocess.call('bin/prepare_index.sh', shell=True)
55 |
56 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/MapTools.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MapTools
3 | * Copyright 23.03.2016 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.tools;
21 |
22 | import java.util.Collections;
23 | import java.util.HashMap;
24 | import java.util.LinkedHashMap;
25 | import java.util.Map;
26 | import java.util.concurrent.atomic.AtomicInteger;
27 | import java.util.stream.Collectors;
28 |
29 | public class MapTools {
30 |
31 | /**
32 | * sort a given map by the value
33 | * @param map
34 | * @return a map with the same keys where the key with the highest value is first
35 | */
36 | public static > LinkedHashMap sortByValue(Map map) {
37 | return map
38 | .entrySet()
39 | .stream()
40 | .sorted(Map.Entry.comparingByValue(Collections.reverseOrder()))
41 | .collect(Collectors.toMap(
42 | Map.Entry::getKey,
43 | Map.Entry::getValue,
44 | (e1, e2) -> e1,
45 | LinkedHashMap::new
46 | ));
47 | }
48 |
49 | public static Map deatomize(Map map) {
50 | final Map a = new HashMap<>();
51 | map.forEach((k, v) -> a.put(k, v.intValue()));
52 | return a;
53 | }
54 |
55 | public static void incCounter(Map map, K key) {
56 | incCounter(map, key, 1);
57 | }
58 |
59 | public static void incCounter(Map map, K key, int inc) {
60 | AtomicInteger c = map.get(key);
61 | if (c == null) {
62 | c = new AtomicInteger(0);
63 | map.put(key, c);
64 | }
65 | c.addAndGet(inc);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/ClassProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ClassProvider
3 | * Copyright 201 by Michael Peter Christen, mc@yacy.net, Frankfurt a. M., Germany
4 | * First released 13.12.2011 at http://yacy.net
5 | *
6 | * This library is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * This library is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program in the file lgpl21.txt
18 | * If not, see .
19 | */
20 |
21 | package net.yacy.grid.tools;
22 |
23 | import java.io.File;
24 | import java.lang.reflect.Method;
25 | import java.net.MalformedURLException;
26 | import java.net.URL;
27 | import java.net.URLClassLoader;
28 |
29 | public class ClassProvider {
30 |
31 | public static Class> load(final String classname, final File jarfile) {
32 | Class> c;
33 | try {
34 | c = Class.forName(classname);
35 | } catch (final ClassNotFoundException e) {
36 | c = null;
37 | }
38 | if (c == null) {
39 | // load jar
40 | String path = jarfile.getAbsolutePath();
41 | if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/');
42 | if (!path.startsWith("/")) path = "/" + path;
43 | URL[] urls;
44 | try {
45 | urls = new URL[]{new URL("file", "", path)};
46 | @SuppressWarnings("resource")
47 | final ClassLoader cl = new URLClassLoader(urls);
48 | c = cl.loadClass(classname);
49 | } catch (final MalformedURLException e) {
50 | } catch (final ClassNotFoundException e) {
51 | }
52 | }
53 | return c;
54 | }
55 |
56 | public static Method getStaticMethod(final Class> c, final String methodName, final Class>[] args) {
57 | if (c == null) return null;
58 | try {
59 | return c.getMethod(methodName, args);
60 | } catch (final SecurityException e) {
61 | return null;
62 | } catch (final NoSuchMethodException e) {
63 | return null;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/http/APIHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * APIHandler
3 | * Copyright 17.05.2016 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.http;
21 |
22 | import java.io.IOException;
23 | import java.util.Map;
24 |
25 | import javax.servlet.http.HttpServletResponse;
26 |
27 | import org.json.JSONObject;
28 |
29 | /**
30 | * Interface for all servlets
31 | */
32 | public interface APIHandler {
33 |
34 | /**
35 | * get the path to the servlet
36 | * @return the url path of the servlet
37 | */
38 | public String getAPIPath();
39 |
40 | /**
41 | * get a name of the servlet (which can be used in the Action object to use servlets for contract actions)
42 | * @return the name element from getAPIPath()
43 | */
44 | public String getAPIName();
45 |
46 | /**
47 | * call the servlet with a query locally without a network connection
48 | * @param call a query object
49 | * @param response a http response object
50 | * @return a Service Response
51 | * @throws APIException
52 | */
53 | public ServiceResponse serviceImpl(Query call, HttpServletResponse response) throws APIException;
54 |
55 | /**
56 | * call a remote servlet with given params
57 | * @param protocolhostportstub the url stub string
58 | * @param params a json object with a set of key/values where each value is of type String
59 | * @return a Service Response
60 | * @throws IOException
61 | */
62 | public ServiceResponse serviceImpl(final String protocolhostportstub, JSONObject params) throws IOException;
63 |
64 | /**
65 | * call a remote servlet with given params
66 | * @param protocolhostportstub the url stub string
67 | * @param params a map object with a set of key/values where each value is of type byte[]
68 | * @return a Service Response
69 | * @throws IOException
70 | */
71 | public ServiceResponse serviceImpl(final String protocolhostportstub, Map params) throws IOException;
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/geo/GeoPoint.java:
--------------------------------------------------------------------------------
1 | /**
2 | * GeoPoint
3 | * Copyright 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
4 | * first published 08.10.2009 on http://yacy.net
5 | *
6 | * This file is part of YaCy Content Integration
7 | *
8 | * This library is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * This library is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with this program in the file lgpl21.txt
20 | * If not, see .
21 | */
22 |
23 | package net.yacy.grid.geo;
24 |
25 |
26 | /**
27 | * Geolocation storage may vary using different data structures for the points.
28 | * The reason to have different implementation is to save memory for the point storage.
29 | * With each version of a point storage comes a accuracy level which can be returned by the object.
30 | */
31 | public interface GeoPoint {
32 |
33 | public static final double meter = 90.0d / 1.0e7d; // this is actually the definition of 'meter': 10 million meter shall be the distance from the equator to the pole
34 |
35 | /**
36 | * get the latitude of the point
37 | * @return
38 | */
39 | public double lat();
40 |
41 | /**
42 | * get the longitude of the point
43 | * @return
44 | */
45 | public double lon();
46 |
47 | /**
48 | * get the implementation-dependent accuracy of the latitude
49 | * @return
50 | */
51 | public double accuracyLat();
52 |
53 | /**
54 | * get the implementation-dependent accuracy of the longitude
55 | * @return
56 | */
57 | public double accuracyLon();
58 |
59 | /**
60 | * compute the hash code of a coordinate
61 | * this produces identical hash codes for locations that are close to each other
62 | */
63 | @Override
64 | public int hashCode();
65 |
66 | /**
67 | * equality test that is needed to use the class inside HashMap/HashSet
68 | */
69 | @Override
70 | public boolean equals(final Object o);
71 |
72 | /**
73 | * compute the distance between two points using the Haversine Algorithm
74 | * https://en.wikipedia.org/wiki/Haversine_formula
75 | * @param othr the other point
76 | * @return the distance of this point and the other point in meter
77 | */
78 | public double distance(final GeoPoint othr);
79 |
80 | /**
81 | * printout format of the point
82 | * @return
83 | */
84 | @Override
85 | public String toString();
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/CommonPattern.java:
--------------------------------------------------------------------------------
1 | /**
2 | * CommonPattern
3 | * Copyright 2012 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
4 | * First published 26.11.2012 on http://yacy.net
5 | *
6 | * This library is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * This library is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program in the file lgpl21.txt
18 | * If not, see .
19 | */
20 |
21 | package net.yacy.grid.tools;
22 |
23 | import java.util.regex.Pattern;
24 |
25 | /**
26 | * This class provides Pattern constants to be used
27 | * to replace a regex in s.split(regex) method calls.
28 | * Because s.split(regex) causes an execution of
29 | * Pattern.compile(regex).split(s, 0), it is wise to pre-compile
30 | * all regex to a pattern p.
31 | * Therefore do the following: transform your code into
32 | * Pattern p = Pattern.compile(regex); p.split(s);
33 | * The compilation of a specific pattern should be done only once.
34 | * Therefore this class provides Pattern objects for the most common regex Strings.
35 | *
36 | * The same applies to s.replaceall(regex, replacement) which is equal to
37 | * Pattern.compile(regex).matcher(s).replaceAll(replacement);
38 | */
39 | public class CommonPattern {
40 |
41 | public final static Pattern SPACE = Pattern.compile(" ");
42 | public final static Pattern SPACES = Pattern.compile(" +"); // pattern for one or multiple spaces
43 | public final static Pattern COMMA = Pattern.compile(",");
44 | public final static Pattern SEMICOLON = Pattern.compile(";");
45 | public final static Pattern DOUBLEPOINT = Pattern.compile(":");
46 | public final static Pattern SLASH = Pattern.compile("/");
47 | public final static Pattern PIPE = Pattern.compile("\\|");
48 | public final static Pattern BACKSLASH = Pattern.compile("\\\\");
49 | public final static Pattern QUESTION = Pattern.compile("\\?");
50 | public final static Pattern AMP = Pattern.compile("&");
51 | public final static Pattern PLUS = Pattern.compile(Pattern.quote("+"));
52 | public final static Pattern DOT = Pattern.compile("\\.");
53 | public final static Pattern NEWLINE = Pattern.compile("\n");
54 | public final static Pattern VERTICALBAR = Pattern.compile(Pattern.quote("|"));
55 | public final static Pattern UNDERSCORE = Pattern.compile("_");
56 | public final static Pattern TAB = Pattern.compile("\t");
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/core/api/info/StatusService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * StatusService
3 | * Copyright 27.02.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.core.api.info;
21 |
22 | import javax.servlet.http.HttpServletResponse;
23 |
24 | import org.json.JSONObject;
25 |
26 | import net.yacy.grid.http.APIHandler;
27 | import net.yacy.grid.http.APIServer;
28 | import net.yacy.grid.http.ObjectAPIHandler;
29 | import net.yacy.grid.http.Query;
30 | import net.yacy.grid.http.ServiceResponse;
31 | import net.yacy.grid.tools.OS;
32 |
33 | // test: http://localhost:8010/yacy/grid/core/info/status.json
34 | public class StatusService extends ObjectAPIHandler implements APIHandler {
35 |
36 | private static final long serialVersionUID = 8578478303032749479L;
37 | public static final String NAME = "status";
38 |
39 | @Override
40 | public String getAPIPath() {
41 | return "/yacy/grid/core/info/" + NAME + ".json";
42 | }
43 |
44 | @Override
45 | public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
46 |
47 | // generate json
48 | Runtime runtime = Runtime.getRuntime();
49 | JSONObject json = new JSONObject(true);
50 | JSONObject system = new JSONObject(true);
51 | system.put("service", APIServer.getName());
52 | system.put("assigned_memory", runtime.maxMemory());
53 | system.put("used_memory", runtime.totalMemory() - runtime.freeMemory());
54 | system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory());
55 | system.put("cores", runtime.availableProcessors());
56 | system.put("threads", Thread.activeCount());
57 | system.put("load_system_average", OS.getSystemLoadAverage());
58 | //system.put("load_system_cpu", OS.getSystemCpuLoad());
59 | system.put("load_process_cpu", OS.getProcessCpuLoad());
60 | system.put("server_threads", APIServer.getServerThreads());
61 |
62 | JSONObject client_info = new JSONObject(true);
63 | JSONObject request_header = new JSONObject(true);
64 | client_info.put("request_header", request_header);
65 |
66 | json.put("system", system);
67 | json.put("client_info", client_info);
68 |
69 | return new ServiceResponse(json);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/IO.java:
--------------------------------------------------------------------------------
1 | package net.yacy.grid.tools;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.security.*;
7 | import java.security.spec.InvalidKeySpecException;
8 | import java.security.spec.X509EncodedKeySpec;
9 | import java.util.Base64;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import net.yacy.grid.http.Log;
14 |
15 | public final class IO {
16 |
17 | private static Map map;
18 | private static boolean initialized = false;
19 |
20 | public static String readFile(Path path) throws IOException {
21 | byte[] encoded = Files.readAllBytes(path);
22 | return new String(encoded);
23 | }
24 |
25 | public static String readFileCached(Path path) throws IOException
26 | {
27 | Path absPath = path.toAbsolutePath();
28 | if(!initialized) init();
29 | if(map.containsKey(absPath)){
30 | return map.get(absPath);
31 | }
32 | else{
33 | String result = readFile(absPath);
34 | map.put(absPath, result);
35 | return result;
36 | }
37 | }
38 |
39 | private static void init(){
40 | map = new HashMap();
41 | initialized = true;
42 | }
43 |
44 | /**
45 | * Create hash for a key
46 | * @param pubkey
47 | * @param algorithm
48 | * @return String hash
49 | */
50 | public static String getKeyHash(PublicKey pubkey, String algorithm){
51 | try {
52 | MessageDigest md = MessageDigest.getInstance(algorithm);
53 | md.update(pubkey.getEncoded());
54 | return Base64.getEncoder().encodeToString(md.digest());
55 | } catch (NoSuchAlgorithmException e) {
56 | Log.logger.error("", e);
57 | }
58 | return null;
59 | }
60 |
61 | /**
62 | * Create hash for a key, use default algorithm SHA-256
63 | * @param pubkey
64 | * @return String hash
65 | */
66 | public static String getKeyHash(PublicKey pubkey){
67 | return getKeyHash(pubkey, "SHA-256");
68 | }
69 |
70 | /**
71 | * Get String representation of a key
72 | * @param key
73 | * @return String representation of a key
74 | */
75 | public static String getKeyAsString(Key key){
76 | return Base64.getEncoder().encodeToString(key.getEncoded());
77 | }
78 |
79 | /**
80 | * Create PublicKey from String representation
81 | * @param encodedKey
82 | * @param algorithm
83 | * @return PublicKey public_key
84 | */
85 | public synchronized static PublicKey decodePublicKey(String encodedKey, String algorithm){
86 | try{
87 | X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(encodedKey));
88 | PublicKey pub = KeyFactory.getInstance(algorithm).generatePublic(keySpec);
89 | return pub;
90 | }
91 | catch(NoSuchAlgorithmException | InvalidKeySpecException e) {
92 | Log.logger.error("", e);
93 | }
94 | return null;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/core/Core.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Base
3 | * Copyright 14.01.2017 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.core;
21 |
22 | import java.io.IOException;
23 | import java.util.ArrayList;
24 | import java.util.Arrays;
25 | import java.util.List;
26 |
27 | import javax.servlet.Servlet;
28 |
29 | import net.yacy.grid.core.api.info.LogService;
30 | import net.yacy.grid.core.api.info.StatusService;
31 | import net.yacy.grid.core.api.info.ThreaddumpService;
32 | import net.yacy.grid.core.api.vis.MapService;
33 | import net.yacy.grid.core.api.vis.MarkdownService;
34 | import net.yacy.grid.http.APIServer;
35 | import net.yacy.grid.http.Log;
36 | import net.yacy.grid.tools.GitTool;
37 |
38 | public class Core {
39 |
40 | public final static String DATA_PATH = "data";
41 |
42 | // define services
43 | @SuppressWarnings("unchecked")
44 | public final static Class extends Servlet>[] BASE_SERVICES = new Class[]{
45 | // information services
46 | StatusService.class,
47 | ThreaddumpService.class,
48 | LogService.class,
49 |
50 | // graphic services
51 | MapService.class,
52 | MarkdownService.class
53 | };
54 |
55 | public static void main(String[] args) {
56 | // initialize environment variables
57 | System.setProperty("java.awt.headless", "true"); // no awt used here so we can switch off that stuff
58 |
59 | // start server
60 | List> services = new ArrayList<>();
61 | services.addAll(Arrays.asList(BASE_SERVICES));
62 | APIServer.initEnvironment("base", 8888, services, DATA_PATH, true);
63 | try {
64 | APIServer.open(null, false);
65 |
66 | // start server
67 | Log.logger.info("started Base!");
68 | Log.logger.info("read status of base peer:");
69 | Log.logger.info("curl http://127.0.0.1:8010/yacy/grid/core/info/status.json");
70 | Log.logger.info("curl http://127.0.0.1:8010/yacy/grid/core/info/log.txt");
71 | Log.logger.info("curl http://127.0.0.1:8010/yacy/grid/core/info/threaddump.txt");
72 | Log.logger.info(new GitTool().toString());
73 | APIServer.runService(null);
74 | } catch (IOException e) {
75 | Log.logger.info("cannot start Base");
76 | e.printStackTrace();
77 | }
78 |
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/bin/clear_loader_queues.sh:
--------------------------------------------------------------------------------
1 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_00'
2 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_01'
3 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_02'
4 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_03'
5 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_04'
6 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_05'
7 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_06'
8 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_07'
9 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_08'
10 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_09'
11 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_10'
12 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_11'
13 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_12'
14 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_13'
15 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_14'
16 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_15'
17 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_16'
18 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_17'
19 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_18'
20 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_19'
21 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_20'
22 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_21'
23 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_22'
24 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_23'
25 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_24'
26 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_25'
27 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_26'
28 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_27'
29 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_28'
30 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_29'
31 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_30'
32 | curl 'http://127.0.0.1:8100/yacy/grid/mcp/messages/clear.json?serviceName=loader&queueName=webloader_31'
33 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/json/JsonObjectWithDefault.java:
--------------------------------------------------------------------------------
1 | /**
2 | * UserManagement
3 | * Copyright 23.06.2015 by Robert Mader, @treba13
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.json;
21 |
22 | import org.json.JSONArray;
23 | import org.json.JSONObject;
24 |
25 | /**
26 | * This class extends JSONObjects with additional get-methods that accept default values. It catches all possible errors and exceptions,
27 | * thus always returning a valid output. It's intention is to provide a saver way to acquire values in security/stability sensitive environments
28 | */
29 | public class JsonObjectWithDefault extends JSONObject {
30 |
31 | public JsonObjectWithDefault(){
32 | super();
33 | }
34 |
35 | public JsonObjectWithDefault(JSONObject src){
36 | this();
37 | if(src != null) putAll(src);
38 | }
39 |
40 | public boolean getBoolean(String key, boolean dftval){
41 | try{
42 | return getBoolean(key);
43 | }
44 | catch (Throwable e){
45 | return dftval;
46 | }
47 | }
48 |
49 | public double getDouble(String key, double dftval){
50 | try{
51 | return getDouble(key);
52 | }
53 | catch (Throwable e){
54 | return dftval;
55 | }
56 | }
57 |
58 | public int getInt(String key, int dftval){
59 | try{
60 | return getInt(key);
61 | }
62 | catch (Throwable e){
63 | return dftval;
64 | }
65 | }
66 | public JSONArray getJSONArray(String key, JSONArray dftval){
67 | try{
68 | return getJSONArray(key);
69 | }
70 | catch (Throwable e){
71 | return dftval;
72 | }
73 | }
74 | public JSONObject getJSONObject(String key, JSONObject dftval){
75 | try{
76 | return getJSONObject(key);
77 | }
78 | catch (Throwable e){
79 | return dftval;
80 | }
81 | }
82 |
83 | public JsonObjectWithDefault getJSONObjectWithDefault(String key, JsonObjectWithDefault dftval){
84 | try{
85 | return new JsonObjectWithDefault(getJSONObject(key));
86 | }
87 | catch (Throwable e){
88 | return dftval;
89 | }
90 | }
91 | public long getLong(String key, long dftval){
92 | try{
93 | return getLong(key);
94 | }
95 | catch (Throwable e){
96 | return dftval;
97 | }
98 | }
99 | public String getString(String key, String dftval){
100 | try{
101 | return getString(key);
102 | }
103 | catch (Throwable e){
104 | return dftval;
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/graphics/AnimationPlotter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AnimationPlotter
3 | * Copyright 2013 by Michael Christen
4 | * First released 9.9.2010 at http://yacy.net
5 | *
6 | * This library is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * This library is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program in the file lgpl21.txt
18 | * If not, see .
19 | */
20 |
21 | package net.yacy.grid.graphics;
22 |
23 | import java.awt.image.BufferedImage;
24 | import java.io.File;
25 | import java.io.FileOutputStream;
26 | import java.io.IOException;
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | import javax.imageio.ImageIO;
31 | import javax.swing.ImageIcon;
32 | import javax.swing.JFrame;
33 | import javax.swing.JLabel;
34 |
35 | public class AnimationPlotter {
36 |
37 | public static class Frame {
38 | BufferedImage image;
39 | int delayMillis;
40 | public Frame(BufferedImage image, int delayMillis) {
41 | this.image = image;
42 | this.delayMillis = delayMillis;
43 | }
44 | }
45 |
46 | private final List frames;
47 |
48 |
49 | public AnimationPlotter() {
50 | this.frames = new ArrayList();
51 | }
52 |
53 | public void addFrame(final BufferedImage image, final int delayMillis) {
54 | this.frames.add(new Frame(image, delayMillis));
55 | }
56 |
57 |
58 | public void save(final File path, final String filestub, final String type) throws IOException {
59 | assert path.isDirectory();
60 | for (int i = 0; i < this.frames.size(); i++) {
61 | Frame frame = this.frames.get(i);
62 | File file = new File(path, filestub + "_" + intformat(i) + '.' + type);
63 | final FileOutputStream fos = new FileOutputStream(file);
64 | ImageIO.write(frame.image, type, fos);
65 | fos.close();
66 | }
67 | }
68 |
69 | private String intformat(final int i) {
70 | String n = Integer.toString(i);
71 | while (n.length() < 6) n = '0' + n;
72 | return n;
73 | }
74 |
75 | /**
76 | * show the images as stream of JFrame on desktop
77 | */
78 | public void show() {
79 | JFrame f = new JFrame();
80 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
81 | f.setVisible(true);
82 | JLabel label = null;
83 | while (true) {
84 | for (int i = 0; i < this.frames.size(); i++) {
85 | Frame frame = this.frames.get(i);
86 | if (label == null) {
87 | label = new JLabel(new ImageIcon(frame.image));
88 | f.getContentPane().add(label);
89 | f.pack();
90 | } else {
91 | label.getGraphics().drawImage(frame.image,0,0, label);
92 | }
93 | try {Thread.sleep(frame.delayMillis);} catch (InterruptedException e) {}
94 | }
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/Compression.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Compression
3 | * Copyright 12.06.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.tools;
21 |
22 | import java.io.BufferedInputStream;
23 | import java.io.BufferedOutputStream;
24 | import java.io.ByteArrayInputStream;
25 | import java.io.ByteArrayOutputStream;
26 | import java.io.File;
27 | import java.io.FileInputStream;
28 | import java.io.FileOutputStream;
29 | import java.io.IOException;
30 | import java.util.zip.Deflater;
31 | import java.util.zip.GZIPInputStream;
32 | import java.util.zip.GZIPOutputStream;
33 |
34 | public class Compression {
35 |
36 | public static void gzip(File source, File dest, boolean deleteSource) throws IOException {
37 | byte[] buffer = new byte[2^20];
38 | GZIPOutputStream out = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(dest), 65536)){{def.setLevel(Deflater.BEST_COMPRESSION);}};
39 | FileInputStream in = new FileInputStream(source);
40 | int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l);
41 | in.close(); out.finish(); out.close();
42 | if (deleteSource && dest.exists()) source.delete();
43 | }
44 |
45 | public static byte[] gzip(byte[] b) {
46 | try {
47 | ByteArrayOutputStream baos = new ByteArrayOutputStream(b.length);
48 | GZIPOutputStream out = new GZIPOutputStream(baos, Math.min(65536, b.length)){{def.setLevel(Deflater.BEST_COMPRESSION);}};
49 | out.write(b, 0, b.length);
50 | out.finish();
51 | out.close();
52 | return baos.toByteArray();
53 | } catch (IOException e) {}
54 | return null;
55 | }
56 |
57 | public static void gunzip(File source, File dest, boolean deleteSource) throws IOException {
58 | byte[] buffer = new byte[2^20];
59 | FileOutputStream out = new FileOutputStream(dest);
60 | GZIPInputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(source)));
61 | int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l);
62 | in.close(); out.close();
63 | if (deleteSource && dest.exists()) source.delete();
64 | }
65 |
66 | public static byte[] gunzip(byte[] b) {
67 | byte[] buffer = new byte[Math.min(2^20, b.length)];
68 | try {
69 | ByteArrayOutputStream baos = new ByteArrayOutputStream(b.length * 2);
70 | GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(b), Math.min(65536, b.length));
71 | int l; while ((l = in.read(buffer)) > 0) baos.write(buffer, 0, l);
72 | in.close();
73 | baos.close();
74 | return baos.toByteArray();
75 | } catch (IOException e) {}
76 | return null;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/CacheMap.java:
--------------------------------------------------------------------------------
1 | /**
2 | * CacheMap
3 | * Copyright 22.02.2015 by Michael Peter Christen, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.tools;
21 |
22 | import java.util.Iterator;
23 | import java.util.LinkedHashMap;
24 |
25 | public class CacheMap {
26 |
27 | private int maxSize;
28 | private LinkedHashMap map;
29 |
30 | public CacheMap(int maxSize) {
31 | this.maxSize = maxSize;
32 | this.map = new LinkedHashMap();
33 | }
34 |
35 | public int size() {
36 | return this.map.size();
37 | }
38 |
39 | public int maxSize() {
40 | return this.maxSize;
41 | }
42 |
43 | public void clear() {
44 | this.map.clear();
45 | }
46 |
47 | private void checkSize() {
48 | if (this.map.size() >= this.maxSize) {
49 | Iterator i = this.map.keySet().iterator();
50 | while (i.hasNext() && this.map.size() > this.maxSize) this.map.remove(i.next());
51 | }
52 | }
53 |
54 | public boolean full() {
55 | return this.map.size() >= this.maxSize;
56 | }
57 |
58 | public V put(K key, V value) {
59 | V oldval;
60 | synchronized (this.map) {
61 | // make room; this may remove entries from the beginning of the list
62 | checkSize();
63 |
64 | // we remove the value first to ensure that the value gets at the end of the list
65 | oldval = this.map.remove(key);
66 |
67 | // the new value gets to the end of the list
68 | this.map.put(key, value);
69 | }
70 | return oldval;
71 | }
72 |
73 | public V get(K key) {
74 | V value;
75 | synchronized (this.map) {
76 | // we remove the value to add it again at the end of the list
77 | value = this.map.remove(key);
78 |
79 | // in case that the entry does not exist we are ready here
80 | if (value == null) {
81 | return null;
82 | }
83 |
84 | // the old value gets to the end of the list
85 | this.map.put(key, value);
86 | }
87 | return value;
88 | }
89 |
90 | public V remove(K key) {
91 | synchronized (this.map) {
92 | return this.map.remove(key);
93 | }
94 | }
95 |
96 | public boolean exist(K key) {
97 | boolean exist = false;
98 | synchronized (this.map) {
99 | exist = this.map.containsKey(key);
100 | }
101 | return exist;
102 | }
103 |
104 | public LinkedHashMap getMap(){
105 | return map;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/tools/HashARC.java:
--------------------------------------------------------------------------------
1 | /**
2 | * HashARC
3 | * an Adaptive Replacement Cache for objects that can be compared using hashing
4 | * Copyright 2009 by Michael Peter Christen, mc@yacy.net, Frankfurt a. M., Germany
5 | * First released 17.04.2009 at http://yacy.net
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with this program in the file lgpl21.txt
19 | * If not, see .
20 | */
21 |
22 | package net.yacy.grid.tools;
23 |
24 | import java.util.Collections;
25 | import java.util.HashMap;
26 | import java.util.LinkedHashMap;
27 | import java.util.Map;
28 | import java.util.Random;
29 |
30 | public final class HashARC extends SimpleARC implements Map, Iterable>, ARC {
31 |
32 | public final static boolean accessOrder = false; // if false, then a insertion-order is used
33 |
34 | public HashARC(final int cacheSize) {
35 | this.cacheSize = cacheSize / 2;
36 | super.levelA = Collections.synchronizedMap(new LinkedHashMap(1, 0.1f, accessOrder) {
37 | private static final long serialVersionUID = 1L;
38 | @Override protected boolean removeEldestEntry(final Map.Entry eldest) {
39 | return size() > HashARC.this.cacheSize;
40 | }
41 | });
42 | this.levelB = Collections.synchronizedMap(new LinkedHashMap(1, 0.1f, accessOrder) {
43 | private static final long serialVersionUID = 1L;
44 | @Override protected boolean removeEldestEntry(final Map.Entry eldest) {
45 | return size() > HashARC.this.cacheSize;
46 | }
47 | });
48 | }
49 |
50 | public static void main(final String[] args) {
51 | final Random r = new Random();
52 | final int testsize = 10000;
53 | final ARC a = new HashARC(testsize * 2);
54 | final Map b = new HashMap();
55 | String key, value;
56 | for (int i = 0; i < testsize; i++) {
57 | key = "k" + r.nextInt();
58 | value = "v" + r.nextInt();
59 | a.insertIfAbsent(key, value);
60 | b.put(key, value);
61 | }
62 |
63 | // now put half of the entries AGAIN into the ARC
64 | int h = testsize / 2;
65 | for (final Map.Entry entry: b.entrySet()) {
66 | a.put(entry.getKey(), entry.getValue());
67 | if (h-- <= 0) break;
68 | }
69 |
70 | // test correctness
71 | for (final Map.Entry entry: b.entrySet()) {
72 | if (!a.containsKey(entry.getKey())) {
73 | System.out.println("missing: " + entry.getKey());
74 | continue;
75 | }
76 | if (!a.get(entry.getKey()).equals(entry.getValue())) {
77 | System.out.println("wrong: a = " + entry.getKey() + "," + a.get(entry.getKey()) + "; v = " + entry.getValue());
78 | }
79 | }
80 | System.out.println("finished test!");
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/net/yacy/grid/json/JsonList.java:
--------------------------------------------------------------------------------
1 | /**
2 | * JSONList
3 | * (C) 3.7.2017 by Michael Peter Christen; mc@yacy.net, @0rb1t3r
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Lesser General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2.1 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program in the file lgpl21.txt
17 | * If not, see .
18 | */
19 |
20 | package net.yacy.grid.json;
21 |
22 | import java.io.BufferedReader;
23 | import java.io.ByteArrayInputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.io.InputStreamReader;
27 | import java.nio.charset.StandardCharsets;
28 | import java.util.Iterator;
29 |
30 | import org.json.JSONArray;
31 | import org.json.JSONException;
32 | import org.json.JSONObject;
33 | import org.json.JSONTokener;
34 |
35 | /**
36 | * A JSONList is an object which represents a list of json objects: that is
37 | * a popular file format which is used as elasticsearch bulk index format.
38 | * A jsonlist file is a text file where every line is a json object.
39 | * To bring a JSONArray into jsonlist format you have to do
40 | * - make sure that every element in the JSONArray is JSONObject
41 | * - print out every json in the list without indentation
42 | */
43 | public class JsonList implements Iterable