Java Clients
Pooling with Directly Supplied Server AttributesWith just a few changes to the example program in Connecting with Directly Supplied Server Attributes, you can use the Java Connection Factory to manage a pool of connections to an IOM server rather than a single factory-managed connection. When set up for connection pooling, the Java Connection Factory tries to fulfill each client's requests for connections by using an existing connection to an IOM server. This is less time consuming than creating a new connection. Behind the scenes, the Java Connection Factory keeps a configurable number of connections alive at all times. For connection pooling to work properly, you must notify the Java Connection Factory when you are finished using a connection by calling To create a pool:
You can maintain performance standards by spreading a pool of connections over more than one server and then setting an upper limit on the number of connections that each server can contribute to the pool. To specify multiple servers, provide a separate
A pool consists of one or more puddles (
To specify multiple puddles, provide a separate ExampleThe following example demonstrates how to specify server properties to the Java Connection Factory and obtain four object references using only two connections to IOM servers. In this example, the pool consists of a puddle with 2 servers. For information about how to use the object reference, see Language Service Example.The last part of this example shows how to dispose of an object reference. For details about this procedure, see Returning Connections to the Java Connection Factory. import java.util.HashSet; import java.util.Set; import com.sas.iom.SAS.IWorkspace; import com.sas.iom.SAS.IWorkspaceHelper; import com.sas.services.connection.BridgeServer; import com.sas.services.connection.Cluster; import com.sas.services.connection.ConnectionFactoryAdminInterface; import com.sas.services.connection.ConnectionFactoryConfiguration; import com.sas.services.connection.ConnectionFactoryInterface; import com.sas.services.connection.ConnectionFactoryManager; import com.sas.services.connection.ConnectionInterface; import com.sas.services.connection.Credential; import com.sas.services.connection.LoadBalancingCluster; import com.sas.services.connection.ManualConnectionFactoryConfiguration; import com.sas.services.connection.PasswordCredential; import com.sas.services.connection.Puddle; import com.sas.services.connection.Server; import org.omg.CORBA.Object; // identify the IOM servers String classID = Server.CLSID_SAS; int port = 5310; String domain = "unx"; Server server0 = new BridgeServer(classID,"serv1.unx.abc.com",port,domain); Server server1 = new BridgeServer(classID,"serv2.unx.abc.com",port,domain); Server[] servers = {server0,server1}; Cluster cluster = new LoadBalancingCluster(servers); // create a login for these servers Credential login = new PasswordCredential("adm1","adm1pass",domain); // create a set of users allowed to use the connections to the servers Credential user1 = new PasswordCredential("use1","use1pass"); Credential user2 = new PasswordCredential("use2","use2pass"); Set authorizedLogins = new HashSet(2); authorizedLogins.add(user1); authorizedLogins.add(user2); // make a puddle with the servers Puddle puddle = new Puddle(cluster,login); puddle.setUserCredentials(authorizedLogins); // make a connection factory configuration with the puddle ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration(puddle); // get a connection factory that matches the configuration ConnectionFactoryManager cxfManager = new ConnectionFactoryManager(); ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig); /* Use a private factory */ // cxfManager.getConnectionFactory(cxfConfig); /* Use a shared factory */ // get connections ConnectionInterface cx1 = cxf.getConnection(user1); Object obj1 = cx1.getObject(); IWorkspace iWorkspace1 = IWorkspaceHelper.narrow(obj1); System.out.println(iWorkspace1.UniqueIdentifier()); ConnectionInterface cx2 = cxf.getConnection(user2); Object obj2 = cx2.getObject(); IWorkspace iWorkspace2 = IWorkspaceHelper.narrow(obj2); System.out.println(iWorkspace2.UniqueIdentifier()); < insert iWorkspace1 and iWorkspace2 usage code here > cx1.close(); cx2.close(); ConnectionInterface cx3 = cxf.getConnection(user1); Object obj3 = cx3.getObject(); IWorkspace iWorkspace3 = IWorkspaceHelper.narrow(obj3); ConnectionInterface cx4 = cxf.getConnection(user1); CORBA.Object obj4 = cx4.getObject(); IWorkspace iWorkspace4 = IWorkspaceHelper.narrow(obj4); < insert iWorkspace3 and iWorkspace4 usage code here > cx3.close(); cx4.close(); // tell the factory that it can destroy unused connections admin.shutdown(); In an effort to make the previous example more readable, we have removed most of the code structuring elements. The example will not compile as it is shown. |