Prevents sending of more than one COIN every 200ms to a specific CallPeerJabberImpl.

cusax-fix
Boris Grozev 13 years ago
parent 5558392ded
commit 19d7346050

@ -71,6 +71,17 @@ public class CallPeerJabberImpl
*/
private final Object sidSyncRoot = new Object();
/**
* Whether a COIN has been scheduled to be sent to this
* <tt>CallPeerJabberImpl</tt>
*/
private boolean coinScheduled = false;
/**
* Synchronization object for coinScheduled
*/
private final Object coinScheduledSyncRoot = new Object();
/**
* Creates a new call peer with address <tt>peerAddress</tt>.
*
@ -1453,4 +1464,20 @@ else if (((IQ) result).getType() != IQ.Type.RESULT)
new TransferredPacketExtension()));
}
}
public boolean isCoinScheduled()
{
synchronized (coinScheduledSyncRoot)
{
return coinScheduled;
}
}
public void setCoinScheduled(boolean coinScheduled)
{
synchronized (coinScheduledSyncRoot)
{
this.coinScheduled = coinScheduled;
}
}
}

@ -49,6 +49,12 @@ public class OperationSetTelephonyConferencingJabberImpl
private static final Logger logger
= Logger.getLogger(OperationSetTelephonyConferencingJabberImpl.class);
/**
* The minimum interval in milliseconds between COINs sent to a single
* <tt>CallPeer</tt>.
*/
private static final int COIN_MIN_INTERVAL = 200;
/**
* Synchronization object.
*/
@ -107,7 +113,34 @@ private void notify(CallPeer callPeer)
if(!(callPeer instanceof CallPeerJabberImpl))
return;
CallPeerJabberImpl callPeerJabber = (CallPeerJabberImpl)callPeer;
final CallPeerJabberImpl callPeerJabber = (CallPeerJabberImpl)callPeer;
final long timeSinceLastCoin = System.currentTimeMillis()
- callPeerJabber.getLastConferenceInfoSentTimestamp();
if (timeSinceLastCoin < COIN_MIN_INTERVAL)
{
if (callPeerJabber.isCoinScheduled())
return;
logger.info("Scheduling to send a COIN to " + callPeerJabber);
callPeerJabber.setCoinScheduled(true);
new Thread(new Runnable(){
@Override
public void run()
{
try
{
Thread.sleep(1 + COIN_MIN_INTERVAL - timeSinceLastCoin);
}
catch (InterruptedException ie) {}
OperationSetTelephonyConferencingJabberImpl.this
.notify(callPeerJabber);
}
}).start();
return;
}
// check that callPeer supports COIN before sending him a
// conference-info
@ -124,6 +157,7 @@ private void notify(CallPeer callPeer)
ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_COIN))
{
logger.info(callPeer.getAddress() + " does not support COIN");
callPeerJabber.setCoinScheduled(false);
return;
}
}
@ -162,6 +196,7 @@ private void notify(CallPeer callPeer)
System.currentTimeMillis());
}
}
callPeerJabber.setCoinScheduled(false);
}
/**

Loading…
Cancel
Save