The Creation Service is a framework specific component (so called a pseudo component) that allows one component to instantiate other components. This service completely encapsulates the component instantiation mechanism thus freeing the component developer from low-level, framework-specific details of instantiation related issues.
The service exports one provides port (called CreationService) with two functions. The createInstance function takes a url describing the component to be created, the instantiation mechanism to be used, the host on which the component is to be instantiated, and returns a ComponentID that act as a reference for the created component. The function also takes an environment object as a second parameter that can be used to specify additional information to the creation service. This information may include full pathname of the component executable, instantiation mechanism specific information, other information that needs to be passed on to the instantiated component, such as command line parameters, and process environment variables like LD_LIBRARY_PATH, PATH, stdin, stdout and stderr.
A component can be created in the same address space environment of the creating component or it may be instantiated in a different address space on a different host.
The deleteInstance function destroys the component specified by a given ComponentID.
The semantics of method calls is based on the Corba specifications:
typedef sequencestringSeq; typedef sequence PortInfoSeq; // Note: If we switch to SIDL to specify interfaces, then we could use SIDL // arrays instead of Corba IDL sequences
valuetype EnvObj {
public string get (in string name);
public void put (in string name, in string val);
public stringSeq getAllNames ();
};
valuetype ComponentID {
public PortInfoSeq getProvidesPorts();
public PortInfoSeq getUsesPorts();
};
// Provides Ports
interface CreationService: CCAPort {
public ComponentID createInstance(in string url, inout EnvObj env)
raises (InstantiateException);
public void deleteInstance(in ComponentID id)
raises (InstantiateException);
};
class EnvObj {
public:
virtual char* get (char* name) = 0;
virtual void put (char* name, char* val) = 0;
virtual void getAllNames (char ** names, int &len) = 0;
};
class ComponentID {
public:
virtual PortInfo** getProvidesPorts(int &len) = 0;
virtual PortInfo** getUsesPorts(int &len) = 0;
};
class CreationService: public Port {
public:
virtual ComponentID* createInstance(char* url, EnvObj* env)
throw (InstantiateException) = 0;
virtual void deleteInstance(ComponentID* id)
throw (InstantiateException) = 0;
};
interface EnvObj {
public String get (String name);
public void put (String name, String val);
public String [] getAllNames ();
}
interface ComponentID {
public PortInfo[] getProvidesPorts();
public PortInfo[] getUsesPorts();
}
interface CreationService: CCAPort {
public ComponentID createInstance(String url, EnvObj env)
throws InstantiateException;
public void deleteInstance(ComponentID id)
throws InstantiateException;
}
string get (in string name);
void put (in string name, in string val);
stringSeq getAllNames ();
ComponentID createInstance(in String url, inout EnvObj env)
raises (InstantiateException);
url examples:
gram:/rainier.extreme.indiana.edu/components/cat/cca/lsa/NewSystem
local://components/cat/cca/lsa/SpLib
in-process://components/cat/cca/LoadChecker
void deleteInstance(in ComponentID id) raises (InstantiateException);
// Use the component's services object to get a uses port connected
// to the creation service.
CreationService creationPort =
(CreationService) services.getPort("CreationService");
// make the component creation url: this example uses
// 1. Globus "gram" as the creation mechanism
// 2. "bread.extreme.indiana.edu" as the target machine
// 3. The component to be created is: "/components/cat/cca/NewSystem". This is
// the scoped name of the component as maintained by the information
// directory service (IDS)
String url = "gram:/bread.extreme.indiana.edu/components/cat/cca/NewSystem";
// Create an environment object to be passed to the createInstance call
EnvObj env = new EnvObj();
// where to find the executable
env.put ("executable", "/u/ccat/components/bin/NewSystem.exe");
// Specify environment variables for the executable
env.put ("stdin", "/u/ccat/components/src/NewSystem/input_file");
env.put ("stdout", "/dev/null");
env.put ("stderr", "/u/ccat/components/src/NewSystem/error_file");
// create component
try {
ComponentID cid = creationPort.createInstance(url, env);
} catch (InstantiateException excep) {
System.out.println ("Error, cannot instantiate component");
}
...
// delete the component instance
try {
creationPort.deleteInstance (cid);
} catch (InstantiateException excep) {
System.out.println ("Error, cannot destroy component");
}
// Release the creation service uses port once you are done with using it
services.releasePort("CreationService");
// Use the component's services object to get a uses port connected
// to the creation service.
CreationService* creationPort =
(CreationService*) services->getPort("CreationService");
// make the component creation url: this example uses
// 1. in-process as the creation mechanism, it will create the component in the
// same address space as that of the creator
// 2. the target machine portion of the url is empty
// 3. The component to be created is: "/components/cat/cca/SpLib". This is
// the scoped name of the component as maintained by the information
// directory service (IDS)
char* url = "in-process://components/cat/cca/SpLib";
// Get an environment object from the IDS info object that describes the
// component. Assume that we have already got the info object through operations
// on the IDS. The getEnvObj function will fill up the returned environment
// object with name - value pairs appropriate for that component
EnvObj* env = infoObject->getEnvObj();
// create component
try {
ComponentID* cid = creationPort->createInstance(url, env);
} catch (InstantiateException& excep) {
cerr << "Error, cannot instantiate component\n";
}
...
// Delete the component instance. This will NOT delete the cid pointer.
try {
creationPort->deleteInstance (cid);
} catch (InstantiateException& excep) {
cerr << "Error, cannot destroy component\n";
}
// Release the creation service uses port once you are done with using it.
services->releasePort("CreationService");
// After you are done with using any pointers returned by the framework
// services, delete them.
delete creationPort;
delete cid;
delete env;
Last modified: Sat Oct 23 00:31:41 EST 1999