package com.xmr.net.client;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.jboss.netty.channel.Channel;

public class SessionManager {
	
	private ConcurrentMap<Integer, Session> Sessions;
	
	public SessionManager() {
		this.Sessions = new ConcurrentHashMap<Integer, Session>();
	}
	
	public boolean addSession(Channel channel) {
		return this.Sessions.putIfAbsent(channel.getId(), new Session(channel)) == null;
	}
	
	public void removeSession(Channel channel) {
		this.Sessions.remove(channel.getId());
	}
	
	public Session getSession(Channel channel) {
		return this.Sessions.get(channel.getId());
	}
	
	public boolean hasSession(Channel channel) {
		return this.Sessions.containsKey(channel.getId());
	}
	
	public Session getSessionWithId(Integer id) {
		for (Session Session : this.Sessions.values())
		{
			if (Session.getHabbo().getId() == id) {
				return Session;
			}
		}
		return null;
	}
}
