Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / models / RoomManager.java
  1. package com.ntlab.irisserver.models;
  2. import com.ntlab.irisserver.entities.Room;
  3. import org.springframework.stereotype.Component;
  4.  
  5. import javax.ws.rs.*;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.UUID;
  9.  
  10. @Component
  11. public class RoomManager {
  12. private static RoomManager theInstance = null;
  13. private Map<String, Room> rooms = new HashMap<String, Room>();
  14.  
  15. public static RoomManager getInstance(){
  16. if(theInstance == null){
  17. theInstance = new RoomManager();
  18. }
  19. return theInstance;
  20. }
  21.  
  22. public Room createRoom(String owner){
  23. UUID uuid = UUID.randomUUID();
  24. String rid = uuid.toString(); //uuid型からstring型に変換
  25. Room r = new Room(rid, owner);
  26. rooms.put(rid, r);
  27. return r;
  28. }
  29.  
  30. public Room getRoom(String rid){
  31. Room r = rooms.get(rid);
  32. return r;
  33. }
  34.  
  35. public void deleteRoom(String rid){
  36. rooms.remove(rid);
  37. }
  38.  
  39.  
  40. }