Custom Services Lab
Time Estimates for Completion
Create a custom service to store files in the database using the file system.
Description:
15 minutes
Lab exercise:
15 minutes
Description
Implement and configure a custom service. Custom services are user-defined services that help to extend the Creo Elements\Direct Model Manager infrastructure. The custom service in this example monitors a directory and stores all files in this directory under a specific folder. These files are removed from the directory only after they have been executed.
Lab Exercise
In this lab you will implement and configure a custom service to store files in the database using the file system.
The high-level steps for this lab are:
1. Implement the service class
2. Create a document to be used as the parent for the files
3. Configure the service
4. Run the service
5. Test the reliability of the service
6. Reconfigure the service
Step 1: Implement the service class
Implement a new com.acme.services.CheckInService class derived from the com.osm.services.AbstractPollingManagerService class.
* 
A sample implementation is available in the com.osm.services.samples.CheckInService class. Copy this class into the com.acme.services package.
Ensure that you change the Java package of your copy from com.osm.services.samples to com.acme.services.
The initialize reads the service-specific configuration parameters. A sample implementation follows:
@Override
public void initialize(final ServiceConfiguration configuration, final Controller controller, final int serviceId,
final ServiceLock lock) throws Exception {
super.initialize(configuration, controller, serviceId, lock);
this.directory = new File(configuration.getChildValue(DIRECTORY_TAG, null));
this.repositoryElid = configuration.getChildValue(REPOSITORY_ELID_TAG, null);
}
The ServiceConfiguration class allows access to any configuration parameter by specifying its XPath relative to <Service> element. You can add nested configuration parameters for the service.
* 
You must call initialize method of the super class to configure the AbstractPollingManagerService class.
The process method is called in every iteration of the worker function. The service checks for files in the directory that is specified in the configuration file and then includes the files in the element repositoryElid with ELID (Element ID).
Step 2: Create a document to be used as parent for the files
1. Log in to Creo Elements/Direct Model Manager and create a default document. For example, create a document named ‘File Repository'.
2. Note the Element ID of this document.
Step 3: Configure the service
1. Copy the ServiceControllerConfig.xml file to CustomServiceControllerConfig.xml file.
2. Add the following to the <Services> section of the CustomServiceControllerConfig.xml file.
<Service enabled="true" java_class="com.acme.services.CheckInService" name="CheckInService">
<Executable> CheckInService.exe</Executable>
<PollIntervalInSeconds>15</PollIntervalInSeconds>
<Directory> ... specify input directory here ... </Directory>
<RepositoryElid> ... specify document ELID here ...</RepositoryElid>
<DefaultUser> ... specify document owner here ... </DefaultUser>
</Service>
3. Specify information in the XML elements that you added in Step 2.
* 
You need not specify the user’s password. The service infrastructure allows you to log in with the user name.
Step 4: Run the service
Restart the Service Controller in the Windows Services Panel and add a file into the CheckIn directory. Open the Model Manager client and view the files included in the File Repository document.
Step 5: Test the service’s reliability
1. Open the Window’s Task Manager and click Processes panel.
2. Select and end the CheckInServices.exe process.
3. The Service Controller detects the unexpected shutdown of the service and restarts the service after a short while.
Step 6: Reconfigure the service
1. In the CustomServiceControllerConfig.xml file, change the polling interval to 60 seconds and restart the Service Controller.
2. Add a file in the directory specified in the XML file above. It will now take up to 60 seconds for the file to be processed.
Was this helpful?