Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.service.protocol
Class AbstractCallPeer<T extends Call,U extends ProtocolProviderService>

java.lang.Object
  extended by net.java.sip.communicator.util.PropertyChangeNotifier
      extended by net.java.sip.communicator.service.protocol.AbstractCallPeer<T,U>
Type Parameters:
T - the call extension class like for example CallSipImpl or CallJabberImpl
U - the provider extension class like for example ProtocolProviderServiceSipImpl or ProtocolProviderServiceJabberImpl
All Implemented Interfaces:
CallPeer
Direct Known Subclasses:
CallPeerGibberishImpl, MediaAwareCallPeer, MockCallPeer

public abstract class AbstractCallPeer<T extends Call,U extends ProtocolProviderService>
extends PropertyChangeNotifier
implements CallPeer

Provides a default implementation for most of the CallPeer methods with the purpose of only leaving custom protocol development to clients using the PhoneUI service.

Author:
Emil Ivov, Lyubomir Marinov, Yana Stamcheva

Field Summary
protected  List<CallPeerConferenceListener> callPeerConferenceListeners
          The list of CallPeerConferenceListeners interested in and to be notified about changes in conference-related information such as this peer acting or not acting as a conference focus and conference membership details.
protected  List<CallPeerListener> callPeerListeners
          All the CallPeer listeners registered with this CallPeer.
protected  List<CallPeerSecurityListener> callPeerSecurityListeners
          All the CallPeerSecurityListener-s registered with this CallPeer.
protected static ConferenceMember[] NO_CONFERENCE_MEMBERS
          The constant which describes an empty set of ConferenceMembers (and which can be used to reduce allocations).
 
Fields inherited from interface net.java.sip.communicator.service.protocol.CallPeer
CALL_DURATION_START_TIME_UNKNOWN, MUTE_PROPERTY_NAME
 
Constructor Summary
AbstractCallPeer()
           
 
Method Summary
 void addCallPeerConferenceListener(CallPeerConferenceListener listener)
          Implements CallPeer#addCallPeerConferenceListener( CallPeerConferenceListener).
 void addCallPeerListener(CallPeerListener listener)
          Registers the listener to the list of listeners that would be receiving CallPeerEvents.
 void addCallPeerSecurityListener(CallPeerSecurityListener listener)
          Registers the listener to the list of listeners that would be receiving CallPeerSecurityEvents.
 void addConferenceMember(ConferenceMember conferenceMember)
          Adds a specific ConferenceMember to the list of ConferenceMembers reported by this peer through getConferenceMembers() and getConferenceMemberCount() and fires CallPeerConferenceEvent#CONFERENCE_MEMBER_ADDED to the currently registered CallPeerConferenceListeners.
protected  ConferenceMember findConferenceMember(long ssrc)
          Returns the ConferenceMember with the specified ssrc ID or null if there is no such ConferenceMember.
protected  void fireCallPeerChangeEvent(String eventType, Object oldValue, Object newValue)
          Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue,
protected  void fireCallPeerChangeEvent(String eventType, Object oldValue, Object newValue, String reason)
          Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.
protected  void fireCallPeerChangeEvent(String eventType, Object oldValue, Object newValue, String reason, int reasonCode)
          Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.
protected  void fireCallPeerConferenceEvent(CallPeerConferenceEvent conferenceEvent)
          Fires a specific CallPeerConferenceEvent to the CallPeerConferenceListeners interested in changes in the conference-related information provided by this peer.
protected  void fireCallPeerSecurityMessageEvent(String messageType, String i18nMessage, int severity)
          Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.
protected  void fireCallPeerSecurityOffEvent(CallPeerSecurityOffEvent evt)
          Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.
protected  void fireCallPeerSecurityOnEvent(CallPeerSecurityOnEvent evt)
          Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.
abstract  T getCall()
          Returns a reference to the call that this peer belongs to.
 long getCallDurationStartTime()
          Gets the time at which this CallPeer transitioned into a state (likely CallPeerState.CONNECTED) marking the start of the duration of the participation in a Call.
 URL getCallInfoURL()
          Returns a URL pointing ta a location with call control information for this peer or null if no such URL is available for this call peer.
 int getConferenceMemberCount()
          Returns the count of the members contained in this peer.
 ConferenceMember[] getConferenceMembers()
          Implements CallPeer#getConferenceMembers().
 CallPeerSecurityStatusEvent getCurrentSecuritySettings()
          Returns the currently used security settings of this CallPeer.
