Skip to content

Commit f519901

Browse files
Simplify cleaning
1 parent 0ab14df commit f519901

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

api/src/org/labkey/api/data/TempTableTracker.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class TempTableTracker
4747
private final String schemaName;
4848
private final String tableName;
4949
private final String qualifiedName;
50+
private final Cleaner.Cleanable cleanable;
51+
private final CleanupState state;
5052

5153
private static class CleanupState implements Runnable
5254
{
@@ -78,15 +80,13 @@ public void run()
7880
}
7981
}
8082

81-
private final CleanupState state;
82-
8383
private TempTableTracker(DbSchema schema, String tableName, Object ref)
8484
{
8585
this.schemaName = schema.getName();
8686
this.tableName = tableName;
8787
this.qualifiedName = this.schemaName + "." + this.tableName;
8888
this.state = new CleanupState(schema, tableName, qualifiedName, schemaName);
89-
cleaner.register(ref, state);
89+
cleanable = cleaner.register(ref, state);
9090
}
9191

9292

@@ -144,10 +144,9 @@ private static TempTableTracker track(TempTableTracker ttt)
144144

145145
public synchronized void delete()
146146
{
147-
state.run();
147+
cleanable.clean();
148148
}
149149

150-
151150
private static void untrack(String qualifiedName, String schemaName, String tableName)
152151
{
153152
_log.debug("untrack(" + qualifiedName + ")");

api/src/org/labkey/api/util/CheckedInputStream.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
package org.labkey.api.util;
1717

18-
import org.apache.logging.log4j.LogManager;
18+
import org.apache.logging.log4j.Logger;
1919
import org.labkey.api.miniprofiler.MiniProfiler;
20+
import org.labkey.api.util.logging.LogHelper;
2021

2122
import java.io.IOException;
2223
import java.io.InputStream;
@@ -27,10 +28,11 @@
2728
* User: adam
2829
* Date: 7/2/12
2930
*/
30-
3131
public class CheckedInputStream extends InputStreamWrapper
3232
{
3333
private static final Cleaner CLEANER = Cleaner.create();
34+
public static final Logger LOG = LogHelper.getLogger(CheckedInputStream.class, "Utility to ensure InputStreams are closed");
35+
private final State _state;
3436

3537
private static class State implements Runnable
3638
{
@@ -49,36 +51,39 @@ public void run()
4951
{
5052
if (!_closed)
5153
{
52-
LogManager.getLogger(CheckedInputStream.class).error("InputStream was not closed. Creation stacktrace:" + ExceptionUtil.renderStackTrace(_creationStackTrace));
53-
try
54-
{
55-
_is.close();
56-
}
57-
catch (IOException e)
58-
{
59-
LogManager.getLogger(CheckedInputStream.class).error("Failed to close InputStream", e);
60-
}
61-
finally
62-
{
63-
_closed = true;
64-
}
54+
LOG.error("InputStream was not closed. Creation stacktrace:" + ExceptionUtil.renderStackTrace(_creationStackTrace));
55+
close();
6556
}
6657
}
67-
}
6858

69-
private final Cleaner.Cleanable _cleanable;
59+
private void close()
60+
{
61+
try
62+
{
63+
_is.close();
64+
}
65+
catch (IOException e)
66+
{
67+
LOG.error("Failed to close InputStream", e);
68+
}
69+
finally
70+
{
71+
_closed = true;
72+
}
73+
}
74+
}
7075

7176
public CheckedInputStream(InputStream is)
7277
{
7378
super(is);
7479
StackTraceElement[] creationStackTrace = MiniProfiler.getTroubleshootingStackTrace();
75-
State state = new State(is, creationStackTrace);
76-
_cleanable = CLEANER.register(this, state);
80+
_state = new State(is, creationStackTrace);
81+
CLEANER.register(this, _state);
7782
}
7883

7984
@Override
8085
public void close() throws IOException
8186
{
82-
_cleanable.clean();
87+
_state.close();
8388
}
8489
}

0 commit comments

Comments
 (0)