jeudi 24 novembre 2016

EJB Design Pattern: Multiple hosts on ApplicationServer

I have a design pattern question. If someone has a better heading, please let me know (difficult to find a good one for this).

My Situation:
There is a running application server. There are two different types of clients, a host client and a guest client. Host clients should be able to create, let's say a party with an identifier. Then the guest clients should be able to join any of those parties, depending on that identifiers.

My Idea:
Using different types of EJBs. As PartyController i wanna use a Singleton Session Bean:

@Singleton
public class PartyController {

    private Map<String, Party> parties;

    @Lock(LockType.WRITE)
    public void createParty(String identifier, Party party) { ... }

    @Lock(LockType.READ)
    public Party findParty(String identifier) { ... }
}

And for every client a Stateful Session Bean:

@Stateful
public class GuestController {

    @EJB
    PartyController partyController;

    private Party party;

    public void joinParty(String identifier) {
        party = partyController.get(identifier);
    }
}

And then the typical other stuff, like servlets and bla, but doesn't matter here. Just to say: the Party class has members, that are instance-dependent (initialized by the host-client). All clients at a party need to use the same party instance as read-only. So there shouldn't be problems with concurrent accesses.

My Question:
Is this a good way to solve this problem? Are there better ways to do this? I know that the singleton blocks while being accessed, but only when a party is created. Is this a stable solution for, let's say 10 Parties and 100 guests, or 100 parties and 1000 guests, and so on?

I'm at the beginning of developing my solution, so i need to have a good and stable base for further programming.

Thank you very much!

Aucun commentaire:

Enregistrer un commentaire