abstract  U getProtocolProvider()
          Returns the protocol provider that this peer belongs to.
 CallPeerState getState()
          Returns an object representing the current state of that peer.
 boolean isConferenceFocus()
          Determines whether this call peer is currently a conference focus.
 boolean isMute()
          Determines whether the audio stream (if any) being sent to this peer is mute.
 void removeCallPeerConferenceListener(CallPeerConferenceListener listener)
          Implements CallPeer#removeCallPeerConferenceListener( CallPeerConferenceListener).
 void removeCallPeerListener(CallPeerListener listener)
          Unregisters the specified listener.
 void removeCallPeerSecurityListener(CallPeerSecurityListener listener)
          Unregisters the specified listener.
 void removeConferenceMember(ConferenceMember conferenceMember)
          Removes a specific ConferenceMember from the list of ConferenceMembers reported by this peer through getConferenceMembers() and getConferenceMemberCount() if it is contained and fires CallPeerConferenceEvent#CONFERENCE_MEMBER_REMOVED to the currently registered CallPeerConferenceListeners.
 void setConferenceFocus(boolean conferenceFocus)
          Specifies whether this peer is a conference focus.
 void setMute(boolean newMuteValue)
          Sets the mute property for this call peer.
 void setState(CallPeerState newState)
          Causes this CallPeer to enter the specified state.
 void setState(CallPeerState newState, String reason)
          Causes this CallPeer to enter the specified state.
 void setState(CallPeerState newState, String reason, int reasonCode)
          Causes this CallPeer to enter the specified state.
 String toString()
          Returns a string representation of the peer in the form of
Display Name <address>;status=CallPeerStatus
 
Methods inherited from class net.java.sip.communicator.util.PropertyChangeNotifier
addPropertyChangeListener, firePropertyChange, getPropertyChangeSource, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.java.sip.communicator.service.protocol.CallPeer
addConferenceMembersSoundLevelListener, addPropertyChangeListener, addStreamSoundLevelListener, getAddress, getContact, getDisplayName, getImage, getPeerID, removeConferenceMembersSoundLevelListener, removePropertyChangeListener, removeStreamSoundLevelListener
 

Field Detail

NO_CONFERENCE_MEMBERS

protected static final ConferenceMember[] NO_CONFERENCE_MEMBERS
The constant which describes an empty set of ConferenceMembers (and which can be used to reduce allocations).


callPeerListeners

protected final List<CallPeerListener> callPeerListeners
All the CallPeer listeners registered with this CallPeer.


callPeerSecurityListeners

protected final List<CallPeerSecurityListener> callPeerSecurityListeners
All the CallPeerSecurityListener-s registered with this CallPeer.


callPeerConferenceListeners

protected final List<CallPeerConferenceListener> callPeerConferenceListeners
The list of CallPeerConferenceListeners interested in and to be notified about changes in conference-related information such as this peer acting or not acting as a conference focus and conference membership details.

Constructor Detail

AbstractCallPeer

public AbstractCallPeer()
Method Detail

addCallPeerListener

public void addCallPeerListener(CallPeerListener listener)
Registers the listener to the list of listeners that would be receiving CallPeerEvents.

Specified by:
addCallPeerListener in interface CallPeer
Parameters:
listener - a listener instance to register with this peer.

removeCallPeerListener

public void removeCallPeerListener(CallPeerListener listener)
Unregisters the specified listener.

Specified by:
removeCallPeerListener in interface CallPeer
Parameters:
listener - the listener to unregister.

addCallPeerSecurityListener

public void addCallPeerSecurityListener(CallPeerSecurityListener listener)
Registers the listener to the list of listeners that would be receiving CallPeerSecurityEvents.

Specified by:
addCallPeerSecurityListener in interface CallPeer
Parameters:
listener - a listener instance to register with this peer.

removeCallPeerSecurityListener

public void removeCallPeerSecurityListener(CallPeerSecurityListener listener)
Unregisters the specified listener.

Specified by:
removeCallPeerSecurityListener in interface CallPeer
Parameters:
listener - the listener to unregister.

fireCallPeerChangeEvent

protected void fireCallPeerChangeEvent(String eventType,
                                       Object oldValue,
                                       Object newValue)
Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue,

Parameters:
eventType - the type of the event to create and dispatch.
oldValue - the value of the source property before it changed.
newValue - the current value of the source property.

