Remove single thread executor

This commit is contained in:
0xboobface 2018-12-05 12:10:21 +01:00
parent d4dadf9fea
commit 8abb3db8a5
2 changed files with 12 additions and 26 deletions

View File

@ -13,8 +13,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -53,7 +51,6 @@ public class MyFreeCamsClient {
private Cache<Integer, SessionState> sessionStates = CacheBuilder.newBuilder().maximumSize(4000).build();
private Cache<Integer, MyFreeCamsModel> models = CacheBuilder.newBuilder().maximumSize(4000).build();
private Lock lock = new ReentrantLock();
private ExecutorService executor = Executors.newSingleThreadExecutor();
private ServerConfig serverConfig;
@SuppressWarnings("unused")
private String tkx;
@ -574,10 +571,6 @@ public class MyFreeCamsClient {
return models.getIfPresent(uid);
}
public void execute(Runnable r) {
executor.execute(r);
}
public void getSessionState(ctbrec.Model model) {
for (SessionState state : sessionStates.asMap().values()) {
if(Objects.equals(state.getNm(), model.getName())) {

View File

@ -45,7 +45,7 @@ public class MyFreeCamsModel extends AbstractModel {
private double camScore;
private int viewerCount;
private State state;
private int resolution[];
private int resolution[] = new int[2];
/**
* This constructor exists only for deserialization. Please don't call it directly
@ -174,26 +174,19 @@ public class MyFreeCamsModel extends AbstractModel {
@Override
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
if(resolution == null) {
if(failFast || hlsUrl == null) {
return new int[2];
if (!failFast && hlsUrl != null) {
try {
List<StreamSource> streamSources = getStreamSources();
Collections.sort(streamSources);
StreamSource best = streamSources.get(streamSources.size() - 1);
resolution = new int[] { best.width, best.height };
} catch (ParseException | PlaylistException e) {
LOG.warn("Couldn't determine stream resolution - {}", e.getMessage());
} catch (ExecutionException | IOException e) {
LOG.error("Couldn't determine stream resolution", e);
}
MyFreeCamsClient.getInstance().execute(()->{
try {
List<StreamSource> streamSources = getStreamSources();
Collections.sort(streamSources);
StreamSource best = streamSources.get(streamSources.size()-1);
resolution = new int[] {best.width, best.height};
} catch (ParseException | PlaylistException e) {
LOG.warn("Couldn't determine stream resolution - {}", e.getMessage());
} catch (ExecutionException | IOException e) {
LOG.error("Couldn't determine stream resolution", e);
}
});
return new int[2];
} else {
return resolution;
}
return resolution;
}
public void setStreamUrl(String hlsUrl) {