threaded load
This commit is contained in:
parent
d5b06ee3ca
commit
18a584f6d8
@ -4,6 +4,6 @@ public interface Constants {
|
|||||||
|
|
||||||
public static final String APP_VERSION = "v0.8";
|
public static final String APP_VERSION = "v0.8";
|
||||||
public static final String COPYRIGHT = "2021";
|
public static final String COPYRIGHT = "2021";
|
||||||
public static final int DEFAULT_HTTP_TIMEOUT = 2000;
|
public static final int DEFAULT_HTTP_TIMEOUT = 10000;
|
||||||
public static final int RELOAD_TIME = 20000;
|
public static final int RELOAD_TIME = DEFAULT_HTTP_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,17 @@ import cz.kamma.mining.vo.KeyValue;
|
|||||||
|
|
||||||
public class MiningBean {
|
public class MiningBean {
|
||||||
|
|
||||||
public static String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
String curSym = "$";
|
||||||
|
String ltcapikey;
|
||||||
|
String dogapikey;
|
||||||
|
String ltcWallet;
|
||||||
|
String xrpWallet;
|
||||||
|
String ethWallet;
|
||||||
|
String currency;
|
||||||
|
String resultStr;
|
||||||
|
String restRequest;
|
||||||
|
|
||||||
|
public String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||||
java.lang.System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
|
java.lang.System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
|
||||||
List<KeyValue> prices = new ArrayList<>();
|
List<KeyValue> prices = new ArrayList<>();
|
||||||
@ -29,32 +39,22 @@ public class MiningBean {
|
|||||||
String[] cryptoCur = new String[] { "btc", "ltc", "xrp", "eth" };
|
String[] cryptoCur = new String[] { "btc", "ltc", "xrp", "eth" };
|
||||||
double[] lastPrices = new double[] { 0, 0, 0, 0 };
|
double[] lastPrices = new double[] { 0, 0, 0, 0 };
|
||||||
|
|
||||||
String ltcapikey = request.getParameter("ltcapikey");
|
ltcapikey = request.getParameter("ltcapikey");
|
||||||
String dogapikey = request.getParameter("dogapikey");
|
dogapikey = request.getParameter("dogapikey");
|
||||||
String ltcWallet = request.getParameter("ltc");
|
ltcWallet = request.getParameter("ltc");
|
||||||
String xrpWallet = request.getParameter("xrp");
|
xrpWallet = request.getParameter("xrp");
|
||||||
String ethWallet = request.getParameter("eth");
|
ethWallet = request.getParameter("eth");
|
||||||
String currency = request.getParameter("cur");
|
currency = request.getParameter("cur");
|
||||||
|
|
||||||
if (currency == null || currency.equals("null") || currency.length() == 0)
|
if (currency == null || currency.equals("null") || currency.length() == 0)
|
||||||
currency = "usd";
|
currency = "usd";
|
||||||
else
|
else
|
||||||
currency = currency.toLowerCase();
|
currency = currency.toLowerCase();
|
||||||
|
|
||||||
String curSym = "$";
|
|
||||||
|
|
||||||
if (currency.equals("usd"))
|
if (currency.equals("usd"))
|
||||||
curSym = "$";
|
curSym = "$";
|
||||||
else if (currency.equals("eur"))
|
else if (currency.equals("eur"))
|
||||||
curSym = "";
|
curSym = "\u20ac";
|
||||||
|
|
||||||
workers.clear();
|
|
||||||
prices.clear();
|
|
||||||
network.clear();
|
|
||||||
pool.clear();
|
|
||||||
|
|
||||||
String resultStr;
|
|
||||||
String restRequest;
|
|
||||||
|
|
||||||
for (int i = 0; i < cryptoCur.length; i++) {
|
for (int i = 0; i < cryptoCur.length; i++) {
|
||||||
String ccur = cryptoCur[i];
|
String ccur = cryptoCur[i];
|
||||||
@ -75,6 +75,10 @@ public class MiningBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
||||||
restRequest = HttpHelper
|
restRequest = HttpHelper
|
||||||
.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
|
.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
|
||||||
@ -94,10 +98,16 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
|
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
|
||||||
restRequest = HttpHelper
|
restRequest = HttpHelper.getStringResponse(
|
||||||
.getStringResponse("https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
|
"https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject full = new JSONObject(restRequest);
|
JSONObject full = new JSONObject(restRequest);
|
||||||
JSONArray balances = (JSONArray) full.get("balances");
|
JSONArray balances = (JSONArray) full.get("balances");
|
||||||
@ -112,11 +122,17 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
|
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
|
||||||
restRequest = HttpHelper
|
restRequest = HttpHelper
|
||||||
.getStringResponse("https://api.etherscan.io/api?module=account&action=balance&address=" + ethWallet
|
.getStringResponse("https://api.etherscan.io/api?module=account&action=balance&address="
|
||||||
+ "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
|
+ ethWallet + "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject full = new JSONObject(restRequest);
|
JSONObject full = new JSONObject(restRequest);
|
||||||
String confirmedBalance = (String) full.get("result");
|
String confirmedBalance = (String) full.get("result");
|
||||||
@ -133,7 +149,13 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
|
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
|
||||||
String miningJson = HttpHelper
|
String miningJson = HttpHelper
|
||||||
.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
|
.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
|
||||||
@ -262,8 +284,15 @@ public class MiningBean {
|
|||||||
pool.add(wi);
|
pool.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
if (dogapikey != null && !"null".equals(dogapikey) && dogapikey.length() > 0) {
|
if (dogapikey != null && !"null".equals(dogapikey) && dogapikey.length() > 0) {
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
String miningJson = HttpHelper
|
String miningJson = HttpHelper
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key="
|
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key="
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
||||||
@ -273,7 +302,7 @@ public class MiningBean {
|
|||||||
JSONArray data = (JSONArray) user.get("data");
|
JSONArray data = (JSONArray) user.get("data");
|
||||||
KeyValue wi = new KeyValue();
|
KeyValue wi = new KeyValue();
|
||||||
|
|
||||||
for (Iterator it = data.iterator(); it.hasNext();) {
|
for (Iterator<Object> it = data.iterator(); it.hasNext();) {
|
||||||
JSONObject workersJson = (JSONObject) it.next();
|
JSONObject workersJson = (JSONObject) it.next();
|
||||||
wi = new KeyValue();
|
wi = new KeyValue();
|
||||||
wi.setKey("HashRate " + workersJson.getString("username"));
|
wi.setKey("HashRate " + workersJson.getString("username"));
|
||||||
@ -282,8 +311,14 @@ public class MiningBean {
|
|||||||
workers.add(wi);
|
workers.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
miningJson = HttpHelper
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String miningJson = HttpHelper
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
|
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
@ -307,13 +342,24 @@ public class MiningBean {
|
|||||||
workers.add(wi);
|
workers.add(wi);
|
||||||
|
|
||||||
wi = new KeyValue();
|
wi = new KeyValue();
|
||||||
wi.setKey("Last Block");
|
wi.setKey("Last Block Time");
|
||||||
if (blocks != null && blocks.get(0) != null) {
|
if (blocks != null && blocks.get(0) != null) {
|
||||||
JSONObject block = (JSONObject) blocks.get(0);
|
JSONObject block = (JSONObject) blocks.get(0);
|
||||||
long time = block.getLong("time");
|
long time = block.getLong("time");
|
||||||
|
wi.setValue("" + sdf.format(new Date(time * 1000)));
|
||||||
|
} else
|
||||||
|
wi.setValue("Unknown");
|
||||||
|
network.add(wi);
|
||||||
|
|
||||||
|
wi = new KeyValue();
|
||||||
|
wi.setKey("Last Block Finder");
|
||||||
|
if (blocks != null && blocks.get(0) != null) {
|
||||||
|
JSONObject block = (JSONObject) blocks.get(0);
|
||||||
String finder = block.getString("finder");
|
String finder = block.getString("finder");
|
||||||
//double amount = block.getDouble("amount");
|
if (block.isNull("group_name"))
|
||||||
wi.setValue("" + sdf.format(new Date(time*1000)) + " "+finder);
|
wi.setValue(finder);
|
||||||
|
else
|
||||||
|
wi.setValue(finder + " (SOLO)");
|
||||||
} else
|
} else
|
||||||
wi.setValue("Unknown");
|
wi.setValue("Unknown");
|
||||||
network.add(wi);
|
network.add(wi);
|
||||||
@ -350,8 +396,14 @@ public class MiningBean {
|
|||||||
wi.setValue("Unknown");
|
wi.setValue("Unknown");
|
||||||
network.add(wi);
|
network.add(wi);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
miningJson = HttpHelper
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String miningJson = HttpHelper
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
|
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
@ -386,6 +438,10 @@ public class MiningBean {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.sleep(Constants.DEFAULT_HTTP_TIMEOUT);
|
||||||
|
|
||||||
KeyValue wi = new KeyValue();
|
KeyValue wi = new KeyValue();
|
||||||
wi.setKey("Last Update");
|
wi.setKey("Last Update");
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||||
pageEncoding="UTF-8"%>
|
pageEncoding="UTF-8"%>
|
||||||
<%
|
<%
|
||||||
String res = MiningBean.updateAll(request, response);
|
MiningBean mb = new MiningBean();
|
||||||
|
String res = mb.updateAll(request, response);
|
||||||
|
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
response.setHeader("Cache-Control", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user