fireCallPeerChangeEvent

protected void fireCallPeerChangeEvent(String eventType,
                                       Object oldValue,
                                       Object newValue,
                                       String reason)
Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.

Parameters:
eventType - the type of the event to create and dispatch.
oldValue - the value of the source property before it changed.
newValue - the current value of the source property.
reason - a string that could be set to contain a human readable explanation for the transition (particularly handy when moving into a FAILED state).

fireCallPeerChangeEvent

protected void fireCallPeerChangeEvent(String eventType,
                                       Object oldValue,
                                       Object newValue,
                                       String reason,
                                       int reasonCode)
Constructs a CallPeerChangeEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.

Parameters:
eventType - the type of the event to create and dispatch.
oldValue - the value of the source property before it changed.
newValue - the current value of the source property.
reason - a string that could be set to contain a human readable explanation for the transition (particularly handy when moving into a FAILED state).
reasonCode - the reason code for the reason of this event.

fireCallPeerSecurityOnEvent

protected void fireCallPeerSecurityOnEvent(CallPeerSecurityOnEvent evt)
Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.

Parameters:
evt - the event object with details to pass on to the consumers

fireCallPeerSecurityOffEvent

protected void fireCallPeerSecurityOffEvent(CallPeerSecurityOffEvent evt)
Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.

Parameters:
evt - the event object with details to pass on to the consumers

fireCallPeerSecurityMessageEvent

protected void fireCallPeerSecurityMessageEvent(String messageType,
                                                String i18nMessage,
                                                int severity)
Constructs a CallPeerSecurityStatusEvent using this call peer as source, setting it to be of type eventType and the corresponding oldValue and newValue.

Parameters:
messageType - the type of the message
i18nMessage - message
severity - severity level

toString

public String toString()
Returns a string representation of the peer in the form of
Display Name <address>;status=CallPeerStatus

Specified by:
toString in interface CallPeer
Overrides:
toString in class Object
Returns:
a string representation of the peer and its state.

getCallInfoURL

public URL getCallInfoURL()
Returns a URL pointing ta a location with call control information for this peer or null if no such URL is available for this call peer.

Specified by:
getCallInfoURL in interface CallPeer
Returns:
a URL link to a location with call information or a call control web interface related to this peer or null if no such URL is available.

getState

public CallPeerState getState()
Returns an object representing the current state of that peer.

Specified by:
getState in interface CallPeer
Returns:
a CallPeerState instance representing the peer's state.

setState

public void setState(CallPeerState newState,
                     String reason)
Causes this CallPeer to enter the specified state. The method also sets the currentStateStartDate field and fires a CallPeerChangeEvent.

Parameters:
newState - the state this call peer should enter.
reason - a string that could be set to contain a human readable explanation for the transition (particularly handy when moving into a FAILED state).

setState

public void setState(CallPeerState newState,
                     String reason,
                     int reasonCode)
Causes this CallPeer to enter the specified state. The method also sets the currentStateStartDate field and fires a CallPeerChangeEvent.

Parameters:
newState - the state this call peer should enter.
reason - a string that could be set to contain a human readable explanation for the transition (particularly handy when moving into a FAILED state).
reasonCode - the code for the reason of the state change.

setState

public void setState(CallPeerState newState)
Causes this CallPeer to enter the specified state. The method also sets the currentStateStartDate field and fires a CallPeerChangeEvent.

Parameters:
newState - the state this call peer should enter.

getCallDurationStartTime

public long getCallDurationStartTime()
Gets the time at which this CallPeer transitioned into a state (likely CallPeerState.CONNECTED) marking the start of the duration of the participation in a Call.

Specified by:
getCallDurationStartTime in interface CallPeer
Returns:
the time at which this CallPeer transitioned into a state marking the start of the duration of the participation in a Call or CallPeer.CALL_DURATION_START_TIME_UNKNOWN if such a transition has not been performed

isMute

public boolean isMute()
Determines whether the audio stream (if any) being sent to this peer is mute.

The default implementation returns false.

Specified by:
isMute in interface CallPeer
Returns:
true if an audio stream is being sent to this peer and it is currently mute; false, otherwise

setMute

public void setMute(boolean newMuteValue)
Sets the mute property for this call peer.

Parameters:
newMuteValue - the new value of the mute property for this call peer

isConferenceFocus

public boolean isConferenceFocus()
Determines whether this call peer is currently a conference focus.

