diff options
author | Sven Gothel <[email protected]> | 2014-07-03 16:06:47 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-07-03 16:06:47 +0200 |
commit | df9ff7f340a5ab4e07efc613f5f264eeae63d4c7 (patch) | |
tree | 239ae276b82024b140428e6c0fe5d739fdd686a4 /src/java/jogamp/common/util/locks | |
parent | eb47aaba63e3b1bf55f274a0f338f1010a017ae4 (diff) |
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
- Change non static accesses to static members using declaring type
- Change indirect accesses to static members to direct accesses (accesses through subtypes)
- Add final modifier to private fields
- Add final modifier to method parameters
- Add final modifier to local variables
- Remove unnecessary casts
- Remove unnecessary '$NON-NLS$' tags
- Remove trailing white spaces on all lines
Diffstat (limited to 'src/java/jogamp/common/util/locks')
7 files changed, 69 insertions, 69 deletions
diff --git a/src/java/jogamp/common/util/locks/LockDebugUtil.java b/src/java/jogamp/common/util/locks/LockDebugUtil.java index ee0a8e8..6f7ee63 100644 --- a/src/java/jogamp/common/util/locks/LockDebugUtil.java +++ b/src/java/jogamp/common/util/locks/LockDebugUtil.java @@ -64,13 +64,13 @@ public class LockDebugUtil { } } - public static void dumpRecursiveLockTrace(PrintStream out) { + public static void dumpRecursiveLockTrace(final PrintStream out) { if(Lock.DEBUG) { - List<Throwable> ls = getRecursiveLockTrace(); + final List<Throwable> ls = getRecursiveLockTrace(); if(null!=ls && ls.size()>0) { int j=0; out.println("TLSLockedStacks: locks "+ls.size()); - for(Iterator<Throwable> i=ls.iterator(); i.hasNext(); j++) { + for(final Iterator<Throwable> i=ls.iterator(); i.hasNext(); j++) { out.print(j+": "); i.next().printStackTrace(out); } diff --git a/src/java/jogamp/common/util/locks/RecursiveLockImpl01CompleteFair.java b/src/java/jogamp/common/util/locks/RecursiveLockImpl01CompleteFair.java index f49e406..c930dff 100644 --- a/src/java/jogamp/common/util/locks/RecursiveLockImpl01CompleteFair.java +++ b/src/java/jogamp/common/util/locks/RecursiveLockImpl01CompleteFair.java @@ -43,7 +43,7 @@ import com.jogamp.common.util.locks.RecursiveLock; public class RecursiveLockImpl01CompleteFair implements RecursiveLock { private static class WaitingThread { - WaitingThread(Thread t) { + WaitingThread(final Thread t) { thread = t; signaledByUnlock = false; } @@ -59,11 +59,11 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { private final Thread getOwner() { return getExclusiveOwnerThread(); } - private final void setOwner(Thread t) { + private final void setOwner(final Thread t) { setExclusiveOwnerThread(t); } - private final void setLockedStack(Throwable s) { - List<Throwable> ls = LockDebugUtil.getRecursiveLockTrace(); + private final void setLockedStack(final Throwable s) { + final List<Throwable> ls = LockDebugUtil.getRecursiveLockTrace(); if(s==null) { ls.remove(lockedStack); } else { @@ -78,7 +78,7 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { /** stack trace of the lock, only used if DEBUG */ private Throwable lockedStack = null; } - private Sync sync = new Sync(); + private final Sync sync = new Sync(); public RecursiveLockImpl01CompleteFair() { } @@ -102,7 +102,7 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { } @Override - public final boolean isOwner(Thread thread) { + public final boolean isOwner(final Thread thread) { synchronized(sync) { return sync.getOwner() == thread ; } @@ -155,7 +155,7 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { } throw new RuntimeException("Waited "+TIMEOUT+"ms for: "+toString()+" - "+threadName(Thread.currentThread())); } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { throw new RuntimeException("Interrupted", e); } } @@ -187,14 +187,14 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { } // enqueue at the start - WaitingThread wCur = new WaitingThread(cur); + final WaitingThread wCur = new WaitingThread(cur); sync.queue.add(0, wCur); do { final long t0 = System.currentTimeMillis(); try { sync.wait(timeout); timeout -= System.currentTimeMillis() - t0; - } catch (InterruptedException e) { + } catch (final InterruptedException e) { if( !wCur.signaledByUnlock ) { sync.queue.remove(wCur); // O(n) throw e; // propagate interruption not send by unlock @@ -255,7 +255,7 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { } @Override - public final void unlock(Runnable taskAfterUnlockBeforeNotify) { + public final void unlock(final Runnable taskAfterUnlockBeforeNotify) { synchronized(sync) { validateLocked(); final Thread cur = Thread.currentThread(); @@ -314,6 +314,6 @@ public class RecursiveLockImpl01CompleteFair implements RecursiveLock { private final String syncName() { return "<"+Integer.toHexString(this.hashCode())+", "+Integer.toHexString(sync.hashCode())+">"; } - private final String threadName(Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } + private final String threadName(final Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } } diff --git a/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java b/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java index 8c9f720..132a9a2 100644 --- a/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java +++ b/src/java/jogamp/common/util/locks/RecursiveLockImpl01Unfairish.java @@ -72,11 +72,11 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { return getExclusiveOwnerThread(); } @Override - public boolean isOwner(Thread t) { + public boolean isOwner(final Thread t) { return getExclusiveOwnerThread()==t; } @Override - public final void setOwner(Thread t) { + public final void setOwner(final Thread t) { setExclusiveOwnerThread(t); } @Override @@ -84,8 +84,8 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { return lockedStack; } @Override - public final void setLockedStack(Throwable s) { - List<Throwable> ls = LockDebugUtil.getRecursiveLockTrace(); + public final void setLockedStack(final Throwable s) { + final List<Throwable> ls = LockDebugUtil.getRecursiveLockTrace(); if(s==null) { ls.remove(lockedStack); } else { @@ -96,9 +96,9 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { @Override public final int getHoldCount() { return holdCount; } @Override - public void incrHoldCount(Thread t) { holdCount++; } + public void incrHoldCount(final Thread t) { holdCount++; } @Override - public void decrHoldCount(Thread t) { holdCount--; } + public void decrHoldCount(final Thread t) { holdCount--; } @Override public final int getQSz() { return qsz; } @@ -117,7 +117,7 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { protected final Sync sync; - public RecursiveLockImpl01Unfairish(Sync sync) { + public RecursiveLockImpl01Unfairish(final Sync sync) { this.sync = sync; } @@ -144,7 +144,7 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { } @Override - public final boolean isOwner(Thread thread) { + public final boolean isOwner(final Thread thread) { synchronized(sync) { return sync.isOwner(thread); } @@ -197,7 +197,7 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { } throw new RuntimeException("Waited "+TIMEOUT+"ms for: "+toString()+" - "+threadName(Thread.currentThread())); } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { throw new RuntimeException("Interrupted", e); } } @@ -270,7 +270,7 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { } @Override - public void unlock(Runnable taskAfterUnlockBeforeNotify) { + public void unlock(final Runnable taskAfterUnlockBeforeNotify) { synchronized(sync) { validateLocked(); final Thread cur = Thread.currentThread(); @@ -315,6 +315,6 @@ public class RecursiveLockImpl01Unfairish implements RecursiveLock { /* package */ final String syncName() { return "<"+Integer.toHexString(this.hashCode())+", "+Integer.toHexString(sync.hashCode())+">"; } - /* package */ final String threadName(Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } + /* package */ final String threadName(final Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } } diff --git a/src/java/jogamp/common/util/locks/RecursiveLockImplJava5.java b/src/java/jogamp/common/util/locks/RecursiveLockImplJava5.java index f3dfa42..badaa72 100644 --- a/src/java/jogamp/common/util/locks/RecursiveLockImplJava5.java +++ b/src/java/jogamp/common/util/locks/RecursiveLockImplJava5.java @@ -10,7 +10,7 @@ public class RecursiveLockImplJava5 implements RecursiveLock { volatile Thread owner = null; ReentrantLock lock; - public RecursiveLockImplJava5(boolean fair) { + public RecursiveLockImplJava5(final boolean fair) { lock = new ReentrantLock(fair); } @@ -20,14 +20,14 @@ public class RecursiveLockImplJava5 implements RecursiveLock { if(!tryLock(TIMEOUT)) { throw new RuntimeException("Waited "+TIMEOUT+"ms for: "+threadName(owner)+" - "+threadName(Thread.currentThread())+", with count "+getHoldCount()+", lock: "+this); } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { throw new RuntimeException("Interrupted", e); } owner = Thread.currentThread(); } @Override - public boolean tryLock(long timeout) throws InterruptedException { + public boolean tryLock(final long timeout) throws InterruptedException { if(lock.tryLock(timeout, TimeUnit.MILLISECONDS)) { owner = Thread.currentThread(); return true; @@ -41,7 +41,7 @@ public class RecursiveLockImplJava5 implements RecursiveLock { } @Override - public void unlock(Runnable taskAfterUnlockBeforeNotify) { + public void unlock(final Runnable taskAfterUnlockBeforeNotify) { validateLocked(); owner = null; if(null!=taskAfterUnlockBeforeNotify) { @@ -66,7 +66,7 @@ public class RecursiveLockImplJava5 implements RecursiveLock { } @Override - public boolean isOwner(Thread thread) { + public boolean isOwner(final Thread thread) { return lock.isLocked() && owner == thread; } @@ -91,5 +91,5 @@ public class RecursiveLockImplJava5 implements RecursiveLock { return lock.getQueueLength(); } - private String threadName(Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } + private String threadName(final Thread t) { return null!=t ? "<"+t.getName()+">" : "<NULL>" ; } } diff --git a/src/java/jogamp/common/util/locks/RecursiveThreadGroupLockImpl01Unfairish.java b/src/java/jogamp/common/util/locks/RecursiveThreadGroupLockImpl01Unfairish.java index 7a386d6..77f73d8 100644 --- a/src/java/jogamp/common/util/locks/RecursiveThreadGroupLockImpl01Unfairish.java +++ b/src/java/jogamp/common/util/locks/RecursiveThreadGroupLockImpl01Unfairish.java @@ -44,14 +44,14 @@ public class RecursiveThreadGroupLockImpl01Unfairish holdCountAdditionOwner = 0; } @Override - public final void incrHoldCount(Thread t) { + public final void incrHoldCount(final Thread t) { super.incrHoldCount(t); if(!isOriginalOwner(t)) { holdCountAdditionOwner++; } } @Override - public final void decrHoldCount(Thread t) { + public final void decrHoldCount(final Thread t) { super.decrHoldCount(t); if(!isOriginalOwner(t)) { holdCountAdditionOwner--; @@ -61,11 +61,11 @@ public class RecursiveThreadGroupLockImpl01Unfairish return holdCountAdditionOwner; } - public final boolean isOriginalOwner(Thread t) { + public final boolean isOriginalOwner(final Thread t) { return super.isOwner(t); } @Override - public final boolean isOwner(Thread t) { + public final boolean isOwner(final Thread t) { if(getExclusiveOwnerThread()==t) { return true; } @@ -80,7 +80,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish public final int getAddOwnerCount() { return threadNum; } - public final void addOwner(Thread t) throws IllegalArgumentException { + public final void addOwner(final Thread t) throws IllegalArgumentException { if(null == threads) { if(threadNum>0) { throw new InternalError("XXX"); @@ -106,7 +106,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish threadNum=0; } - public final void removeOwner(Thread t) throws IllegalArgumentException { + public final void removeOwner(final Thread t) throws IllegalArgumentException { for (int i = 0 ; i < threadNum ; i++) { if (threads[i] == t) { threadNum--; @@ -119,7 +119,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish } String addOwnerToString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for(int i=0; i<threadNum; i++) { if(i>0) { sb.append(", "); @@ -145,14 +145,14 @@ public class RecursiveThreadGroupLockImpl01Unfairish } @Override - public final boolean isOriginalOwner(Thread thread) { + public final boolean isOriginalOwner(final Thread thread) { synchronized(sync) { return ((ThreadGroupSync)sync).isOriginalOwner(thread) ; } } @Override - public final void addOwner(Thread t) throws RuntimeException, IllegalArgumentException { + public final void addOwner(final Thread t) throws RuntimeException, IllegalArgumentException { validateLocked(); final Thread cur = Thread.currentThread(); final ThreadGroupSync tgSync = (ThreadGroupSync)sync; @@ -166,7 +166,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish } @Override - public final void unlock(Runnable taskAfterUnlockBeforeNotify) { + public final void unlock(final Runnable taskAfterUnlockBeforeNotify) { synchronized(sync) { final Thread cur = Thread.currentThread(); final ThreadGroupSync tgSync = (ThreadGroupSync)sync; @@ -182,7 +182,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish while ( tgSync.getAdditionalOwnerHoldCount() > 0 ) { try { sync.wait(); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { // regular wake up! } } @@ -205,7 +205,7 @@ public class RecursiveThreadGroupLockImpl01Unfairish } @Override - public final void removeOwner(Thread t) throws RuntimeException, IllegalArgumentException { + public final void removeOwner(final Thread t) throws RuntimeException, IllegalArgumentException { validateLocked(); ((ThreadGroupSync)sync).removeOwner(t); } diff --git a/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java b/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java index a3d3ac9..44a5d28 100644 --- a/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java +++ b/src/java/jogamp/common/util/locks/SingletonInstanceFileLock.java @@ -41,11 +41,11 @@ public class SingletonInstanceFileLock extends SingletonInstance { static { String s = null; try { - File tmpFile = File.createTempFile("TEST", "tst"); - String absTmpFile = tmpFile.getCanonicalPath(); + final File tmpFile = File.createTempFile("TEST", "tst"); + final String absTmpFile = tmpFile.getCanonicalPath(); tmpFile.delete(); s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator)); - } catch (IOException ex) { + } catch (final IOException ex) { ex.printStackTrace(); } temp_file_path = s; @@ -55,17 +55,17 @@ public class SingletonInstanceFileLock extends SingletonInstance { return temp_file_path; } - public static String getCanonicalTempLockFilePath(String basename) { + public static String getCanonicalTempLockFilePath(final String basename) { return getCanonicalTempPath() + File.separator + basename; } - public SingletonInstanceFileLock(long poll_ms, String lockFileBasename) { + public SingletonInstanceFileLock(final long poll_ms, final String lockFileBasename) { super(poll_ms); file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) ); setupFileCleanup(); } - public SingletonInstanceFileLock(long poll_ms, File lockFile) { + public SingletonInstanceFileLock(final long poll_ms, final File lockFile) { super(poll_ms); file = lockFile ; setupFileCleanup(); @@ -96,7 +96,7 @@ public class SingletonInstanceFileLock extends SingletonInstance { if (fileLock != null) { return true; } - } catch (Exception e) { + } catch (final Exception e) { System.err.println(infoPrefix()+" III "+getName()+" - Unable to create and/or lock file"); e.printStackTrace(); } @@ -118,7 +118,7 @@ public class SingletonInstanceFileLock extends SingletonInstance { file.delete(); } return true; - } catch (Exception e) { + } catch (final Exception e) { System.err.println(infoPrefix()+" EEE "+getName()+" - Unable to remove lock file"); e.printStackTrace(); } finally { diff --git a/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java b/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java index a1ca2ff..b1b42c3 100644 --- a/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java +++ b/src/java/jogamp/common/util/locks/SingletonInstanceServerSocket.java @@ -40,30 +40,30 @@ public class SingletonInstanceServerSocket extends SingletonInstance { private final Server singletonServer; private final String fullName; - public SingletonInstanceServerSocket(long poll_ms, int portNumber) { + public SingletonInstanceServerSocket(final long poll_ms, final int portNumber) { super(poll_ms); // Gather the local InetAddress, loopback is prioritized InetAddress ilh = null; try { ilh = InetAddress.getByName(null); // loopback - } catch (UnknownHostException e1) { } + } catch (final UnknownHostException e1) { } if(null == ilh) { try { ilh = InetAddress.getByName("localhost"); if(null!=ilh && !ilh.isLoopbackAddress()) { ilh = null; } - } catch (UnknownHostException e1) { } + } catch (final UnknownHostException e1) { } } if(null == ilh) { try { ilh = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 } ); if(null!=ilh && !ilh.isLoopbackAddress()) { ilh = null; } - } catch (UnknownHostException e) { } + } catch (final UnknownHostException e) { } } if(null == ilh) { try { ilh = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { } + } catch (final UnknownHostException e) { } } if(null == ilh) { throw new RuntimeException(infoPrefix()+" EEE Could not determine local InetAddress"); @@ -97,11 +97,11 @@ public class SingletonInstanceServerSocket extends SingletonInstance { } // check if other JVM's locked the server socket .. - Socket clientSocket = singletonServer.connect(); + final Socket clientSocket = singletonServer.connect(); if(null != clientSocket) { try { clientSocket.close(); - } catch (IOException e) { } + } catch (final IOException e) { } return false; } @@ -124,11 +124,11 @@ public class SingletonInstanceServerSocket extends SingletonInstance { private volatile boolean shallQuit = false; private volatile boolean alive = false; - private Object syncOnStartStop = new Object(); + private final Object syncOnStartStop = new Object(); private ServerSocket serverSocket = null; private Thread serverThread = null; // allowing kill() to force-stop last server-thread - public Server(InetAddress localInetAddress, int portNumber) { + public Server(final InetAddress localInetAddress, final int portNumber) { this.localInetAddress = localInetAddress; this.portNumber = portNumber; } @@ -145,11 +145,11 @@ public class SingletonInstanceServerSocket extends SingletonInstance { serverThread.start(); try { syncOnStartStop.wait(); - } catch (InterruptedException ie) { + } catch (final InterruptedException ie) { ie.printStackTrace(); } } - boolean ok = isBound(); + final boolean ok = isBound(); if(!ok) { shutdown(); } @@ -164,7 +164,7 @@ public class SingletonInstanceServerSocket extends SingletonInstance { connect(); try { syncOnStartStop.wait(); - } catch (InterruptedException ie) { + } catch (final InterruptedException ie) { ie.printStackTrace(); } } @@ -188,14 +188,14 @@ public class SingletonInstanceServerSocket extends SingletonInstance { if(null != serverThread) { try { serverThread.stop(); - } catch(Throwable t) { } + } catch(final Throwable t) { } } if(null != serverSocket) { try { final ServerSocket ss = serverSocket; serverSocket = null; ss.close(); - } catch (Throwable t) { } + } catch (final Throwable t) { } } } @@ -208,7 +208,7 @@ public class SingletonInstanceServerSocket extends SingletonInstance { public final Socket connect() { try { return new Socket(localInetAddress, portNumber); - } catch (Exception e) { } + } catch (final Exception e) { } return null; } @@ -227,7 +227,7 @@ public class SingletonInstanceServerSocket extends SingletonInstance { serverSocket = new ServerSocket(portNumber, 1, localInetAddress); serverSocket.setReuseAddress(true); // reuse same port w/ subsequent instance, i.e. overcome TO state when JVM crashed alive = true; - } catch (IOException e) { + } catch (final IOException e) { System.err.println(infoPrefix()+" III - Unable to install ServerSocket: "+e.getMessage()); shallQuit = true; } finally { @@ -239,7 +239,7 @@ public class SingletonInstanceServerSocket extends SingletonInstance { try { final Socket clientSocket = serverSocket.accept(); clientSocket.close(); - } catch (IOException ioe) { + } catch (final IOException ioe) { System.err.println(infoPrefix()+" EEE - Exception during accept: " + ioe.getMessage()); } } @@ -249,7 +249,7 @@ public class SingletonInstanceServerSocket extends SingletonInstance { if(null != serverSocket) { serverSocket.close(); } - } catch (IOException e) { + } catch (final IOException e) { System.err.println(infoPrefix()+" EEE - Exception during close: " + e.getMessage()); } finally { serverSocket = null; |