Commit 952d0559 authored by jehan's avatar jehan

add proxy publisher timer

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@109 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent b4c1f861
......@@ -173,6 +173,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mConfigurator.setProperty(JxtaNetworkManager.HTTP_LISTENING_PUBLIC_ADDRESS,args[i + 1]+":9700");
mConfigurator.setProperty(JxtaNetworkManager.TCP_LISTENING_PUBLIC_ADDRESS,args[i + 1]+":9701");
mConfigurator.setProperty(RtpRelayService.AUDIO_VIDEO_PUBLIC_URI,"udp://"+args[i + 1]+":"+lMediaPort);
mConfigurator.setProperty(SipProxyRegistrar.REGISTRAR_PUBLIC_ADDRESS,args[i + 1]);
System.out.println("public address detected[" + args[i + 1] + "]");
}
else if (argument.equals("-socks-url")) {
......@@ -267,8 +268,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
}
//setup account manager
mP2pProxyAccountManagement = new P2pProxyAccountManagement(mJxtaNetworkManager);
//set management
try {
ObjectName lObjectName = new ObjectName(ACCOUNT_MGR_MBEAN_NAME);
......@@ -301,6 +301,8 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mServiceProvider = new EdgePeerServiceManager(aProperties, mJxtaNetworkManager);
mP2pProxyManagement = (P2pProxyManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
//setup account manager
mP2pProxyAccountManagement = new P2pProxyAccountManagement(mJxtaNetworkManager);
mServiceProvider.start(3000L);
}
......@@ -311,6 +313,8 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mP2pProxyManagement = (P2pProxyManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
mServiceProvider.start(3000L);
//setup account manager
mP2pProxyAccountManagement = new P2pProxyAccountManagement(mJxtaNetworkManager);
// setup sip provider
SipStack.log_path = mConfigHomeDir+"/logs";
mSipAndPipeListener = new SipProxyRegistrar(mConfigurator,mJxtaNetworkManager,mP2pProxyAccountManagement);
......@@ -330,7 +334,9 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mP2pProxyManagement = null;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
mServiceProvider.start(3000L);
// setup sip provider
//setup account manager
mP2pProxyAccountManagement = new P2pProxyAccountManagement(mJxtaNetworkManager);
// setup sip provider
SipStack.log_path = mConfigHomeDir+"/logs";
mSipAndPipeListener = new SipProxyRegistrar(mConfigurator,mJxtaNetworkManager,mP2pProxyAccountManagement);
//set management
......
......@@ -26,6 +26,8 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
......@@ -57,6 +59,7 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
public final static String REGISTRAR_PORT="org.linphone.p2pproxy.SipListener.registrar.port";
public final static String REGISTRAR_PUBLIC_ADDRESS="org.linphone.p2pproxy.SipListener.registrar.public.address";
public final static String ADV_NAME = "p2p-proxy-proxyregistrar";
private final int ADV_LIFE_TIME=60000;
//
private final SipProvider mProvider;
private final JxtaNetworkManager mJxtaNetworkManager;
......@@ -68,7 +71,8 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
private final P2pProxyAccountManagementMBean mP2pProxyAccountManagement;
private final Configurator mProperties;
private final SuperPeerProxy mSuperPeerProxy;
private final NetworkResourceAdvertisement mProxyRegistrationAdvertisement;
private NetworkResourceAdvertisement mProxyRegistrationAdvertisement;
private final Timer mTimer = new Timer ("Proxy registrar adv publisher");
//private long mNumberOfEstablishedCall;
private long mNumberOfRefusedRegistration;
......@@ -172,12 +176,21 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
mProvider.addSipProviderListener(SipProvider.PROMISQUE,this);
mPool = Executors.newCachedThreadPool();
mSuperPeerProxy = new SuperPeerProxy(aJxtaNetworkManager, "sip:"+mProvider.getViaAddress()+":"+mProvider.getPort(),mRegistrationTab);
mProxyRegistrationAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType());
mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), mSuperPeerProxy.getSipProxyRegistrarAddress().toString().getBytes()));
mProxyRegistrationAdvertisement.setAddress(mSuperPeerProxy.getSipProxyRegistrarAddress());
mProxyRegistrationAdvertisement.setName(ADV_NAME);
mJxtaNetworkManager.getPeerGroup().getDiscoveryService().publish(mProxyRegistrationAdvertisement,60000,30000);
mLog.info(mProxyRegistrationAdvertisement + "published");
TimerTask lPublisherTask = new TimerTask() {
@Override
public void run() {
try {
SipProxyRegistrar.this.publishAdvertisement();
} catch (IOException e) {
mLog.error("cannot publish proxy registar adv", e);
}
}
};
mTimer.scheduleAtFixedRate(lPublisherTask, 0, ADV_LIFE_TIME-ADV_LIFE_TIME/10);
}
public void onReceivedMessage(SipProvider aProvider, Message aMessage) {
if (aProvider.getListeners().containsKey(aMessage.getTransactionId())) {
......@@ -355,4 +368,14 @@ public void stop() {
public long getNumberOfUnRegistration() {
return mNumberOfUnRegistration;
}
private void publishAdvertisement() throws IOException {
if (mProxyRegistrationAdvertisement == null) {
mProxyRegistrationAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType());
mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), mSuperPeerProxy.getSipProxyRegistrarAddress().toString().getBytes()));
mProxyRegistrationAdvertisement.setAddress(mSuperPeerProxy.getSipProxyRegistrarAddress());
mProxyRegistrationAdvertisement.setName(ADV_NAME);
}
mJxtaNetworkManager.getPeerGroup().getDiscoveryService().publish(mProxyRegistrationAdvertisement,ADV_LIFE_TIME,ADV_LIFE_TIME/2);
mLog.info(mProxyRegistrationAdvertisement + "published");
}
}
......@@ -77,7 +77,7 @@ public UserInstance(final String userName) throws P2pProxyException {
if (lFile.exists() == false) lFile.mkdir();
mProvider=new SipProvider(null,lSipPort);
mSipClient = new SipClient(mProvider,userName,30000);
final TimerTask lTimerTask = new TimerTask() {
class RegistrarTimerTask extends TimerTask {
@Override
public void run() {
try {
......@@ -94,12 +94,12 @@ public UserInstance(final String userName) throws P2pProxyException {
} catch(Exception e) {
mLog.error("cannot register user["+userName+"]",e);
} finally {
mTimer.schedule(this, REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
mTimer.schedule(new RegistrarTimerTask(), REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
}
}
};
mTimer.schedule(lTimerTask, REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
mTimer.schedule(new RegistrarTimerTask(), REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
mSipClient.listen();
} catch (Exception e) {
throw new P2pProxyException("cannot start client",e);
......@@ -128,7 +128,6 @@ public static void main(String[] args) throws P2pProxyException {
} else if (argument.equals("-nb-call")) {
lLoop = Integer.parseInt(args[i + 1]);
System.out.println("nb-call [" + lLoop + "]");
isRegistered
} else {
System.out.println("Invalid option: " + args[i]);
usage();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment