mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-25 18:44:16 +00:00
Module Client : ajout de méthds shutdown() à tous les services; appel des méthds shutdown() lors d'un event de fermeture de la fenêtre
This commit is contained in:
parent
c57d910d7c
commit
b9de88a43f
@ -12,6 +12,10 @@ public class Main extends Application{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
new FrameManager(primaryStage).show();
|
FrameManager fm = new FrameManager(primaryStage);
|
||||||
|
|
||||||
|
primaryStage.setOnCloseRequest(event->fm.onCloseEvent());
|
||||||
|
|
||||||
|
fm.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,12 @@ public class FrameManager {
|
|||||||
private FrameScene mainFrameScene;
|
private FrameScene mainFrameScene;
|
||||||
private FrameScene startupFrameScene;
|
private FrameScene startupFrameScene;
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
|
private ClientBackEndModuleManager moduleManager;
|
||||||
|
|
||||||
public FrameManager(Stage stage) {
|
public FrameManager(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
|
|
||||||
ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null);
|
moduleManager = new ClientBackEndModuleManager(null);
|
||||||
|
|
||||||
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
||||||
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
||||||
@ -68,4 +69,8 @@ public class FrameManager {
|
|||||||
Platform.exit();
|
Platform.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onCloseEvent() {
|
||||||
|
moduleManager.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import com.pqt.client.module.stock.StockService;
|
|||||||
|
|
||||||
public class ClientBackEndModuleManager {
|
public class ClientBackEndModuleManager {
|
||||||
|
|
||||||
|
private final ConnectionService connectionService;
|
||||||
|
private final QueryExecutor queryExecutor;
|
||||||
private final SaleService saleService;
|
private final SaleService saleService;
|
||||||
private final StockService stockService;
|
private final StockService stockService;
|
||||||
private final AccountService accountService;
|
private final AccountService accountService;
|
||||||
@ -19,8 +21,8 @@ public class ClientBackEndModuleManager {
|
|||||||
private final NetworkService networkService;
|
private final NetworkService networkService;
|
||||||
|
|
||||||
public ClientBackEndModuleManager(String serverUrl) {
|
public ClientBackEndModuleManager(String serverUrl) {
|
||||||
ConnectionService connectionService = new ConnectionService(serverUrl);
|
connectionService = new ConnectionService(serverUrl);
|
||||||
QueryExecutor queryExecutor = new QueryExecutor(connectionService);
|
queryExecutor = new QueryExecutor(connectionService);
|
||||||
saleService = new SaleService(queryExecutor);
|
saleService = new SaleService(queryExecutor);
|
||||||
stockService = new StockService(queryExecutor);
|
stockService = new StockService(queryExecutor);
|
||||||
accountService = new AccountService(queryExecutor);
|
accountService = new AccountService(queryExecutor);
|
||||||
@ -88,4 +90,22 @@ public class ClientBackEndModuleManager {
|
|||||||
public NetworkService getNetworkService() {
|
public NetworkService getNetworkService() {
|
||||||
return networkService;
|
return networkService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
shutHighLevelServices();
|
||||||
|
shutLowLevelServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shutHighLevelServices(){
|
||||||
|
saleService.shutdown();
|
||||||
|
stockService.shutdown();
|
||||||
|
statService.shutdown();
|
||||||
|
networkService.shutdown();
|
||||||
|
accountService.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shutLowLevelServices(){
|
||||||
|
queryExecutor.shutdown();
|
||||||
|
connectionService.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.pqt.client.module.account;
|
package com.pqt.client.module.account;
|
||||||
|
|
||||||
|
import com.pqt.client.module.account.listeners.AccountListenerAdapter;
|
||||||
import com.pqt.client.module.query.QueryExecutor;
|
import com.pqt.client.module.query.QueryExecutor;
|
||||||
import com.pqt.client.module.query.query_callback.ICollectionItemMessageCallback;
|
import com.pqt.client.module.query.query_callback.ICollectionItemMessageCallback;
|
||||||
import com.pqt.client.module.query.query_callback.INoItemMessageCallback;
|
import com.pqt.client.module.query.query_callback.INoItemMessageCallback;
|
||||||
@ -12,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
//TODO écrire javadoc
|
//TODO écrire javadoc
|
||||||
//TODO add log lines
|
//TODO add log lines
|
||||||
@ -120,4 +122,37 @@ public class AccountService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
if(connected) {
|
||||||
|
try {
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
new Thread(() ->{
|
||||||
|
this.addListener(new AccountListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAccountStatusChangedEvent(boolean status) {
|
||||||
|
//TODO ajouter des logs
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccountStatusNotChangedEvent(Throwable cause) {
|
||||||
|
//TODO ajouter des logs
|
||||||
|
cause.printStackTrace();
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logOutCurrentAccount();
|
||||||
|
}).start();
|
||||||
|
latch.await(); // Wait for thread to call latch.countDown()
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
//TODO ajouter des logs
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
listenerList = null;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,8 @@ public class ConnectionService {
|
|||||||
throw new IllegalStateException("Service was shut down : unable to send text");
|
throw new IllegalStateException("Service was shut down : unable to send text");
|
||||||
executor.submit(()->textSender.send(serverUrl, "message="+text, listener));
|
executor.submit(()->textSender.send(serverUrl, "message="+text, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
stop(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,4 +139,8 @@ public class NetworkService {
|
|||||||
if(port<1 || port>65535)
|
if(port<1 || port>65535)
|
||||||
throw new IllegalArgumentException("port number must be an unsigned 16-bit integer (0<n<65536)");
|
throw new IllegalArgumentException("port number must be an unsigned 16-bit integer (0<n<65536)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,4 +173,8 @@ public class QueryExecutor {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import com.pqt.client.module.sale.listeners.ISaleListener;
|
|||||||
import com.pqt.client.module.sale.listeners.SimpleSaleFirerer;
|
import com.pqt.client.module.sale.listeners.SimpleSaleFirerer;
|
||||||
import com.pqt.core.entities.sale.SaleType;
|
import com.pqt.core.entities.sale.SaleType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
//TODO écrire javadoc
|
//TODO écrire javadoc
|
||||||
//TODO add log lines
|
//TODO add log lines
|
||||||
@ -69,8 +69,17 @@ public class SaleService {
|
|||||||
eventFirerer.removeListener(listener);
|
eventFirerer.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SaleType> getSaleTypes() {
|
public Collection<SaleType> getSaleTypes() {
|
||||||
//TODO
|
//TODO faire en sorte que cette liste soit donnée par le serveur
|
||||||
return null;
|
|
||||||
|
Set<SaleType> types = new HashSet<>();
|
||||||
|
types.add(SaleType.CASH);
|
||||||
|
types.add(SaleType.OFFERED_GUEST);
|
||||||
|
types.add(SaleType.OFFERED_STAFF_MEMBER);
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
//Nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,4 +31,7 @@ public class StatService {
|
|||||||
dao.removeListener(listener);
|
dao.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,4 +129,8 @@ public class StockService {
|
|||||||
public void removeListener(IStockListener listener) {
|
public void removeListener(IStockListener listener) {
|
||||||
dao.removeListener(listener);
|
dao.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user