mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-05 15:26:28 +00:00
Cleanup
This commit is contained in:
@@ -42,12 +42,12 @@ public class BurstExecutor {
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public Future<?> queue(Runnable r) {
|
||||
if (!multicore) {
|
||||
if(!multicore) {
|
||||
r.run();
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
synchronized(futures) {
|
||||
|
||||
Future<?> c = executor.submit(r);
|
||||
futures.add(c);
|
||||
@@ -56,16 +56,16 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public BurstExecutor queue(List<Runnable> r) {
|
||||
if (!multicore) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
if(!multicore) {
|
||||
for(Runnable i : new KList<>(r)) {
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
synchronized(futures) {
|
||||
for(Runnable i : new KList<>(r)) {
|
||||
queue(i);
|
||||
}
|
||||
}
|
||||
@@ -74,16 +74,16 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public BurstExecutor queue(Runnable[] r) {
|
||||
if (!multicore) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
if(!multicore) {
|
||||
for(Runnable i : new KList<>(r)) {
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
synchronized(futures) {
|
||||
for(Runnable i : r) {
|
||||
queue(i);
|
||||
}
|
||||
}
|
||||
@@ -92,22 +92,22 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public void complete() {
|
||||
if (!multicore) {
|
||||
if(!multicore) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
synchronized(futures) {
|
||||
if(futures.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
for (Future<?> i : futures) {
|
||||
for(Future<?> i : futures) {
|
||||
i.get();
|
||||
}
|
||||
|
||||
futures.clear();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class GridLock {
|
||||
public boolean tryLock(int x, int z, long timeout) {
|
||||
try {
|
||||
return locks.get(x, 0, z).tryLock(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
} catch(InterruptedException e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,15 +45,15 @@ public class HyperLock {
|
||||
public HyperLock(int capacity, boolean fair) {
|
||||
this.fair = fair;
|
||||
locks = new ConcurrentLinkedHashMap.Builder<Long, ReentrantLock>()
|
||||
.initialCapacity(capacity)
|
||||
.maximumWeightedCapacity(capacity)
|
||||
.listener((k, v) -> {
|
||||
if (v.isLocked() || v.isHeldByCurrentThread()) {
|
||||
Iris.warn("InfiniLock Eviction of " + k + " still has locks on it!");
|
||||
}
|
||||
})
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
.initialCapacity(capacity)
|
||||
.maximumWeightedCapacity(capacity)
|
||||
.listener((k, v) -> {
|
||||
if(v.isLocked() || v.isHeldByCurrentThread()) {
|
||||
Iris.warn("InfiniLock Eviction of " + k + " still has locks on it!");
|
||||
}
|
||||
})
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void with(int x, int z, Runnable r) {
|
||||
@@ -73,12 +73,12 @@ public class HyperLock {
|
||||
Throwable ee = null;
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {
|
||||
} catch(Throwable e) {
|
||||
ee = e;
|
||||
} finally {
|
||||
unlock(x, z);
|
||||
|
||||
if (ee != null) {
|
||||
if(ee != null) {
|
||||
throw ee;
|
||||
}
|
||||
}
|
||||
@@ -89,12 +89,12 @@ public class HyperLock {
|
||||
IOException ee = null;
|
||||
try {
|
||||
r.run();
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
ee = e;
|
||||
} finally {
|
||||
unlock(x, z);
|
||||
|
||||
if (ee != null) {
|
||||
if(ee != null) {
|
||||
throw ee;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class HyperLock {
|
||||
public boolean tryLock(int x, int z, long timeout) {
|
||||
try {
|
||||
return getLock(x, z).tryLock(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
} catch(InterruptedException e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
public void lock(int x, int z) {
|
||||
if (!enabled) {
|
||||
if(!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
public void unlock(int x, int z) {
|
||||
if (!enabled) {
|
||||
if(!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,20 +54,20 @@ public class MultiBurst {
|
||||
|
||||
private synchronized ExecutorService getService() {
|
||||
last.set(M.ms());
|
||||
if (service == null || service.isShutdown()) {
|
||||
if(service == null || service.isShutdown()) {
|
||||
service = new ForkJoinPool(IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism()),
|
||||
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
||||
int m = 0;
|
||||
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
||||
int m = 0;
|
||||
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setPriority(priority);
|
||||
worker.setName(name + " " + ++m);
|
||||
return worker;
|
||||
}
|
||||
},
|
||||
(t, e) -> e.printStackTrace(), true);
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setPriority(priority);
|
||||
worker.setName(name + " " + ++m);
|
||||
return worker;
|
||||
}
|
||||
},
|
||||
(t, e) -> e.printStackTrace(), true);
|
||||
}
|
||||
|
||||
return service;
|
||||
@@ -78,7 +78,7 @@ public class MultiBurst {
|
||||
}
|
||||
|
||||
public void burst(boolean multicore, Runnable... r) {
|
||||
if (multicore) {
|
||||
if(multicore) {
|
||||
burst(r);
|
||||
} else {
|
||||
sync(r);
|
||||
@@ -90,7 +90,7 @@ public class MultiBurst {
|
||||
}
|
||||
|
||||
public void burst(boolean multicore, List<Runnable> r) {
|
||||
if (multicore) {
|
||||
if(multicore) {
|
||||
burst(r);
|
||||
} else {
|
||||
sync(r);
|
||||
@@ -98,19 +98,19 @@ public class MultiBurst {
|
||||
}
|
||||
|
||||
private void sync(List<Runnable> r) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
for(Runnable i : new KList<>(r)) {
|
||||
i.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void sync(Runnable... r) {
|
||||
for (Runnable i : r) {
|
||||
for(Runnable i : r) {
|
||||
i.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void sync(KList<Runnable> r) {
|
||||
for (Runnable i : r) {
|
||||
for(Runnable i : r) {
|
||||
i.run();
|
||||
}
|
||||
}
|
||||
@@ -150,25 +150,25 @@ public class MultiBurst {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (service != null) {
|
||||
if(service != null) {
|
||||
service.shutdown();
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
try {
|
||||
while (!service.awaitTermination(1, TimeUnit.SECONDS)) {
|
||||
while(!service.awaitTermination(1, TimeUnit.SECONDS)) {
|
||||
Iris.info("Still waiting to shutdown burster...");
|
||||
if (p.getMilliseconds() > 7000) {
|
||||
if(p.getMilliseconds() > 7000) {
|
||||
Iris.warn("Forcing Shutdown...");
|
||||
|
||||
try {
|
||||
service.shutdownNow();
|
||||
} catch (Throwable e) {
|
||||
} catch(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user