Skip to content

Commit 1c04d8d

Browse files
committed
Merge branch 'master' into enh-ngconfig
2 parents d7bfb60 + 682081e commit 1c04d8d

File tree

5 files changed

+235
-80
lines changed

5 files changed

+235
-80
lines changed

server/src/main/java/password/pwm/http/servlet/configmanager/DebugItemGenerator.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import password.pwm.svc.stats.Statistic;
5151
import password.pwm.svc.stats.StatisticsManager;
5252
import password.pwm.util.LDAPPermissionCalculator;
53+
import password.pwm.util.java.ClosableIterator;
5354
import password.pwm.util.java.DebugOutputBuilder;
5455
import password.pwm.util.java.FileSystemUtility;
5556
import password.pwm.util.java.JavaHelper;
@@ -468,9 +469,9 @@ public String getFilename( )
468469
@Override
469470
public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
470471
{
471-
final List<FileSystemUtility.FileSummaryInformation> fileSummaryInformations = new ArrayList<>();
472472
final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
473473
final File applicationPath = pwmApplication.getPwmEnvironment().getApplicationPath();
474+
final List<File> interestedFiles = new ArrayList<>( );
474475

475476
if ( pwmApplication.getPwmEnvironment().getContextManager() != null )
476477
{
@@ -483,7 +484,7 @@ public void outputItem( final DebugItemInput debugItemInput, final OutputStream
483484

484485
if ( servletRootPath != null )
485486
{
486-
fileSummaryInformations.addAll( FileSystemUtility.readFileInformation( webInfPath ) );
487+
interestedFiles.add( webInfPath );
487488
}
488489
}
489490
}
@@ -497,14 +498,16 @@ public void outputItem( final DebugItemInput debugItemInput, final OutputStream
497498
{
498499
try
499500
{
500-
fileSummaryInformations.addAll( FileSystemUtility.readFileInformation( applicationPath ) );
501+
interestedFiles.add( applicationPath );
501502
}
502503
catch ( Exception e )
503504
{
504505
LOGGER.error( debugItemInput.getSessionLabel(), "unable to generate appPath fileMd5sums during zip debug building: " + e.getMessage() );
505506
}
506507
}
507508

509+
510+
try ( ClosableIterator<FileSystemUtility.FileSummaryInformation> iter = FileSystemUtility.readFileInformation( interestedFiles ); )
508511
{
509512
final CSVPrinter csvPrinter = JavaHelper.makeCsvPrinter( outputStream );
510513
{
@@ -516,8 +519,10 @@ public void outputItem( final DebugItemInput debugItemInput, final OutputStream
516519
headerRow.add( "Checksum" );
517520
csvPrinter.printComment( StringUtil.join( headerRow, "," ) );
518521
}
519-
for ( final FileSystemUtility.FileSummaryInformation fileSummaryInformation : fileSummaryInformations )
522+
523+
while ( iter.hasNext() )
520524
{
525+
final FileSystemUtility.FileSummaryInformation fileSummaryInformation = iter.next();
521526
try
522527
{
523528
final List<String> dataRow = new ArrayList<>();

server/src/main/java/password/pwm/http/servlet/resource/ResourceServletService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import password.pwm.health.HealthRecord;
3232
import password.pwm.http.PwmRequest;
3333
import password.pwm.svc.PwmService;
34+
import password.pwm.util.java.ClosableIterator;
3435
import password.pwm.util.java.FileSystemUtility;
3536
import password.pwm.util.java.JavaHelper;
3637
import password.pwm.util.java.MovingAverage;
@@ -277,9 +278,15 @@ private static void checksumResourceFilePath( final PwmApplication pwmApplicatio
277278
final File resourcePath = new File( basePath.getAbsolutePath() + File.separator + "public" + File.separator + "resources" );
278279
if ( resourcePath.exists() )
279280
{
280-
for ( final FileSystemUtility.FileSummaryInformation fileSummaryInformation : FileSystemUtility.readFileInformation( resourcePath ) )
281+
try ( ClosableIterator<FileSystemUtility.FileSummaryInformation> iter =
282+
FileSystemUtility.readFileInformation( Collections.singletonList( resourcePath ) ) )
281283
{
282-
checksumStream.write( JavaHelper.longToBytes( fileSummaryInformation.getChecksum() ) );
284+
while ( iter.hasNext() )
285+
{
286+
final FileSystemUtility.FileSummaryInformation fileSummaryInformation = iter.next();
287+
checksumStream.write( JavaHelper.longToBytes( fileSummaryInformation.getChecksum() ) );
288+
}
289+
283290
}
284291
}
285292
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Password Management Servlets (PWM)
3+
* http://www.pwm-project.org
4+
*
5+
* Copyright (c) 2006-2009 Novell, Inc.
6+
* Copyright (c) 2009-2019 The PWM Project
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package password.pwm.util.java;
22+
23+
import java.util.Iterator;
24+
import java.util.NoSuchElementException;
25+
import java.util.Optional;
26+
import java.util.concurrent.atomic.AtomicBoolean;
27+
import java.util.concurrent.atomic.AtomicReference;
28+
import java.util.function.Supplier;
29+
30+
public class ConcurrentClosableIteratorWrapper<T> implements Iterator<T>, ClosableIterator<T>
31+
{
32+
private final AtomicReference<T> nextReference = new AtomicReference<>();
33+
private final AtomicBoolean completed = new AtomicBoolean( false );
34+
35+
private final Supplier<Optional<T>> nextSupplier;
36+
private final Runnable closeFunction;
37+
38+
public ConcurrentClosableIteratorWrapper( final Supplier<Optional<T>> nextFunction, final Runnable closeFunction )
39+
{
40+
this.nextSupplier = nextFunction;
41+
this.closeFunction = closeFunction;
42+
}
43+
44+
@Override
45+
public synchronized boolean hasNext()
46+
{
47+
if ( completed.get() )
48+
{
49+
return false;
50+
}
51+
work();
52+
return nextReference.get() != null;
53+
}
54+
55+
@Override
56+
public synchronized T next()
57+
{
58+
if ( completed.get() )
59+
{
60+
throw new NoSuchElementException( );
61+
}
62+
work();
63+
final T fileSummaryInformation = nextReference.get();
64+
if ( fileSummaryInformation == null )
65+
{
66+
throw new NoSuchElementException( );
67+
}
68+
nextReference.set( null );
69+
return fileSummaryInformation;
70+
}
71+
72+
@Override
73+
public synchronized void close()
74+
{
75+
closeImpl();
76+
}
77+
78+
private void closeImpl()
79+
{
80+
if ( !completed.get() )
81+
{
82+
completed.set( true );
83+
nextReference.set( null );
84+
closeFunction.run();
85+
}
86+
}
87+
88+
private void work()
89+
{
90+
if ( nextReference.get() == null && !completed.get() )
91+
{
92+
final Optional<T> next = nextSupplier.get();
93+
if ( next.isPresent() )
94+
{
95+
nextReference.set( next.get() );
96+
}
97+
else
98+
{
99+
closeImpl();
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)