/* * (C) Copyright 2014 Kurento (http://kurento.org/) * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License * (LGPL) version 2.1 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-2.1.html * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ package com.kurento.kmf.demo.group; import static com.google.common.base.Strings.isNullOrEmpty; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.kurento.kmf.media.factory.MediaPipelineFactory; /** * @author Ivan Gracia (izanmail@gmail.com) * */ public class RoomManager { private final Logger log = LoggerFactory.getLogger(RoomManager.class); @Autowired private MediaPipelineFactory mpf; private final ConcurrentMap<String, Room> rooms = new ConcurrentHashMap<>(); /** * @param roomName * the name of the room * @return the room if it was already created, or a new one if it is the * first time this room is accessed */ public Room getRoom(String roomName) { Room room; if (isNullOrEmpty(roomName)) { throw new IllegalArgumentException("Room name cannot be empty"); } log.debug("Searching for room {}", roomName); room = rooms.get(roomName); if (room == null) { log.debug("Room {} not existent. Will create now!", roomName); room = new Room(roomName, mpf.create()); rooms.put(roomName, room); } return room; } }