cancel
Showing results for 
Search instead for 
Did you mean: 

Question: HowTo Handle several client pools in JCo 3.0?

Former Member
0 Kudos

Hello Forum,

i have the requirement to handle several client pools in JCo 3.0.

Therefore:

It is no problem to create pooled client destinations with file based connection properties files. Please see code sample


		Properties pooledConDE = conn.getPooledConnection("DE");
		Properties pooledConEN = conn.getPooledConnection("EN");
		
		String poolDe = "POOL_DE";
		String poolEn = "POOL_EN";
		
		conn.createDestinationDataFile(poolDe, pooledConDE);
		conn.createDestinationDataFile(poolEn, pooledConEN);
		
		JCoDestination destDE = JCoDestinationManager.getDestination(poolDe);
		JCoDestination destEN = JCoDestinationManager.getDestination(poolEn);
		
		System.out.println(destDE.getAttributes());
		System.out.println(destEN.getAttributes());

But i dont want to use this file based connection properties and for that, i understood that i can create my own Custom Data provider. This basically works well with one pool. But when i want to add the second pool, i got the exception:


Exception in thread "main" java.lang.IllegalStateException: DestinationDataProvider already registered [com.myjco.de.connection.CustomConnectionDataProvider]
	at com.sap.conn.jco.rt.RuntimeEnvironment.setDestinationDataProvider(RuntimeEnvironment.java:133)
	at com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(Environment.java:220)
	at com.myjco.de.connection.Connection.testProvider(Connection.java:102)
	at com.myjco.de.test.TT_Connect.main(TT_Connect.java:40)

This exception appears, when i invoke the method "registerDestinationDataProvider()".


        CustomConnectionDataProvider myProviderDest1 = new CustomConnectionDataProvider(poolDE);
        
        com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProviderDest1);
        myProviderDest1.changePropertiesForABAP_AS(poolDE,pooledConDE);        
        
        CustomConnectionDataProvider myProviderDest2 = new CustomConnectionDataProvider(poolEN);
        
        com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProviderDest2); --> Here it fails
        myProviderDest2.changePropertiesForABAP_AS(poolEn,pooledConEN);

Can you please suggest, how to create this several pools without file handling?

Any hint is very appreciated.

Thanks and best regards,

Sigi

Edited by: Siegfried Ertl on Feb 8, 2011 7:23 AM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi all,

the solution is easy. This is a small example, that shows how it could be done.

Cheers,

Sigi



public class CustomDestinationDataProvider
{
    static class MyDestinationDataProvider implements DestinationDataProvider
    {
        private DestinationDataEventListener eL;

        private Hashtable<String, Properties> propertiesTab = new Hashtable<String, Properties>();
        
        public Properties getDestinationProperties(String destinationName)
        {
        	if(propertiesTab.containsKey(destinationName)){
        		return propertiesTab.get(destinationName);
        	}
            
            return null;
            //alternatively throw runtime exception
            //throw new RuntimeException("Destination " + destinationName + " is not available");
        }

        public void setDestinationDataEventListener(DestinationDataEventListener eventListener)
        {
            this.eL = eventListener;
        }

        public boolean supportsEvents()
        {
            return true;
        }
        
        void changePropertiesForABAP_AS(Properties pConProps)
        {
            if(pConProps.getProperty("ACTION").equalsIgnoreCase("CREATE")){
            	propertiesTab.put(pConProps.getProperty("jco.client.dest"), pConProps);
            	eL.updated(pConProps.getProperty("jco.client.dest"));            	
            }
            else if(pConProps.getProperty("ACTION").equalsIgnoreCase("DELETE")){
            	propertiesTab.remove(pConProps.getProperty("jco.client.dest"));
            	eL.deleted(pConProps.getProperty("jco.client.dest"));
            }
        }
    }
    
    
    public static void main(String[] args) throws Exception
    {
        Properties connectPropertiesEN = new Properties();
        connectPropertiesEN.setProperty("ACTION", "CREATE");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_DEST, "POOL_EN");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_ASHOST, "<HOST_IP>");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_SYSNR,  "<SYSNR>");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_CLIENT, "<CLIENT>");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_USER,   "<USER>");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_PASSWD, "<PASS>");
        connectPropertiesEN.setProperty(DestinationDataProvider.JCO_LANG,   "en");
        
        Properties connectPropertiesDE = new Properties();
        connectPropertiesDE.setProperty("ACTION", "CREATE");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_DEST, "POOL_DE");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_ASHOST, "<HOST_IP>");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_SYSNR,  "<SYSNR>");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_CLIENT, "<CLIENT>");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_USER,   "<USER>");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_PASSWD, "<PASS>");
        connectPropertiesDE.setProperty(DestinationDataProvider.JCO_LANG,   "de");        

        MyDestinationDataProvider myProvider = new MyDestinationDataProvider();
        
        com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);
        myProvider.changePropertiesForABAP_AS(connectPropertiesEN);
        myProvider.changePropertiesForABAP_AS(connectPropertiesDE);
        
        JCoDestination ABAP_AS_EN = JCoDestinationManager.getDestination("POOL_EN");
        System.out.println(ABAP_AS_EN.getAttributes());
        ABAP_AS_EN.ping();
        
        JCoDestination ABAP_AS_DE = JCoDestinationManager.getDestination("POOL_DE");
        System.out.println(ABAP_AS_DE.getAttributes());
        ABAP_AS_DE.ping();        

        System.out.println(ABAP_AS_EN.getDestinationName() +" destination is ok");
        System.out.println(ABAP_AS_DE.getDestinationName() +" destination is ok");        
        
    }
    
}