Skip to content

Commit cc65fc4

Browse files
Various fixes
- Common/R66: improve multithreading usage - Compression: make Zlib codec usable for FTP (mode Z) (only using compatible clients, such as WaarpFtp4J based o FTP4J) - Packaging: following issue #2 from fb clone on packaging using release profile - Update dependencies (including issue #1 from fb clone) - Try to fix and improve FTP concurrency (including issue #99) - Fix documentation
1 parent 1e32557 commit cc65fc4

File tree

93 files changed

+2294
-836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2294
-836
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ cd Waarp-All
6262
mvn -P jre11 package
6363
```
6464

65+
If you want to build unofficial RPM/DEV/TGZ/ZIP and documentation, you can do as the following,
66+
ensuring you have already cloned and install using `pip` the repo for Sphinx template for Waarp
67+
`code.waarp.fr:2222/waarp/sphinx-template.git` with the following packages for Sphinx:
68+
69+
- sphinx
70+
- sphinx-autobuild
71+
- sphinxcontrib-httpdomain
72+
- Possibly fix the current version 1.6 to 1.7
73+
- `sphinxcontrib/httpdomain.py`
74+
- line 766
75+
- `+ app.add_domain(HTTPDomain)`
76+
- sphinxcontrib-openapi
77+
- sphinx.ext.todo
78+
79+
```sh
80+
mvn -P jre11,release package
81+
```
82+
6583
You can use a JDK 11 (or higher) with `jre11` profile, and a JDK 8 with `jre8` or `jre6` profiles.
6684

6785
`mvn -P jre11 package` also runs the full test suite, which takes quite some time (for more

WaarpCommon/src/main/java/org/waarp/common/database/DbSession.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ private void initialize(final DbModel dbModel, final String server,
122122
} catch (final SQLException ex) {
123123
setDisActive(true);
124124
// handle any errors
125-
logger.error(CANNOT_CREATE_CONNECTION);
125+
logger.error(CANNOT_CREATE_CONNECTION + " while already having {}",
126+
DbAdmin.getNbConnection());
126127
error(ex);
127128
if (getConn() != null) {
128129
try {
@@ -223,7 +224,8 @@ public final void setAutoCommit(final boolean autoCommit)
223224
getConn().setAutoCommit(autoCommit);
224225
} catch (final SQLException e) {
225226
// handle any errors
226-
logger.error(CANNOT_CREATE_CONNECTION);
227+
logger.error(CANNOT_CREATE_CONNECTION + " while already having {}",
228+
DbAdmin.getNbConnection());
227229
error(e);
228230
if (getConn() != null) {
229231
try {

WaarpCommon/src/main/java/org/waarp/common/file/DataBlock.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.netty.buffer.ByteBuf;
2323
import io.netty.buffer.Unpooled;
24+
import org.waarp.common.utility.WaarpNettyUtil;
2425

2526
/**
2627
* Main object implementing Data Block whaveter the mode, type, structure used.
@@ -139,11 +140,11 @@ public final void setBlock(final ByteBuf block) {
139140
this.block = new byte[byteCount];
140141
offsetBuf = 0;
141142
if (blockBuf != null) {
142-
blockBuf.release();
143+
WaarpNettyUtil.release(blockBuf);
143144
blockBuf = null;
144145
}
145146
block.readBytes(this.block);
146-
block.release();
147+
WaarpNettyUtil.release(block);
147148
}
148149

149150
/**
@@ -165,8 +166,14 @@ public final void setBlock(final byte[] block, final int size) {
165166
if (isRESTART) {
166167
this.block = null;
167168
markers = new int[6];
168-
for (int i = 0; i < 6; i++) {
169-
markers[i] = block[i];
169+
if (block == null) {
170+
for (int i = 0; i < 6; i++) {
171+
markers[i] = 0;
172+
}
173+
} else {
174+
for (int i = 0; i < 6; i++) {
175+
markers[i] = block[i];
176+
}
170177
}
171178
byteCount = 6;
172179
return;
@@ -178,7 +185,7 @@ public final void setBlock(final byte[] block, final int size) {
178185
byteCount = size;
179186
}
180187
if (blockBuf != null) {
181-
blockBuf.release();
188+
WaarpNettyUtil.release(blockBuf);
182189
blockBuf = null;
183190
}
184191
offsetBuf = 0;
@@ -337,7 +344,7 @@ public final void setMarkers(final int[] markers) {
337344
*/
338345
public final void clear() {
339346
if (blockBuf != null) {
340-
blockBuf.release();
347+
WaarpNettyUtil.release(blockBuf);
341348
blockBuf = null;
342349
}
343350
block = null;

WaarpCommon/src/main/java/org/waarp/common/file/filesystembased/FilesystemBasedFileImpl.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public final String getFile() throws CommandAbstractException {
276276
}
277277

278278
@Override
279-
public boolean closeFile() throws CommandAbstractException {
279+
public synchronized boolean closeFile() throws CommandAbstractException {
280280
if (fileInputStream != null) {
281281
FileUtils.close(fileInputStream);
282282
fileInputStream = null;
@@ -295,7 +295,8 @@ public boolean closeFile() throws CommandAbstractException {
295295
}
296296

297297
@Override
298-
public final boolean abortFile() throws CommandAbstractException {
298+
public final synchronized boolean abortFile()
299+
throws CommandAbstractException {
299300
if (isInWriting() &&
300301
((FilesystemBasedFileParameterImpl) getSession().getFileParameter()).deleteOnAbort) {
301302
delete();
@@ -320,15 +321,15 @@ public long length() throws CommandAbstractException {
320321
}
321322

322323
@Override
323-
public final boolean isInReading() {
324+
public final synchronized boolean isInReading() {
324325
if (!isReady) {
325326
return false;
326327
}
327328
return fileInputStream != null;
328329
}
329330

330331
@Override
331-
public final boolean isInWriting() {
332+
public final synchronized boolean isInWriting() {
332333
if (!isReady) {
333334
return false;
334335
}
@@ -473,7 +474,7 @@ public boolean renameTo(final String path) throws CommandAbstractException {
473474
}
474475

475476
@Override
476-
public final DataBlock readDataBlock()
477+
public final synchronized DataBlock readDataBlock()
477478
throws FileTransferException, FileEndOfTransferException {
478479
if (isReady) {
479480
return getByteBlock(getSession().getBlockSize());
@@ -482,7 +483,7 @@ public final DataBlock readDataBlock()
482483
}
483484

484485
@Override
485-
public final DataBlock readDataBlock(final byte[] bufferGiven)
486+
public final synchronized DataBlock readDataBlock(final byte[] bufferGiven)
486487
throws FileTransferException, FileEndOfTransferException {
487488
if (isReady) {
488489
return getByteBlock(bufferGiven);
@@ -491,7 +492,7 @@ public final DataBlock readDataBlock(final byte[] bufferGiven)
491492
}
492493

493494
@Override
494-
public final void writeDataBlock(final DataBlock dataBlock)
495+
public final synchronized void writeDataBlock(final DataBlock dataBlock)
495496
throws FileTransferException {
496497
if (isReady) {
497498
if (dataBlock.isEOF()) {
@@ -514,7 +515,7 @@ public final void writeDataBlock(final DataBlock dataBlock)
514515
*
515516
* @return the position
516517
*/
517-
public final long getPosition() {
518+
public final synchronized long getPosition() {
518519
return position;
519520
}
520521

@@ -526,7 +527,8 @@ public final long getPosition() {
526527
* @throws IOException
527528
*/
528529
@Override
529-
public final void setPosition(final long position) throws IOException {
530+
public final synchronized void setPosition(final long position)
531+
throws IOException {
530532
if (this.position != position) {
531533
this.position = position;
532534
if (fileInputStream != null) {
@@ -556,8 +558,9 @@ public final void setPosition(final long position) throws IOException {
556558
*
557559
* @throws FileTransferException
558560
*/
559-
private void writeBlock(final byte[] buffer, final int offset,
560-
final int length) throws FileTransferException {
561+
private synchronized void writeBlock(final byte[] buffer, final int offset,
562+
final int length)
563+
throws FileTransferException {
561564
if (length > 0 && !isReady) {
562565
throw new FileTransferException(NO_FILE_IS_READY);
563566
}
@@ -597,8 +600,9 @@ private void writeBlock(final byte[] buffer, final int offset,
597600
*
598601
* @throws FileTransferException
599602
*/
600-
private void writeBlockEnd(final byte[] buffer, final int offset,
601-
final int length) throws FileTransferException {
603+
private synchronized void writeBlockEnd(final byte[] buffer, final int offset,
604+
final int length)
605+
throws FileTransferException {
602606
writeBlock(buffer, offset, length);
603607
try {
604608
closeFile();
@@ -629,7 +633,7 @@ private void checkByteBufSize(final int size) {
629633
* @throws FileTransferException
630634
* @throws FileEndOfTransferException
631635
*/
632-
private DataBlock getByteBlock(final int sizeblock)
636+
private synchronized DataBlock getByteBlock(final int sizeblock)
633637
throws FileTransferException, FileEndOfTransferException {
634638
if (!isReady) {
635639
throw new FileTransferException(NO_FILE_IS_READY);
@@ -656,7 +660,7 @@ private DataBlock getByteBlock(final int sizeblock)
656660
* @throws FileTransferException
657661
* @throws FileEndOfTransferException
658662
*/
659-
private DataBlock getByteBlock(final byte[] bufferGiven)
663+
private synchronized DataBlock getByteBlock(final byte[] bufferGiven)
660664
throws FileTransferException, FileEndOfTransferException {
661665
if (!isReady) {
662666
throw new FileTransferException(NO_FILE_IS_READY);

WaarpCommon/src/main/java/org/waarp/common/guid/GUID.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public GUID(final int tenantId, final int platformId) {
196196
count = ++counter;
197197
if (count > 0xFFFFFF) {
198198
try {
199-
FORSYNC.wait(1);//NOSONAR
199+
Thread.sleep(1);//NOSONAR
200200
} catch (final InterruptedException e) {//NOSONAR
201201
// ignore
202202
SysErrLogger.FAKE_LOGGER.ignoreLog(e);

WaarpCommon/src/main/java/org/waarp/common/utility/WaarpNettyUtil.java

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
2929
import io.netty.channel.WriteBufferWaterMark;
3030
import io.netty.channel.socket.nio.NioServerSocketChannel;
3131
import io.netty.channel.socket.nio.NioSocketChannel;
32+
import io.netty.util.IllegalReferenceCountException;
3233
import io.netty.util.concurrent.Future;
3334
import org.waarp.common.logging.SysErrLogger;
3435

36+
import java.io.IOException;
37+
import java.net.InetAddress;
38+
import java.net.ServerSocket;
39+
3540
/**
3641
* Utility class for Netty usage
3742
*/
@@ -159,6 +164,58 @@ public static void setServerBootstrap(final ServerBootstrap bootstrap,
159164
}
160165
}
161166

167+
/**
168+
* Checks to see if a specific port is available.
169+
*
170+
* @param port the port to check for availability
171+
*/
172+
public static boolean availablePort(final int port) {
173+
ServerSocket ss = null;
174+
try {
175+
ss = new ServerSocket(port); // NOSONAR
176+
ss.setReuseAddress(true);
177+
return true;
178+
} catch (final IOException e) {
179+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
180+
} finally {
181+
if (ss != null) {
182+
try {
183+
ss.close();
184+
} catch (final Exception e) {
185+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
186+
}
187+
}
188+
}
189+
return false;
190+
}
191+
192+
/**
193+
* Checks to see if a specific port is available.
194+
*
195+
* @param port the port to check for availability
196+
* @param localAddress the associated localAddress to use
197+
*/
198+
public static boolean availablePort(final int port,
199+
final InetAddress localAddress) {
200+
ServerSocket ss = null;
201+
try {
202+
ss = new ServerSocket(port, 0, localAddress); // NOSONAR
203+
ss.setReuseAddress(true);
204+
return true;
205+
} catch (final IOException e) {
206+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
207+
} finally {
208+
if (ss != null) {
209+
try {
210+
ss.close();
211+
} catch (final Exception e) {
212+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
213+
}
214+
}
215+
}
216+
return false;
217+
}
218+
162219
/**
163220
* @param future
164221
*
@@ -225,7 +282,12 @@ public static boolean release(final ByteBuf byteBuf) {
225282
if (byteBuf == null || byteBuf.refCnt() <= 0) {
226283
return true;
227284
}
228-
return byteBuf.release();
285+
try {
286+
return byteBuf.release();
287+
} catch (final IllegalReferenceCountException e) {
288+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
289+
return true;
290+
}
229291
}
230292

231293
/**
@@ -236,7 +298,26 @@ public static boolean release(final ByteBuf byteBuf) {
236298
public static void releaseCompletely(final ByteBuf byteBuf) {
237299
if (byteBuf != null && byteBuf.refCnt() != 0) {
238300
final int refCnt = byteBuf.refCnt();
239-
byteBuf.release(refCnt);
301+
try {
302+
byteBuf.release(refCnt);
303+
} catch (final IllegalReferenceCountException e) {
304+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
305+
}
306+
}
307+
}
308+
309+
/**
310+
* Retain this ByteBuf
311+
*
312+
* @param byteBuf
313+
*/
314+
public static void retain(final ByteBuf byteBuf) {
315+
if (byteBuf != null) {
316+
try {
317+
byteBuf.retain();
318+
} catch (final IllegalReferenceCountException e) {
319+
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
320+
}
240321
}
241322
}
242323

0 commit comments

Comments
 (0)