Java Clients
Connecting with Directly Supplied Server PropertiesIn order to make a connection to an IOM server, you must give the Java Workspace Factory specific information about the server and about the desired connection. The quickest and simplest method of providing this information is to place it directly into the client program using name/value pairs in ajava.util.Properties object.
The following properties can be provided:
ExampleThe Java code in this example demonstrates how to use name/value pairs in ajava.util.Properties object to provide information to the
Java Workspace Factory and obtain a workspace object reference.
For information about how to use the workspace object reference, see
Language Service Example.
The last two statements in the example show how to dispose of a workspace object reference. For details about this procedure, see Returning a Workspace to the Java Workspace Factory. import com.sas.iom.WorkspaceConnector; import com.sas.iom.WorkspaceFactory; import com.sas.iom.SAS.IWorkspace; import java.util.Properties; Properties iomServerProperties = new Properties(); iomServerProperties.put("host",host); iomServerProperties.put("port",port); iomServerProperties.put("userName",user name); iomServerProperties.put("password",password); Properties[] serverList = {iomServerProperties}; WorkspaceFactory wFactory = new WorkspaceFactory(serverList,null,null); WorkspaceConnector connector = wFactory.getWorkspaceConnector(0L); IWorkspace workspace = connector.getWorkspace(); < insert workspace usage code here > wFactory.shutdown(); connector.close(); In the preceding example, exception handling statements have been removed for the sake of clarity. The example will not compile as shown.Adding Connection Pooling FeaturesWith minor changes to the preceding example program, you can use the Java Workspace Factory to manage a pool of connections to an IOM server rather than a single connection. When set up for connection pooling, the Java Workspace Factory tries to fulfill each client's requests for workspace objects by opening a new workspace object on an existing connection to an IOM server. This is less time consuming than creating a new connection. Behind the scenes, the Java Workspace Factory keeps a configurable number of connections alive at all times. For connection pooling to work properly, you must notify the Java Workspace Factory when you are finished using a workspace object by callingcom.sas.iom.WorkspaceConnector.close() . For more details, Returning a Workspace to the Java Workspace Factory.
When a client uses a workspace object, it has exclusive access to the connection serving that workspace object. When the client is finished using the workspace object, the workspace object is closed before the connection is returned to the pool. These actions help preserve the performance and security of the single connection case. You can also 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, simply provide a separate To implement connection pooling, you can specify the following properties for each server in addition to the other server properties described previously.
In addition to the information about the servers that participate in a connection
pool, you can also specify information about the pool itself.
Again, the information can be provided to the Java Workspace Factory as name/value pairs in
a
ExampleThe following example demonstrates how to specify server properties to the Java Workspace Factory and obtain four workspace object references using only two connections to IOM servers. For information about how to use the workspace object reference, see Language Service Example.The last part of this example shows how to dispose of a workspace object reference. For details about this procedure, see Returning a Workspace to the Java Workspace Factory. import com.sas.iom.WorkspaceConnector; import com.sas.iom.WorkspaceFactory; import com.sas.iom.SAS.IWorkspace; import java.util.Properties; Properties serverProperties0 = new Properties(); serverProperties0.put("host",host 0); serverProperties0.put("port",port 0); serverProperties0.put("userName",user name 0); serverProperties0.put("password",password 0); serverProperties0.put("sasMaxPerWorkspacePool","1"); serverProperties0.put("sas-RecycleActivationLimit","2"); Properties serverProperties1 = new Properties(); serverProperties1.put("host",host 1); serverProperties1.put("port",port 1); serverProperties1.put("userName",user name 1); serverProperties1.put("password",password 1); serverProperties1.put("sasMaxPerWorkspacePool","1"); serverProperties1.put("sas-RecycleActivationLimit","2"); Properties[] serverList = {serverProperties0,serverProperties1}; Properties poolProperties = new Properties(); poolProperties.put("sasMinSize","2"); WorkspaceFactory wFactory = new WorkspaceFactory(serverList,poolProperties,null); WorkspaceConnector connector0 = wFactory.getWorkspaceConnector(0L); IWorkspace workspace0 = connector0.getWorkspace(); WorkspaceConnector connector1 = wFactory.getWorkspaceConnector(0L); IWorkspace workspace1 = connector1.getWorkspace(); < insert workspace0 and workspace1 usage code here > connector0.close(); connector1.close(); WorkspaceConnector connector2 = wFactory.getWorkspaceConnector(0L); IWorkspace workspace2 = connector2.getWorkspace(); WorkspaceConnector connector3 = wFactory.getWorkspaceConnector(0L); IWorkspace workspace3 = connector3.getWorkspace(); < insert workspace2 and workspace3 usage code here > wFactory.shutdown(); connector2.close(); connector3.close(); In the preceding example, exception handling statements have been removed for the sake of clarity. The example will not compile as shown.Waiting for Connections to Become AvailableAt the time of a client's request for a workspace object, it is possible that all of the available connections in a connection pool will already be allocated to other clients. For example, the Java Workspace Factory might not be able to make an additional connection to a server because it would violate thesasMaxPerWorkspacePool value that
has been set for the server.
In such cases, the client's request cannot be fulfilled until one of the other clients
is finished with its workspace object.
To indicate what action you want the Java Workspace Factory to take when a request
cannot be fulfilled immediately, you can use a
Logging Java Workspace Factory ActivityThe Java Workspace Factory will write diagnostic and status messages to an instance ofjava.util.PrintWriter if you provide one.
The information that the Java Workspace Factory writes to this object will be useful
for debugging or performance monitoring.
ExampleThe following example shows how to make the Java Workspace Factory write messages to standard output: import com.sas.iom.WorkspaceConnector; import com.sas.iom.WorkspaceFactory; import com.sas.iom.SAS.IWorkspace; import java.io.PrintWriter; import java.util.Properties; PrintWriter logWriter = new PrintWriter(System.out); Properties iomServerProperties = new Properties(); iomServerProperties.put("host",host); iomServerProperties.put("port",port); iomServerProperties.put("userName",user name); iomServerProperties.put("password",password); Properties[] serverList = {iomServerProperties}; WorkspaceFactory wFactory = new WorkspaceFactory(serverList,null,logWriter); WorkspaceConnector connector = wFactory.getWorkspaceConnector(0L); IWorkspace workspace = connector.getWorkspace(); < insert workspace usage code here > wFactory.shutdown(); connector.close(); In the preceding example, exception handling statements have been removed for the sake of clarity. The example will not compile as shown. |