now i just need the new machine to install everything for deloyment
This commit is contained in:
@@ -24,7 +24,7 @@ public class DBCPDataSource {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl("jdbc:mysql://151.80.230.149:3306/unloze_racetimer_css?useLegacyDatetimeCode=false&serverTimezone=UTC");
|
||||
ds.setUsername("unloze_racetimer_css");
|
||||
ds.setPassword("ahsdbahb/#¤FHdasd");
|
||||
ds.setPassword("dfhasFEb234dfsnFEEJSfFEJdfap");
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package facade;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class CallableJsonObject implements Callable<Map.Entry<String, String>> {
|
||||
|
||||
private JSONObject jsonObject;
|
||||
private String avatar;
|
||||
private String steamID;
|
||||
|
||||
public CallableJsonObject(JSONObject jsonObject) {
|
||||
String steamID64 = jsonObject.getString("steamid");
|
||||
this.avatar = jsonObject.getString("avatarfull");
|
||||
this.steamID = convertCommunityIdToSteamId(Long.valueOf(steamID64));
|
||||
}
|
||||
|
||||
public CallableJsonObject() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map.Entry<String, String> call() throws Exception {
|
||||
Map.Entry<String, String> entry = new AbstractMap.SimpleEntry<String, String>(steamID, avatar);
|
||||
return entry;
|
||||
}
|
||||
|
||||
private String convertCommunityIdToSteamId(long communityId) {
|
||||
long steamId1 = communityId % 2;
|
||||
long steamId2 = communityId - 76561197960265728L;
|
||||
steamId2 = (steamId2 - steamId1) / 2;
|
||||
return "STEAM_0:" + steamId1 + ":" + steamId2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,14 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -47,6 +52,13 @@ public class Facade {
|
||||
private final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(30, TimeUnit.MINUTES);
|
||||
private Instant elapsedTime;
|
||||
private int initSetup = 0;
|
||||
private static final ForkJoinPool executor = instantiateExecutor();
|
||||
|
||||
private static ForkJoinPool instantiateExecutor() {
|
||||
return new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
||||
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
||||
null, false);
|
||||
}
|
||||
|
||||
public Facade() {
|
||||
elapsedTime = Instant.now();
|
||||
@@ -311,31 +323,27 @@ public class Facade {
|
||||
}
|
||||
}
|
||||
|
||||
private String convertCommunityIdToSteamId(long communityId) {
|
||||
long steamId1 = communityId % 2;
|
||||
long steamId2 = communityId - 76561197960265728L;
|
||||
steamId2 = (steamId2 - steamId1) / 2;
|
||||
return "STEAM_0:" + steamId1 + ":" + steamId2;
|
||||
}
|
||||
|
||||
private void retrieveAvatarFull(String avatarurl) {
|
||||
try {
|
||||
Callable<Entry<String, String>> worker;
|
||||
final ConcurrentMap<Integer, Future<Entry<String, String>>> futures = new MapMaker().concurrencyLevel(6).makeMap();
|
||||
URL url = new URL(avatarurl);
|
||||
JSONTokener tokener = new JSONTokener(url.openStream());
|
||||
JSONObject root = new JSONObject(tokener);
|
||||
JSONObject jsonObject = root.getJSONObject("response");
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("players");
|
||||
for (int incrementer = 0; incrementer < jsonArray.length(); incrementer++) {
|
||||
try {
|
||||
String steamID64 = jsonArray.getJSONObject(incrementer).getString("steamid");
|
||||
String avatar = jsonArray.getJSONObject(incrementer).getString("avatarfull");
|
||||
String steamID = convertCommunityIdToSteamId(Long.valueOf(steamID64));
|
||||
playerCache.get(steamID).setAvatar(avatar);
|
||||
//System.out.println("avatar: " + avatar + "\nname: " + playerCache.get(steamID).getName() + "\n");
|
||||
} catch (NumberFormatException | JSONException ex) {
|
||||
System.out.println("ex: " + ex.getLocalizedMessage() + "\n Nosteamer");
|
||||
}
|
||||
worker = new CallableJsonObject(jsonArray.getJSONObject(incrementer));
|
||||
futures.put(incrementer, executor.submit(worker));
|
||||
}
|
||||
futures.values().parallelStream().forEach(future -> {
|
||||
try {
|
||||
Entry<String, String> getEntry = future.get(3, TimeUnit.SECONDS);
|
||||
playerCache.get(getEntry.getKey()).setAvatar(getEntry.getValue());
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
||||
Logger.getLogger(Facade.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
});
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(Facade.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
@@ -349,7 +357,8 @@ public class Facade {
|
||||
avatarURL.append("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=262F3F0C6B83E0F263C272C3762002F1&steamids=");
|
||||
int incrementer = 0;
|
||||
int overallCounter = 0;
|
||||
int fetchCapacity = 450;
|
||||
int fetchCapacity = players.size() > 5 ? players.size() / 5 : 6;
|
||||
CountDownLatch cdl = new CountDownLatch(1);
|
||||
for (Player player : players) {
|
||||
if (incrementer > 0) {
|
||||
avatarURL.append(",");
|
||||
@@ -358,13 +367,25 @@ public class Facade {
|
||||
avatarURL.append(Long.toString(convertSteamIdToCommunityId(player.getSteamID())));
|
||||
if (incrementer >= fetchCapacity || incrementer + overallCounter >= players.size()) {
|
||||
final String fullUrl = avatarURL.toString();
|
||||
retrieveAvatarFull(fullUrl);
|
||||
final int overall = incrementer + overallCounter;
|
||||
new Thread(() -> {
|
||||
retrieveAvatarFull(fullUrl);
|
||||
if (overall >= players.size()) {
|
||||
cdl.countDown();
|
||||
}
|
||||
}).start();
|
||||
overallCounter += incrementer;
|
||||
incrementer = 0;
|
||||
avatarURL = new StringBuilder();
|
||||
avatarURL.append("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=262F3F0C6B83E0F263C272C3762002F1&steamids=");
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
cdl.await();
|
||||
} catch (InterruptedException ex) {
|
||||
System.out.println("cdl await interrupted: " + ex.getLocalizedMessage() + "\n");
|
||||
}
|
||||
setNonExistingAvatarOnPlayers(players);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user