
org.mobicents.media.io.ice.FoundationsRegistry Maven / Gradle / Ivy
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2014, Telestax Inc and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see
*
*/
package org.mobicents.media.io.ice;
import java.util.HashMap;
import java.util.Map;
/**
* Registry that keeps records of generated foundations for the lifetime of an
* ICE agent.
*
* @author Henrique Rosa
* @see RFC5245
*/
public abstract class FoundationsRegistry {
/**
* Map that associates addresses to their corresponding foundation
*/
Map foundations = new HashMap();
private int currentFoundation = 0;
/**
* Retrieves the foundation associated to an address.
* If no foundation exists for such address, one will be generated.
*
* @param candidate
* The ICE candidate
* @return The foundation associated to the candidate address.
*/
public String assignFoundation(IceCandidate candidate) {
String identifier = computeIdentifier(candidate);
synchronized (this.foundations) {
String foundation = this.foundations.get(identifier);
if (foundation == null) {
this.currentFoundation++;
foundation = String.valueOf(this.currentFoundation);
this.foundations.put(identifier, foundation);
}
candidate.setFoundation(foundation);
return foundation;
}
}
/**
* Computes the identifier, based on a candidate, that will be used as the
* identifier to a foundation.
*
* @param candidate
* The candidate that holds data that will form the identifier
* @return The identifier
*/
protected abstract String computeIdentifier(IceCandidate candidate);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy