There are several ways to use MOIDs on the IBM Director Console.
Since we are running inside the Console and the Con-Objects are also inthe Console, we can use them directly. The idea is this:
In a previous section we created a targetted Interactive Task which displayed the MOID for the target Managed Object. We could change that code to display the label for the Managed Object by changing the code that was in buildView() from this:
String msg = resourceBundle.getString("HelloMsgTarget"); Long moid = new Long(moids.GetValue(0)); // get the first moid // Build the substitution array to format the translated string Object substitutions[] = new Object[]{moid}; message = MessageFormat.format(msg, substitutions);
to:
String msg = resourceBundle.getString("HelloMsgTarget"); long moid = moids.GetValue(0); // get the first moid // Now get the label of the Managed Object TWGConManagedObject conObject = (TWGConManagedObject) TWGConObject.FindObject(moid); String targetLabel = conObject.getName(); // Build the substitution array to format the translated string Object substitutions[] = new Object[]{targetLabel}; message = MessageFormat.format(msg, substitutions);
Additionally, we will want to change the string for "HelloMsgTarget" in the Resource Bundle from:
{ "HelloMsgTarget", "Hello From Bob Co target moid = {0}" },to:
{ "HelloMsgTarget", "Hello From Bob Co target = {0}" },
When we redeploy and test, we see the system name in the Task Frame:
Note: Before reading this description, you need to understand IBM Director IPC.
The basic idea is to create a TWGGetAttributeCommand adn send it to the IBM Director Server. Note: the constructor for the TWGGetAttributeCommand will set the destination address.
Code to get the IP Addressses for a Managed Object would look something like this:
1 static ServiceNode sn; // IMPORTANT: do not create a new service node // for each command you send. 2 long object_id; . . . 3 TWGGetAttributeCommand getCmd = new TWGGetAttributeCommand(object_id, TWGManagedObjectConstants.ATTRIB_IP_ADDRS); try { // send the command to the server 5 returnCode = sn.SendCommand( getCmd ); 6 DataValue val = ((TWGGetAttributeCommand)cmd).getAttributeValue(oid, 7 TWGManagedObjectConstants.ATTRIB_IP_ADDRS); 8 if((val != null) && (val instanceof TWGStringArray)) { 9 TWGStringArray ipaddrs = (TWGStringArray)val; 10 String[] iplist = ipaddrs.getValue(); 11 if(iplist.length > 0) { /* If any addresses in list */ 12 String agentAddr = new IPAddress(iplist[0]); } } } catch( InterruptedException ix ) { TWGRas.error( TWGRas.EX0, "InterruptedException ", ix ); } catch( ServiceNodeClosedException sncx ) { TWGRas.error( TWGRas.EX0, "ServiceNodeClosedException ", sncx ); } catch( ServiceNodeException snx ) { TWGRas.error( TWGRas.EX0, "ServiceNodeException ", snx ); }
In the above code section:
Line 1
: to send a com.tivoli.twg.libs.Command, you need an instance of a com.tivoli.twg.libs.ServiceNode. It is critical that you not create a new ServiceNode for every command you send. Instead, create one an re-use it.
Line 3: Create the TWGGetAttributeCommand using th moid and the attribute that you want. Note that if you wanted to get several attributes, you could have passed an array of attribute IDs rather than sending several commands to the IBM Director Server.
Line 5: Send the Command to the IBM Director Server. This example uses the blocking call fro sending a command. It may be necessary to use the non-blocking call and create a CommandCompleteListener to process the command results. See the IPc description in the Programmer's Guide.
Line 6: TWGGetAttributeCommand has a convenience method getAttributeValue that you can use to make it easier to process the Command OutputParameters. Attributes are always in com.tivoli.twg.libs.DataValue objects.
Line 8 through 12: show how to process a DataValue. In this case the dataValue is a com.tivoli.twg.libs.TWGStringArray.
Note: Before reading this description, you need to understand IBM Director IPC.
The basic idea is this: