Reformat and clean up "net" package

This commit is contained in:
P0nk
2021-09-09 23:26:02 +02:00
parent 69f4580637
commit 6be6ea9927
235 changed files with 3556 additions and 3398 deletions

View File

@@ -37,7 +37,6 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
*
* @author RonanLana
*/
public class TrackerReadLock extends ReentrantReadWriteLock.ReadLock implements MonitoredReadLock {
@@ -47,17 +46,17 @@ public class TrackerReadLock extends ReentrantReadWriteLock.ReadLock implements
private final int hashcode;
private final Lock state = new ReentrantLock(true);
private final AtomicInteger reentrantCount = new AtomicInteger(0);
public TrackerReadLock(MonitoredReentrantReadWriteLock lock) {
super(lock);
this.id = lock.id;
hashcode = this.hashCode();
}
@Override
public void lock() {
if(YamlConfig.config.server.USE_THREAD_TRACKER) {
if(deadlockedState != null) {
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
if (deadlockedState != null) {
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getDefault());
@@ -68,24 +67,24 @@ public class TrackerReadLock extends ReentrantReadWriteLock.ReadLock implements
registerLocking();
}
super.lock();
}
@Override
public void unlock() {
if(YamlConfig.config.server.USE_THREAD_TRACKER) {
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
unregisterLocking();
}
super.unlock();
}
@Override
public boolean tryLock() {
if(super.tryLock()) {
if(YamlConfig.config.server.USE_THREAD_TRACKER) {
if(deadlockedState != null) {
if (super.tryLock()) {
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
if (deadlockedState != null) {
//FilePrinter.printError(FilePrinter.DEADLOCK_ERROR, "Deadlock occurred when trying to use the '" + id.name() + "' lock resources:\r\n" + printStackTrace(deadlockedState));
ThreadTracker.getInstance().accessThreadTracker(true, true, id, hashcode);
deadlockedState = null;
@@ -98,13 +97,13 @@ public class TrackerReadLock extends ReentrantReadWriteLock.ReadLock implements
return false;
}
}
private void registerLocking() {
state.lock();
try {
ThreadTracker.getInstance().accessThreadTracker(false, true, id, hashcode);
if(reentrantCount.incrementAndGet() == 1) {
if (reentrantCount.incrementAndGet() == 1) {
final Thread t = Thread.currentThread();
timeoutSchedule = TimerManager.getInstance().schedule(() -> issueDeadlock(t), YamlConfig.config.server.LOCK_MONITOR_TIME);
}
@@ -112,51 +111,51 @@ public class TrackerReadLock extends ReentrantReadWriteLock.ReadLock implements
state.unlock();
}
}
private void unregisterLocking() {
state.lock();
try {
if(reentrantCount.decrementAndGet() == 0) {
if(timeoutSchedule != null) {
if (reentrantCount.decrementAndGet() == 0) {
if (timeoutSchedule != null) {
timeoutSchedule.cancel(false);
timeoutSchedule = null;
}
}
ThreadTracker.getInstance().accessThreadTracker(false, false, id, hashcode);
} finally {
state.unlock();
}
}
private void issueDeadlock(Thread t) {
deadlockedState = t.getStackTrace();
//super.unlock();
}
private static String printStackTrace(StackTraceElement[] list) {
String s = "";
for (StackTraceElement stackTraceElement : list) {
s += (" " + stackTraceElement.toString() + "\r\n");
}
return s;
}
@Override
public MonitoredReadLock dispose() {
state.lock();
try {
if(timeoutSchedule != null) {
if (timeoutSchedule != null) {
timeoutSchedule.cancel(false);
timeoutSchedule = null;
}
reentrantCount.set(Integer.MAX_VALUE);
} finally {
state.unlock();
}
//unlock();
return new EmptyReadLock(id);
}