Specified by:
isConferenceFocus in interface CallPeer
Returns:
true if this peer is a conference focus and false otherwise.

setConferenceFocus

public void setConferenceFocus(boolean conferenceFocus)
Specifies whether this peer is a conference focus.

Parameters:
conferenceFocus - true if this peer is to become a conference focus and false otherwise.

getConferenceMembers

public ConferenceMember[] getConferenceMembers()
Implements CallPeer#getConferenceMembers(). In order to reduce allocations, returns #NO_CONFERENCE_MEMBERS if #conferenceMembers contains no ConferenceMember instances.

Specified by:
getConferenceMembers in interface CallPeer
Returns:
an array of the conference members

getConferenceMemberCount

public int getConferenceMemberCount()
Returns the count of the members contained in this peer.

Implements CallPeer#getConferenceMemberCount().

Specified by:
getConferenceMemberCount in interface CallPeer
Returns:
the count of the members contained in this peer

addConferenceMember

public void addConferenceMember(ConferenceMember conferenceMember)
Adds a specific ConferenceMember to the list of ConferenceMembers reported by this peer through getConferenceMembers() and getConferenceMemberCount() and fires CallPeerConferenceEvent#CONFERENCE_MEMBER_ADDED to the currently registered CallPeerConferenceListeners.

Parameters:
conferenceMember - a ConferenceMember to be added to the list of ConferenceMember reported by this peer. If the specified ConferenceMember is already contained in the list, it is not added again and no event is fired.

removeConferenceMember

public void removeConferenceMember(ConferenceMember conferenceMember)
Removes a specific ConferenceMember from the list of ConferenceMembers reported by this peer through getConferenceMembers() and getConferenceMemberCount() if it is contained and fires CallPeerConferenceEvent#CONFERENCE_MEMBER_REMOVED to the currently registered CallPeerConferenceListeners.

Parameters:
conferenceMember - a ConferenceMember to be removed from the list of ConferenceMember reported by this peer. If the specified ConferenceMember is no contained in the list, no event is fired.

addCallPeerConferenceListener

public void addCallPeerConferenceListener(CallPeerConferenceListener listener)
Implements CallPeer#addCallPeerConferenceListener( CallPeerConferenceListener). In the fashion of the addition of the other listeners, does not throw an exception on attempting to add a null listeners and just ignores the call.

Specified by:
addCallPeerConferenceListener in interface CallPeer
Parameters:
listener - the CallPeerConferenceListener to add

removeCallPeerConferenceListener

public void removeCallPeerConferenceListener(CallPeerConferenceListener listener)
Implements CallPeer#removeCallPeerConferenceListener( CallPeerConferenceListener).

Specified by:
removeCallPeerConferenceListener in interface CallPeer
Parameters:
listener - the CallPeerConferenceListener to remove

fireCallPeerConferenceEvent

protected void fireCallPeerConferenceEvent(CallPeerConferenceEvent conferenceEvent)
Fires a specific CallPeerConferenceEvent to the CallPeerConferenceListeners interested in changes in the conference-related information provided by this peer.

Parameters:
conferenceEvent - a CallPeerConferenceEvent to be fired and carrying the event data

findConferenceMember

protected ConferenceMember findConferenceMember(long ssrc)
Returns the ConferenceMember with the specified ssrc ID or null if there is no such ConferenceMember. The method is meant for very frequent use and every call simply iterates through the conference members collection without creating an iterator or other object that may have an impact on garbage collection when used frequently.

Parameters:
ssrc - the SSRC identifier of the RTP streams transmitted by the ConferenceMember that we are looking for.
Returns:
the ConferenceMember with the specified ssrc ID or null if there is no such member.

getCurrentSecuritySettings

public CallPeerSecurityStatusEvent getCurrentSecuritySettings()
Returns the currently used security settings of this CallPeer.

Specified by:
getCurrentSecuritySettings in interface CallPeer
Returns:
the CallPeerSecurityStatusEvent that contains the current security settings.

getCall

public abstract T getCall()
Returns a reference to the call that this peer belongs to.

Specified by:
getCall in interface CallPeer
Returns:
a reference to the call containing this peer.

getProtocolProvider

public abstract U getProtocolProvider()
Returns the protocol provider that this peer belongs to.

Specified by:
getProtocolProvider in interface CallPeer
Returns:
a reference to the ProtocolProviderService that this peer belongs to.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.