Cleanup for release stage
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
17ac47f15e
commit
bf8d76750f
@ -96,8 +96,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
||||
public void run() {
|
||||
try {
|
||||
while (!socket.isClosed()) {
|
||||
while (!socket.isClosed() &&
|
||||
!consoleManager.available()) {
|
||||
while (!socket.isClosed() && !consoleManager.available()) {
|
||||
waitASec();
|
||||
}
|
||||
if (socket.isClosed()) {
|
||||
@ -192,7 +191,8 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
||||
// Create the streams
|
||||
runSokectServer();
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.SEVERE,
|
||||
LOGGER.severe("Communication error between client and server"); //$NON-NLS-1$
|
||||
LOGGER.log(Level.FINE,
|
||||
"Communication error between client and server", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
@ -229,12 +229,20 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
||||
LOGGER.log(Level.FINE,
|
||||
"Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$
|
||||
e);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
LOGGER.info("Closing client"); //$NON-NLS-1$
|
||||
}
|
||||
runnable.setRunning(false);
|
||||
try {
|
||||
consoleManager.type(applicationShutdown);
|
||||
consoleManager.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warning("Unable to close application correctly"); //$NON-NLS-1$
|
||||
LOGGER.log(Level.FINE, "Application closing caused an exception",
|
||||
e);
|
||||
}
|
||||
LOGGER.info("Closing Server"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,8 @@ public abstract class ParametrizedCommand extends Command {
|
||||
/** @param param the parameter
|
||||
* @param stringParameter the string parameter type
|
||||
* @param needed if the parameter is needed
|
||||
* @throws InvalidParameterException if the new definition is invalid */
|
||||
* @throws InvalidParameterException if the new definition is invalid
|
||||
* @deprecated since 1.3.3 */
|
||||
@Deprecated
|
||||
private void checkParam(String param, boolean stringParameter,
|
||||
boolean needed) throws InvalidParameterException {
|
||||
|
@ -53,6 +53,61 @@ import java.util.logging.Logger;
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ReadingRunnable implements Runnable {
|
||||
|
||||
/** The runnable to wait for notification on an object
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
private final class ToWaitRunnable implements Runnable {
|
||||
/** The Object */
|
||||
private final Object obj;
|
||||
/** The locking object */
|
||||
private final Object start;
|
||||
/** The message */
|
||||
private final String message;
|
||||
/** The started status */
|
||||
private boolean started = false;
|
||||
|
||||
/** @param obj the object to lock on
|
||||
* @param start the object to notify when ready to wait
|
||||
* @param message the message to wait for */
|
||||
public ToWaitRunnable(Object obj, Object start,
|
||||
String message) {
|
||||
this.obj = obj;
|
||||
this.start = start;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (obj) {
|
||||
synchronized (start) {
|
||||
started = true;
|
||||
start.notify();
|
||||
}
|
||||
while (isRunning()) {
|
||||
try {
|
||||
obj.wait();
|
||||
if (delivering.equals(message)) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE,
|
||||
THREAD_INTERRUPTION_EXCEPTION, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the started */
|
||||
public boolean isStarted() {
|
||||
synchronized (start) {
|
||||
return started;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The thread intteruption logging message */
|
||||
private static final String THREAD_INTERRUPTION_EXCEPTION = "Thread interruption exception."; //$NON-NLS-1$
|
||||
/** The closed pipe message */
|
||||
private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$
|
||||
/** Wait timeout */
|
||||
@ -79,6 +134,7 @@ public class ReadingRunnable implements Runnable {
|
||||
* The lock
|
||||
*/
|
||||
private final Object messageBlockerLock = new Object();
|
||||
/** The message being delivered */
|
||||
private String delivering;
|
||||
|
||||
/** @param reader the input to read from */
|
||||
@ -146,7 +202,7 @@ public class ReadingRunnable implements Runnable {
|
||||
try {
|
||||
lock.wait(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$
|
||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
|
||||
e);
|
||||
}
|
||||
if (messages.isEmpty() && !running) {
|
||||
@ -218,38 +274,20 @@ public class ReadingRunnable implements Runnable {
|
||||
}
|
||||
final Object obj = messageBlocker.get(message);
|
||||
final Object start = new Object();
|
||||
Thread th = new Thread(new Runnable() {
|
||||
ToWaitRunnable waitRunn = new ToWaitRunnable(obj, start, message);
|
||||
Thread th = new Thread(waitRunn);
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (obj) {
|
||||
synchronized (start) {
|
||||
start.notify();
|
||||
}
|
||||
while (isRunning()) {
|
||||
try {
|
||||
obj.wait();
|
||||
if (delivering.equals(message)) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE,
|
||||
"Thread interruption exception.", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
synchronized (start) {
|
||||
th.start();
|
||||
while (!waitRunn.isStarted()) {
|
||||
try {
|
||||
start.wait();
|
||||
start.wait(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$
|
||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return th;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.manager.ReadingRunnableTest.java
|
||||
* Created on: Dec 6, 2016
|
||||
*/
|
||||
package fr.bigeon.gclc.manager;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
public class ReadingRunnableTest {
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetMessage(){
|
||||
BufferedReader reader = null;
|
||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
runnable.setRunning(false);
|
||||
|
||||
try {
|
||||
runnable.getMessage();
|
||||
fail("reading from closed runnable");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}.
|
||||
*/
|
||||
@Test
|
||||
public final void testHasMessage(){
|
||||
|
||||
BufferedReader reader = null;
|
||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
runnable.setRunning(false);
|
||||
|
||||
try {
|
||||
runnable.getMessage();
|
||||
fail("reading from closed runnable");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetWaitForDelivery(){
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user