How to choose the right Java data structure for modeling 1st relational mapping?

Scenario

I am going to be as brief as possible. Basically, referring to this classdiag , I have a facade that manages the SocketManager list (which manages a single socket connection). Each SocketManager registers with a remote server using a unique SocketUserId. In addition, each SocketManager will receive messages from clients destined for a specific list of Recipients . For discussion, view these Recipients as easily as remote data buckets identified by name.

Customers will send data as follows:

SocketFacade facade = ...;

byte[] data = ...

facade.sendData( receipient, data );

When SocketFacade starts, it will query the mysql table, which returns a 1-m relationship between SocketUserId and Receipients. I will use MultiValuedMap to represent this 1 m relationship. Then several SocketManager will be launched , iterating over the map.

(1) Map< SocketUserId, List<Receipient> > 

eg. Suppose we have 2 SocketManager with SocketUserIds "alice" and "tom" respectively

            +----SocketManager1 ( "alice" ) for Receipients { "B", "C" }
            |
 SocketFacade 
            |
            +----SocketManager2 ( "tom" ) for Receipients { "A", "D" }

Question

I am linking to how to implement the sendData method. Basically I need a way to map the receiver (for example, "B") to its responsible SocketManager (for example, SocketManager1).

Suppose i do it

(2) Map< SocketUserId, SocketManager >
(3) Map< Receipient, SocketUserId >
  • Do I need a SoftReference for the value in (2)?
  • SocketManager?
  • SocketFacade , , (1). , (1), (2) (3) . SocketFacade . , - , / .

    interface Callback
    {
        void receipientAdded( Receipient r );
        void receipientDeleted( Receipient r );
    }
    
+3
3

SocketManager Receipient. , ( , ).

SocketManager Receipient. Receipient, SocketManager.

SocketFacade , SocketUserId SocketManager. . , , . SQL-.

ORM.

+1

1-1 SocketUserId SocketManager, SocketUserId SocketManager SocketManager ?

, , SocketManager. sendData SocketManager.

+1

: 1 Thing, n OtherThing s. , , Thing java.util.List<OtherThing> n OtherThing s. () . , java.util.List Thing ( ). List ​​ java.util.ArrayList<OtherThing> , .

+1
source

Source: https://habr.com/ru/post/1708722/


All Articles