diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3aa1131ab8be253dc4542438e7d916856588d2ea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +banking-server/target/ diff --git a/banking/banking.iml b/banking/banking.iml deleted file mode 100644 index c90834f2d607afe55e6104d8aa2cdfffb713f688..0000000000000000000000000000000000000000 --- a/banking/banking.iml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file diff --git a/banking/src/ufrn/imd/BankingServerApp.java b/banking/src/ufrn/imd/BankingServerApp.java deleted file mode 100644 index 4fed7390ea3b7b3ab9901b8f402f99065adf9142..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/BankingServerApp.java +++ /dev/null @@ -1,26 +0,0 @@ -package ufrn.imd; - -import ufrn.imd.controller.Controller; -import ufrn.imd.controller.impl.BalanceControllerImpl; -import ufrn.imd.controller.impl.DepositControllerImpl; -import ufrn.imd.service.BalanceService; -import ufrn.imd.service.DepositService; -import ufrn.imd.service.impl.BalanceServiceImpl; -import ufrn.imd.service.impl.DepositServiceImpl; - -import java.net.MalformedURLException; -import java.rmi.AlreadyBoundException; -import java.rmi.RemoteException; - -public class BankingServerApp { - public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException { - - DepositService depositService = new DepositServiceImpl(); - BalanceService balanceService = new BalanceServiceImpl(); - - Controller depositController = new DepositControllerImpl(depositService); - Controller balanceController = new BalanceControllerImpl(balanceService); - - - } -} diff --git a/banking/src/ufrn/imd/controller/Controller.java b/banking/src/ufrn/imd/controller/Controller.java deleted file mode 100644 index 36dc9b4c23f85da1774874073ce187064e596202..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/controller/Controller.java +++ /dev/null @@ -1,12 +0,0 @@ -package ufrn.imd.controller; - -import ufrn.imd.domain.Client; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.util.List; - -public interface Controller extends Remote { - public void registerClient(Client client) throws RemoteException; - -} diff --git a/banking/src/ufrn/imd/controller/impl/BalanceControllerImpl.java b/banking/src/ufrn/imd/controller/impl/BalanceControllerImpl.java deleted file mode 100644 index 4dd0bb54d3cfc7c01a7e6ee8efcf3b71adb573d8..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/controller/impl/BalanceControllerImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package ufrn.imd.controller.impl; - -import ufrn.imd.controller.Controller; -import ufrn.imd.domain.Client; -import ufrn.imd.service.BalanceService; -import ufrn.imd.service.DepositService; -import ufrn.imd.service.impl.BalanceServiceImpl; -import ufrn.imd.utils.Log; - -import java.net.MalformedURLException; -import java.rmi.AlreadyBoundException; -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.server.UnicastRemoteObject; -import java.util.ArrayList; -import java.util.List; - -import static ufrn.imd.utils.NameSpace.*; - -public class BalanceControllerImpl extends UnicastRemoteObject implements Controller { - - private volatile List<Client> clients = new ArrayList<>(); - - public BalanceControllerImpl(BalanceService service) throws RemoteException, MalformedURLException, AlreadyBoundException { - super(); - Log.info(BalanceServiceImpl.class, "Starting Deposit service!"); - - new Notify(service).start(); - - Log.info(BalanceServiceImpl.class, - String.format("Initializing server in %s", HOST_BALANCE_SERVICE)); - - LocateRegistry.createRegistry(PORT_BALANCE_SERVICE); - - Naming.bind(HOST_BALANCE_SERVICE, this); - } - - @Override - public void registerClient(Client client) throws RemoteException { - clients.add(client); - Log.info(BalanceService.class, "new client registred"); - Log.info(BalanceService.class, String.format("total users: %d", clients.size())); - } - - - - - private class Notify extends Thread{ - - private final BalanceService service; - - public Notify(BalanceService service) { - super(); - this.service = service; - } - public void run() { - - for(;;) { - if(clients.size() > 0) { - - Log.info( - BalanceService.class, - "notyfing the clients!" - ); - int i = 0; - for (Client client : clients) { - - try { - this.service.balance(client.getAccount()); - - } catch (RemoteException e) { - e.printStackTrace(); - } - } - try { - Thread.sleep(15 * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } else { - try { - Thread.sleep(15 * 1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - Log.info(BalanceService.class, "No there's clients!"); - } - - } - - } - } -} diff --git a/banking/src/ufrn/imd/controller/impl/DepositControllerImpl.java b/banking/src/ufrn/imd/controller/impl/DepositControllerImpl.java deleted file mode 100644 index 34cccd467fdc2a911cbb8f231d7651866b6d5c73..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/controller/impl/DepositControllerImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package ufrn.imd.controller.impl; - -import ufrn.imd.controller.Controller; -import ufrn.imd.utils.Log; -import ufrn.imd.domain.Client; -import ufrn.imd.service.DepositService; - -import java.net.MalformedURLException; -import java.rmi.AlreadyBoundException; -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.server.UnicastRemoteObject; -import java.util.ArrayList; -import java.util.List; - -import static ufrn.imd.utils.NameSpace.HOST_DEPOSIT_SERVICE; -import static ufrn.imd.utils.NameSpace.PORT_DEPOSIT_SERVICE; - -public class DepositControllerImpl extends UnicastRemoteObject implements Controller { - - private volatile List<Client> clients = new ArrayList<>(); - public DepositControllerImpl(DepositService service) throws RemoteException, MalformedURLException, AlreadyBoundException { - super(); - Log.info(DepositControllerImpl.class, "Starting Deposit service!"); - - new Notify(service).start(); - Log.info(DepositControllerImpl.class, - String.format("Initializing server in %s", HOST_DEPOSIT_SERVICE)); - - LocateRegistry.createRegistry(PORT_DEPOSIT_SERVICE); - - Naming.bind(HOST_DEPOSIT_SERVICE, this); - } - - @Override - public void registerClient(Client client) throws RemoteException { - clients.add(client); - Log.info(DepositControllerImpl.class, "new client registred"); - Log.info(DepositControllerImpl.class, String.format("total users: %d", clients.size())); - } - - - - - private class Notify extends Thread{ - - private final DepositService service; - - public Notify(DepositService service) { - super(); - this.service = service; - } - public void run() { - - for(;;) { - - if(clients.size() > 0) { - - Log.info( - DepositControllerImpl.class, - "notyfing the clients!" - ); - int i = 0; - for (Client client : clients) { - - try { - this.service.deposit(client.getBalance(), client.getAccount()); - - } catch (RemoteException e) { - e.printStackTrace(); - } - } - try { - Thread.sleep(15 * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } else { - try { - Thread.sleep(15 * 1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - Log.info(DepositControllerImpl.class, "No there's clients!"); - - - } - - } - - } - } -} diff --git a/banking/src/ufrn/imd/domain/Account.java b/banking/src/ufrn/imd/domain/Account.java deleted file mode 100644 index dc11776a78721abf973ee3fb0ce09a5e82803a73..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/domain/Account.java +++ /dev/null @@ -1,41 +0,0 @@ -package ufrn.imd.domain; - -import java.io.Serializable; - -public class Account implements Serializable { - private static final long serialVersionUID = 2L; - private Integer id; - private String number; - private Double balance; - - public Account() {} - public Account(Integer id, String number, Double balance) { - this.id = id; - this.number = number; - this.balance = balance; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getNumber() { - return number; - } - - public void setNumber(String number) { - this.number = number; - } - - public Double getBalance() { - return balance; - } - - public void setBalance(Double balance) { - this.balance = balance; - } -} diff --git a/banking/src/ufrn/imd/domain/Client.java b/banking/src/ufrn/imd/domain/Client.java deleted file mode 100644 index 7419ef5f21d81687463caca4520964d3f862bb66..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/domain/Client.java +++ /dev/null @@ -1,17 +0,0 @@ -package ufrn.imd.domain; - -import ufrn.imd.domain.Account; - -import java.io.Serializable; -import java.util.Optional; - -public class Client implements Serializable { - private static final long serialVersionUID = 1L; - private Account account; - public Double getBalance() { - return account.getBalance(); - } - public Optional<Account> getAccount() { - return Optional.of(account); - } -} diff --git a/banking/src/ufrn/imd/repository/Repository.java b/banking/src/ufrn/imd/repository/Repository.java deleted file mode 100644 index a7b91a12159bbe271354734417cea2e75cf9e69e..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/repository/Repository.java +++ /dev/null @@ -1,2 +0,0 @@ -package ufrn.imd.repository;public interface Repository { -} diff --git a/banking/src/ufrn/imd/repository/impl/ClientRepository.java b/banking/src/ufrn/imd/repository/impl/ClientRepository.java deleted file mode 100644 index 271350123a335b0e483b47667d4d6b446e0e29c8..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/repository/impl/ClientRepository.java +++ /dev/null @@ -1,2 +0,0 @@ -package ufrn.imd.repository.impl;public class ClientRepository { -} diff --git a/banking/src/ufrn/imd/service/BalanceService.java b/banking/src/ufrn/imd/service/BalanceService.java deleted file mode 100644 index b82470c15060014b18ce9c6323ca2a37a5268fee..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/service/BalanceService.java +++ /dev/null @@ -1,12 +0,0 @@ -package ufrn.imd.service; - -import ufrn.imd.domain.Account; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.util.Optional; - -public interface BalanceService extends Remote { - - public void balance(Optional<Account> account) throws RemoteException; -} diff --git a/banking/src/ufrn/imd/service/DepositService.java b/banking/src/ufrn/imd/service/DepositService.java deleted file mode 100644 index aab39ac63fd5da6827a9ee113ba692da9902459e..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/service/DepositService.java +++ /dev/null @@ -1,13 +0,0 @@ -package ufrn.imd.service; - -import ufrn.imd.domain.Account; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.util.Optional; - -public interface DepositService extends Remote { - - public void deposit(Double value, Optional<Account> account) throws RemoteException, RuntimeException; - -} diff --git a/banking/src/ufrn/imd/service/WidthawService.java b/banking/src/ufrn/imd/service/WidthawService.java deleted file mode 100644 index 8a5ed3baa7ecd8367276729a144c1ff882a35bed..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/service/WidthawService.java +++ /dev/null @@ -1,12 +0,0 @@ -package ufrn.imd.service; - -import ufrn.imd.domain.Account; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface WidthawService extends Remote { - - public void widthaw(Double value, Account account) throws RemoteException; - -} diff --git a/banking/src/ufrn/imd/service/impl/BalanceServiceImpl.java b/banking/src/ufrn/imd/service/impl/BalanceServiceImpl.java deleted file mode 100644 index f550c9d9e0f97f3439028a8ba6b8137c91537600..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/service/impl/BalanceServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package ufrn.imd.service.impl; - -import ufrn.imd.domain.Account; - -import java.rmi.RemoteException; -import java.util.Optional; - -import ufrn.imd.service.*; -import ufrn.imd.utils.Log; - -public class BalanceServiceImpl implements BalanceService { - - - @Override - public void balance(Optional<Account> accOP) throws RemoteException { - Account account = accOP.orElseThrow(() -> new RuntimeException("Invalid account")); - Log.info( - BalanceServiceImpl.class, - String.format("Account Balance: R$ %f", account.getBalance()) - ); - - } -} diff --git a/banking/src/ufrn/imd/service/impl/DepositServiceImpl.java b/banking/src/ufrn/imd/service/impl/DepositServiceImpl.java deleted file mode 100644 index f7a1cb7d53f7d257d652df80008f3a8ddb9b5323..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/service/impl/DepositServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package ufrn.imd.service.impl; - -import ufrn.imd.domain.Account; -import ufrn.imd.utils.Log; -import ufrn.imd.service.DepositService; - -import java.rmi.RemoteException; -import java.util.Optional; - -public class DepositServiceImpl implements DepositService { - - public DepositServiceImpl() { - super(); - } - - public void deposit(Double value, Optional<Account> acOp) throws RemoteException, RuntimeException { - Account account = acOp.orElseThrow(() -> new RuntimeException("Null User!")); - if(account.getBalance() < value) throw new RuntimeException("There's no money!"); - account.setBalance(account.getBalance() - value); - Log.info(DepositServiceImpl.class, "deposit"); - } - -} diff --git a/banking/src/ufrn/imd/utils/Log.java b/banking/src/ufrn/imd/utils/Log.java deleted file mode 100644 index 38d3f87c29c5bba875697400c9d9fecad5cbe99a..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/utils/Log.java +++ /dev/null @@ -1,10 +0,0 @@ -package ufrn.imd.utils; - -public class Log { - - public static void info(Class path, String text) { - System.out.println( - String.format("[LOG] %s - %s", path , text) - ); - } -} diff --git a/banking/src/ufrn/imd/utils/NameSpace.java b/banking/src/ufrn/imd/utils/NameSpace.java deleted file mode 100644 index bb5d5251a3090f100905b78e8f8fe9d47f290cb1..0000000000000000000000000000000000000000 --- a/banking/src/ufrn/imd/utils/NameSpace.java +++ /dev/null @@ -1,11 +0,0 @@ -package ufrn.imd.utils; - -public class NameSpace { - - public final static Integer PORT_BALANCE_SERVICE = 1908; - public final static Integer PORT_DEPOSIT_SERVICE = 1907; - public final static String HOST_DEPOSIT_SERVICE = - String.format("rmi://127.0.0.1:%d/%s", PORT_DEPOSIT_SERVICE, "deposit"); - public final static String HOST_BALANCE_SERVICE = - String.format("rmi://127.0.0.1:%d/%s", PORT_BALANCE_SERVICE, "balance"); -}