Sample Code Sample Code: Configure Services with Properties


# Set the architecture property when adding a service
smcconf repository add bean MyService.jar -P ARCH=`uname -p`

# Or change a property after the service is already installed
smcconf repository add property com.mycompany.myproduct.MyServiceImpl -P PORT=8080

At runtime, the service retrieves the properties through the ServiceContext that is given to the service via the method setContext():

import com.sun.management.viper.VService;
public class MyServiceImpl extends VService implements MyService {
    ...
    public void init() {
        super.init();
        ServiceContext context = super.getContext();
        String arch = context.getRegistryProperty("ARCH");
        String port = context.getRegistryProperty("PORT")
        ...
    }