aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java')
-rw-r--r--src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java84
1 files changed, 45 insertions, 39 deletions
diff --git a/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java b/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java
index 0651d34..3654c80 100644
--- a/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java
+++ b/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java
@@ -21,27 +21,30 @@ public class GameProfileFetcher {
private static MinecraftSessionService sessionService;
private static GameProfileRepository profileRepo;
// there could be contention if thread pool has more than one thread
- private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 1, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
-
+ private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 1, 1L, TimeUnit.MINUTES,
+ new LinkedBlockingQueue<Runnable>());
+
private static final Map<String, GameProfileFetcher> fetchersByName = Maps.<String, GameProfileFetcher>newHashMap();
private static final Map<UUID, GameProfileFetcher> fetchersById = Maps.<UUID, GameProfileFetcher>newHashMap();
-
+
@Nullable
private GameProfile profile;
-
- public static void init(File dataDir) {
- YggdrasilAuthenticationService auth = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
- sessionService = auth.createMinecraftSessionService();
- profileRepo = auth.createProfileRepository();
- }
-
+
+ public static void init(File dataDir) {
+ YggdrasilAuthenticationService auth = new YggdrasilAuthenticationService(Proxy.NO_PROXY,
+ UUID.randomUUID().toString());
+ sessionService = auth.createMinecraftSessionService();
+ profileRepo = auth.createProfileRepository();
+ }
+
private GameProfileFetcher(GameProfile profileIn) {
dispatchFetchProfile(profileIn);
}
-
+
public static GameProfileFetcher fetchProfile(GameProfile profile) {
if (profile.getId() != null && fetchersById.containsKey(profile.getId())) {
- // if the profile specifies an ID, ensure that the fetcher with the correct ID returns, as it will reject a profile with the wrong ID
+ // if the profile specifies an ID, ensure that the fetcher with the correct ID
+ // returns, as it will reject a profile with the wrong ID
return fetchersById.get(profile.getId());
} else if (fetchersByName.containsKey(profile.getName())) {
return fetchersByName.get(profile.getName());
@@ -54,34 +57,37 @@ public class GameProfileFetcher {
return fetcher;
}
}
-
+
@Nullable
public synchronized GameProfile getGameProfile() {
- return profile;
+ return profile;
+ }
+
+ private void dispatchFetchProfile(GameProfile profileIn) {
+ THREAD_POOL.submit(new Runnable() {
+ public void run() {
+ class LocalCallback implements ProfileLookupCallback {
+ public GameProfile fetched;
+
+ public void onProfileLookupSucceeded(GameProfile success) {
+ fetched = success;
+ }
+
+ public void onProfileLookupFailed(GameProfile failed, Exception exception) {
+ fetched = null;
+ }
+ }
+ ;
+ LocalCallback callback = new LocalCallback();
+ profileRepo.findProfilesByNames(new String[] { profileIn.getName() }, Agent.MINECRAFT, callback);
+
+ GameProfile fetched = sessionService.fillProfileProperties(callback.fetched, false);
+ if (profileIn.getId() == null || fetched.getId().equals(profileIn.getId())) {
+ synchronized (this) {
+ profile = fetched;
+ }
+ }
+ }
+ });
}
-
- private void dispatchFetchProfile(GameProfile profileIn) {
- THREAD_POOL.submit(new Runnable() {
- public void run() {
- class LocalCallback implements ProfileLookupCallback {
- public GameProfile fetched;
- public void onProfileLookupSucceeded(GameProfile success) {
- fetched = success;
- }
- public void onProfileLookupFailed(GameProfile failed, Exception exception) {
- fetched = null;
- }
- };
- LocalCallback callback = new LocalCallback();
- profileRepo.findProfilesByNames(new String[] {profileIn.getName()}, Agent.MINECRAFT, callback);
-
- GameProfile fetched = sessionService.fillProfileProperties(callback.fetched, false);
- if (profileIn.getId() == null || fetched.getId().equals(profileIn.getId())) {
- synchronized (this) {
- profile = fetched;
- }
- }
- }
- });
- }
}