Use a Specific Connection Broker in DFC Client

Suppose that we need to create a  DFC client that won’t have connection broker information before run time. So we couldn’t put this information in dmcl.ini (this is pre D6, but one could imagine a similar situation for dfc.properties – the solution would probably be similar, maybe not identical).  Yes, one could list all the connection brokers present in the environment in dmcl.ini. There may be a reason we want to use a specific connection broker. For example, if we cloned a repository (say, DEV or QA copy of production) we may have two repositories with the same ID in our environment. In this case, one repository would be hidden by the other depending on the order of connection brokers in the dmcl.ini. Once there is a such a need, it can be accomplished as follows:

// connection broker info
String cbHost = "host";
int cbPort = 1489;

// connection info
String repo = "docbasename";
String user = "me";
String pass = "secret";
String domain = null;

// get local client
IDfClientX clientx = new DfClientX();
IDfClient client = clientx.getLocalClient();

// alter client config to set the primary connection broker
IDfTypedObject cfg = client.getClientConfig();
cfg.setString("primary_host", cbHost);
cfg.setInt("primary_port", cbPort);

// create login info to set identity
IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
loginInfoObj.setUser(user);
loginInfoObj.setPassword(pass);
loginInfoObj.setDomain(domain);

// Create and bind the Session Manager to the login info
IDfSessionManager sessionManager = client.newSessionManager();
sessionManager.setIdentity(repo, loginInfoObj);

IDfSession session = sessionManager.getSession(repo);

Of course, you need to set the host and connection strings according to your environment.

Note that this code alters the configuration that was read from dmcl.ini so we couldn’t rely on dmcl.ini configuration any more while we are using the same session manager. If we need to go back to the regular dmcl.ini configuration we will need to save that information before overwriting it. Or we could start from scratch creating a new DfClientX object.

Such a need maybe rare but when you need it you really need it.

[This approach is probably unsupported. This post doesn’t claim suitability for any purpose whatsoever.]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s