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