-
Notifications
You must be signed in to change notification settings - Fork 53
Add synchronously entries from resource collections that do no support concurrent access #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,7 +333,7 @@ private void writeManifest( ConcurrentJarCreator zOut, Manifest manifest ) | |
|
|
||
| ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() ); | ||
| super.zipFile( createInputStreamSupplier( bais ), zOut, MANIFEST_NAME, System.currentTimeMillis(), null, | ||
| DEFAULT_FILE_MODE, null ); | ||
| DEFAULT_FILE_MODE, null, false ); | ||
| super.initZipOutputStream( zOut ); | ||
| } | ||
|
|
||
|
|
@@ -435,15 +435,15 @@ private void createIndexList( ConcurrentJarCreator zOut ) | |
| ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() ); | ||
|
|
||
| super.zipFile( createInputStreamSupplier( bais ), zOut, INDEX_NAME, System.currentTimeMillis(), null, | ||
| DEFAULT_FILE_MODE, null ); | ||
| DEFAULT_FILE_MODE, null, true ); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the index is ok to be added in parallel. But it's seems this is the current behavior so I just kept it this way.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There does not appear to be any ordering constraints for the index file, like there is for the manifest |
||
| } | ||
|
|
||
| /** | ||
| * Overridden from Zip class to deal with manifests and index lists. | ||
| */ | ||
| protected void zipFile( InputStreamSupplier is, ConcurrentJarCreator zOut, String vPath, | ||
| long lastModified, File fromArchive, | ||
| int mode, String symlinkDestination ) | ||
| int mode, String symlinkDestination, boolean addInParallel ) | ||
| throws IOException, ArchiverException | ||
| { | ||
| if ( MANIFEST_NAME.equalsIgnoreCase( vPath ) ) | ||
|
|
@@ -464,7 +464,7 @@ else if ( INDEX_NAME.equalsIgnoreCase( vPath ) && index ) | |
| { | ||
| rootEntries.addElement( vPath ); | ||
| } | ||
| super.zipFile( is, zOut, vPath, lastModified, fromArchive, mode, symlinkDestination ); | ||
| super.zipFile( is, zOut, vPath, lastModified, fromArchive, mode, symlinkDestination, addInParallel ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ public class ConcurrentJarCreator { | |
| private final ScatterZipOutputStream directories; | ||
| private final ScatterZipOutputStream metaInfDir; | ||
| private final ScatterZipOutputStream manifest; | ||
| private final ScatterZipOutputStream synchronousEntries; | ||
|
|
||
| private final ParallelScatterZipCreator parallelScatterZipCreator; | ||
| private long zipCloseElapsed; | ||
|
|
@@ -61,6 +62,7 @@ public ConcurrentJarCreator(int nThreads) throws IOException { | |
| directories = createDeferred(defaultSupplier); | ||
| manifest = createDeferred(defaultSupplier); | ||
| metaInfDir = createDeferred( defaultSupplier ); | ||
| synchronousEntries = createDeferred( defaultSupplier ); | ||
|
|
||
| parallelScatterZipCreator = new ParallelScatterZipCreator(Executors.newFixedThreadPool(nThreads), defaultSupplier); | ||
| } | ||
|
|
@@ -72,10 +74,12 @@ public ConcurrentJarCreator(int nThreads) throws IOException { | |
| * | ||
| * @param zipArchiveEntry The entry to add. Compression method | ||
| * @param source The source input stream supplier | ||
| * @param addInParallel Indicates if the entry should be add in parallel. | ||
| * If set to {@code false} the entry is added synchronously. | ||
| * @throws java.io.IOException | ||
| */ | ||
|
|
||
| public void addArchiveEntry(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier source) throws IOException { | ||
| public void addArchiveEntry(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier source, | ||
| final boolean addInParallel) throws IOException { | ||
| final int method = zipArchiveEntry.getMethod(); | ||
| if (method == -1) throw new IllegalArgumentException("Method must be set on the supplied zipArchiveEntry"); | ||
| if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) { | ||
|
|
@@ -93,8 +97,10 @@ public void addArchiveEntry(final ZipArchiveEntry zipArchiveEntry, final InputSt | |
| if (zipArchiveEntry.isDirectory()) zipArchiveEntry.setMethod(ZipEntry.STORED); | ||
| manifest.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, createInputStreamSupplier(payload))); | ||
| payload.close(); | ||
| } else { | ||
| } else if (addInParallel) { | ||
| parallelScatterZipCreator.addArchiveEntry(zipArchiveEntry, source); | ||
| } else { | ||
| synchronousEntries.addArchiveEntry( createZipArchiveEntryRequest( zipArchiveEntry, source ) ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -110,12 +116,14 @@ public void writeTo(ZipArchiveOutputStream targetStream) throws IOException, Exe | |
| metaInfDir.writeTo( targetStream ); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug ! |
||
| manifest.writeTo(targetStream); | ||
| directories.writeTo(targetStream); | ||
| synchronousEntries.writeTo( targetStream ); | ||
| parallelScatterZipCreator.writeTo( targetStream); | ||
| long startAt = System.currentTimeMillis(); | ||
| targetStream.close(); | ||
| zipCloseElapsed = System.currentTimeMillis() - startAt; | ||
| manifest.close(); | ||
| directories.close(); | ||
| synchronousEntries.close(); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ public InputStream get() { | |
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| }); | ||
| }, true); | ||
| } | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manifests are not added in parallel anyway but just in case.