Cleanup for release stage

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2016-12-06 11:35:38 -05:00
parent 17ac47f15e
commit bf8d76750f
4 changed files with 155 additions and 35 deletions

View File

@ -96,8 +96,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
public void run() { public void run() {
try { try {
while (!socket.isClosed()) { while (!socket.isClosed()) {
while (!socket.isClosed() && while (!socket.isClosed() && !consoleManager.available()) {
!consoleManager.available()) {
waitASec(); waitASec();
} }
if (socket.isClosed()) { if (socket.isClosed()) {
@ -192,7 +191,8 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
// Create the streams // Create the streams
runSokectServer(); runSokectServer();
} catch (final IOException e) { } 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$ "Communication error between client and server", e); //$NON-NLS-1$
} }
} }
@ -229,12 +229,20 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
LOGGER.log(Level.FINE, LOGGER.log(Level.FINE,
"Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$ "Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$
e); e);
} catch (IOException e) {
throw e;
} }
LOGGER.info("Closing client"); //$NON-NLS-1$ LOGGER.info("Closing client"); //$NON-NLS-1$
} }
runnable.setRunning(false); runnable.setRunning(false);
consoleManager.type(applicationShutdown); try {
consoleManager.close(); 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$ LOGGER.info("Closing Server"); //$NON-NLS-1$
} }

View File

@ -167,7 +167,8 @@ public abstract class ParametrizedCommand extends Command {
/** @param param the parameter /** @param param the parameter
* @param stringParameter the string parameter type * @param stringParameter the string parameter type
* @param needed if the parameter is needed * @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 @Deprecated
private void checkParam(String param, boolean stringParameter, private void checkParam(String param, boolean stringParameter,
boolean needed) throws InvalidParameterException { boolean needed) throws InvalidParameterException {

View File

@ -53,6 +53,61 @@ import java.util.logging.Logger;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class ReadingRunnable implements Runnable { 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 */ /** The closed pipe message */
private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$ private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$
/** Wait timeout */ /** Wait timeout */
@ -79,6 +134,7 @@ public class ReadingRunnable implements Runnable {
* The lock * The lock
*/ */
private final Object messageBlockerLock = new Object(); private final Object messageBlockerLock = new Object();
/** The message being delivered */
private String delivering; private String delivering;
/** @param reader the input to read from */ /** @param reader the input to read from */
@ -146,7 +202,7 @@ public class ReadingRunnable implements Runnable {
try { try {
lock.wait(TIMEOUT); lock.wait(TIMEOUT);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$ LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
e); e);
} }
if (messages.isEmpty() && !running) { if (messages.isEmpty() && !running) {
@ -218,36 +274,18 @@ public class ReadingRunnable implements Runnable {
} }
final Object obj = messageBlocker.get(message); final Object obj = messageBlocker.get(message);
final Object start = new Object(); 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) { synchronized (start) {
th.start(); th.start();
try { while (!waitRunn.isStarted()) {
start.wait(); try {
} catch (InterruptedException e) { start.wait(TIMEOUT);
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$ } catch (InterruptedException e) {
e); LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
e);
}
} }
} }
return th; return th;

View File

@ -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(){
}
}