1

I'm developing a Banking Client-Server architecture.

I want to know what is the most convenient way to organize the Server side. Does the Bank need to be the Server and the GUI in the same file ?

Because currently I have the server GUI which instantiates a Bank. This Bank has a list of Customer and each Customer has several Account.

  1. My first problem concerns a JTable in the server GUI. In fact a Bank store an ArrayList of every operations previously done by the clients. I wrote an implementation of AbstractTableModel which also store an ArrayList. The problem is that the Server instantiate a Bank and a TableModel for the JTable. So, when the Bank adds an Operation in its ArrayList, the TableModel is not aware of that. How can I link these two without giving the TableModel to the Bank ?

  2. The second problem concerns the connection with the Client. The Server pass a Session interface to the Client when login/password are correct. Session contains Banking operations that a Client can do. Is it a security problem if the SessionImpl encapsulate the Bank instance ? Because in reality Session methods call the Bank ones. Session is the only remote Object between the Client and the Server but encapsulating the Bank gives me the impression that the Client can access to the Bank directly.

xenom
  • 377
  • 1
  • 5
  • 15
  • What kind of technology are you using on your server (EJBs, Servlets, something else)? Why did you choose to put some objects on a separate tier? – rancidfishbreath Dec 03 '12 at 16:00
  • I am using RMI. What do you mean by separate tier ? – xenom Dec 03 '12 at 16:02
  • RMI is a very low level API and one of the more complicated ways to do client server applications. I am trying to figure out why you chose the technology and what you hope to gain from using it. Maybe you want to learn RMI which is a valid motivation. If you can help us understand why you went down this route or really what you are trying to accomplish then you are going to get better answers. – rancidfishbreath Dec 03 '12 at 16:11
  • Well it's an academic project actually. I must implement a Banking Client-Server architecture using absolutely RMI. I wanted to respect OOP principles by writing Server/Bank/Customer/Account but it seems I'd rather merge Server and Bank. Can the server GUI be in the same file than the Server itself ? Or it's preferable to split Server GUI and Server in two classes ? My two questions are also still valid. – xenom Dec 03 '12 at 16:24
  • Please cite your porevious [question](http://stackoverflow.com/q/13683306/230513) on the same topic. – trashgod Dec 03 '12 at 17:27

1 Answers1

1

1) You want your AbstractTableModel to take a Bank object in the constructor. The AbstractTableModel methods then delegates to the underlying list of operations on the Bank object.

There are two ways to solve the what happens if the bank object changes problem.

a) Assuming a Bank object with a method:

public List<Operation> getOperations();

You can just call getOperations() each time a request is made to the table model. For instance:

public Object getValueAt(int row, int column) {
  return bank.getOperations().get(row)...
}

This is slow but a simple way to get updates.

b) In the more complicated way you would have the AbstractTableModel register with the Bank object to receive an event when a new operation is added to the Bank. This would look like:

public class BankTableModel extends AbstractTableModel {
  private List<Operation> operations;

  public BankTableModel(Bank bank) {
    operations = bank.getOperations();
    bank.addOperationEventListener(...);
  }

  public Object getValueAt(int row, int column) {
    return operations.get(row)...
  }
}

The problem with this is that RMI does not provide a mechanism for the server to talk to the client so both the server and client need to be RMI endpoints. See RMI Events.

2) The whole point of RMI is you get a stub of the remote object that resides on the server. The stub allows you to call methods on the remote object as if that object was local. Don't worry about the security at this level especially in an academic setting.

I would get rid of the Session object and just return the Bank object directly. If you are forwarding all your calls to the Bank object then you really just want to interact with the Bank object directly. In a more complicated system you may have justifiable reason for adding Proxy or Facade layers but I would keep it simple in this case.

3) Your GUI and your Server should be two different objects. Your GUI is your client and there should be no GUI code at all on your server side.

Community
  • 1
  • 1
rancidfishbreath
  • 3,944
  • 2
  • 30
  • 44
  • 1) Thanks for your answer I was thinking effectively thinking about listeners. 2) Actually I really need a secured application, I was giving the whole Bank at the beginning but it's networking programming project. So it must be realistic and I need to keep this Session architecture. I plan to secure the RMI connection with SSL later on. 3) Both the Client and the Server need a GUI. I was speaking about the Server GUI which shows in real time every operations. That's my JTable. – xenom Dec 03 '12 at 17:22
  • That makes it easy then. Just fire an event when an operation is added to your Bank and have the AbstractTableModel listen to the event as in 1b) – rancidfishbreath Dec 03 '12 at 17:27