example.remote.interface.demo/src/terra/harvest/bundle/demo/RemoteInterfaceOSGiDemo.java
public void runConfigAdminDemo() throws IOException
    {
        // The PID is the identifier for a configuration via the OSGi-provided ConfigurationAdmin service
        final String logWriterPid = "mil.dod.th.ose.logging.LogWriter";
        final String logWriterProp = "logLevel";
        
        //---------------------------------------------------------------------
        //              REQUEST THE CONFIGURATION INFO
        // Users may request configuration info to see which configurations are
        // present on an instance of controller software.
        //---------------------------------------------------------------------
        // Build the request
        final GetConfigurationInfoRequestData requestForInfo = GetConfigurationInfoRequestData.
                newBuilder().                                       // Start a new builder
                setFilter("(service.Pid=" + logWriterPid + ")").    // Get the LogWriter bundle
                setIncludeProperties(false).                        // Don't include configuration property information
                build();                                            // Finalize construction
        
        
        // Create a response handler using an anonymous class
        // The response handler can be null when appropriate
        final ResponseHandler infoRequestHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload,
                    final Message namespaceMsg, final Message dataMsg)
            {
                System.out.println(PRINT_TAG_CA 
                        + "The response to the GetConfigurationInfoRequest has a payload with data type");
                System.out.println(PRINT_TAG_CA + " '" + ((ConfigAdminNamespace)namespaceMsg).getType() + "'");

                // Get the data from the response
                System.out.println(PRINT_TAG_CA + "The configuration list: [" 
                        + ((GetConfigurationInfoResponseData)dataMsg).getConfigurationsList() + "]");
            }
        };
        
        // Queue the message to the other controller
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetConfigurationInfoRequest,
                requestForInfo).queue(this.m_TargetSystemID, EncryptType.NONE, infoRequestHandler);
        
        // The response is handled by configAdminEventHandler.handleEvent and by the ResponseHandler


        //---------------------------------------------------------------------
        //              UPDATE OR CREATE A REMOTE CONFIGURATION 
        // A remote configuration must be created before it can be used (such
        // as reading values from it). Typically, one would be pre-loaded on
        // the controller software. But in the situation that one is not, the
        // user can create one remotely using a SetPropertyRequest.
        //
        // To create a remote configuration, send a message setting any
        // parameter. This example creates a parameter called 'logLevel' of
        // type INT32. The parameter value is "2". The log levels are
        // 1: Error
        // 2: Warning
        // 3: Info
        // 4: Debug
        // Setting a log level gets all the levels above it. So, setting a log
        // level of '2' also includes '1'.
        //
        // A ConfigAdminMessageType.SetPropertyRequest creates the
        // configuration if a configuration does not exist; otherwise, it
        // updates the configuration. If a configuration does not already
        // exist, then a ConfigAdminMessageType.SetPropertyRequest must be the
        // first call to the remote system.
        //---------------------------------------------------------------------

        // Build a parameter to send
        final Multitype mtype = Multitype.
                newBuilder().                   // Start the builder
                setType(Type.INT32).            // Designate it as type INT32
                setInt32Value(2).               // Assign a value to the variable
                build();                        // Finalize construction

        //Build the property to be set
        final SimpleTypesMapEntry prop = SimpleTypesMapEntry.newBuilder().setKey(logWriterProp).setValue(mtype).build();
        
        // Build a message using the above payload
        final SetPropertyRequestData setPropertyRequest = SetPropertyRequestData.
                newBuilder().
                setPid(logWriterPid).
                addProperties(prop).
                build();
               
        
        // Create the response handler 
        final ResponseHandler setPropertyHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                // The response should be a non-null response with a namespace type Namespace.ConfigAdmin
                System.out.println(PRINT_TAG_CA + "Response to namespace is " + payload.getNamespace());

                // The message namespace should be of type ConfigAdminMessageType.SetPropertyResponse
                System.out.println(PRINT_TAG_CA + "Namespace response type is "
                        + ((ConfigAdminNamespace)namespaceMsg).getType());
            }
        };
        
        // Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.SetPropertyRequest,
                setPropertyRequest).queue(this.m_TargetSystemID, EncryptType.NONE, setPropertyHandler);

        // The response will be handled by configAdminEventHandler.handleEvent and by the remote handler above
        

        //---------------------------------------------------------------------
        //              REQUEST A PARAMETER
        // Request the value of a specific parameter belonging to a known
        // configuration from a specific remote controller software.
        // This example requests the current log level from the LogWriter.
        //---------------------------------------------------------------------
        // Build the request
        final GetPropertyRequestData requestProperty = GetPropertyRequestData.
                newBuilder().
                setPid(logWriterPid).
                setKey(logWriterProp).
                build();
        
        // Create the response handler 
        final ResponseHandler requestPropHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                // Get the type and value of the property
                // Getting the type is important because a property may be overridden by a different type of data.
                // For example, one analyst might remotely assign a parameter called "ID" parameter as a string, while
                // another analyst may habitually assign a parameter with the same name ("ID") as an integer value.

                // Get the parameter data type and value
                final Multitype value = ((GetPropertyResponseData)dataMsg).getValue();
                System.out.println(PRINT_TAG_CA + "The property type is " + value.getType());
                // Because this is a demo and we know the type is a String, we'll skip using any conditional logic
                System.out.println(PRINT_TAG_CA + "The value is " + value.getStringValue());
            }
        };

        // Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetPropertyRequest,
                requestProperty).queue(this.m_TargetSystemID, EncryptType.NONE, requestPropHandler);

        // The response will be handled by configAdminEventHandler.handleEvent and the above handler
        

        //---------------------------------------------------------------------
        //              REQUEST THE LIST OF PARAMETER KEYS
        // This is useful when you need to see what parameter keys are on the
        // remote device. If you use an invalid PID, a non-null response is
        // returned with an empty array of data.
        // Currently, the two keys in the configuration should be "logLevel"
        // and "service.pid". All configurations have a "service.pid" property,
        // equal to the value used in setPid (below).
        //---------------------------------------------------------------------
        // Build the request
        final GetPropertyKeysRequestData requestPropertyKeys = GetPropertyKeysRequestData
                .newBuilder()
                .setPid(logWriterPid)
                .build();
        
        // Develop the response handler 
        final ResponseHandler propKeysHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                final GetPropertyKeysResponseData keysData = (GetPropertyKeysResponseData)dataMsg;
                System.out.println(PRINT_TAG_CA + "Keys are " + keysData.getKeyList() + " with "
                        + keysData.getKeyCount() + " keys");
            }
        };
        
        // Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetPropertyKeysRequest,
                requestPropertyKeys).queue(this.m_TargetSystemID, EncryptType.NONE, propKeysHandler);

        // The response will be handled by configAdminEventHandler.handleEvent and the above handler

    }
/**
     * The ConfigurationAdmin shows how to manipulate properties on remote controller software.
     * @throws IOException 
     *      if an endpoint cannot be reached.
     */
The ConfigurationAdmin shows how to manipulate properties on remote controller software.
@throws IOException
if an endpoint cannot be reached.
The ConfigurationAdmin shows how to manipulate properties on remote controller software . @throws IOException if an endpoint cannot be reached .
public void runConfigAdminDemo() throws IOException
    {
        final String logWriterPid = "mil.dod.th.ose.logging.LogWriter";
        final String logWriterProp = "logLevel";
        final GetConfigurationInfoRequestData requestForInfo = GetConfigurationInfoRequestData.
                newBuilder().                                       
                setFilter("(service.Pid=" + logWriterPid + ")").    
                setIncludeProperties(false).                        
                build();                                            
        final ResponseHandler infoRequestHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload,
                    final Message namespaceMsg, final Message dataMsg)
            {
                System.out.println(PRINT_TAG_CA 
                        + "The response to the GetConfigurationInfoRequest has a payload with data type");
                System.out.println(PRINT_TAG_CA + " '" + ((ConfigAdminNamespace)namespaceMsg).getType() + "'");
                System.out.println(PRINT_TAG_CA + "The configuration list: [" 
                        + ((GetConfigurationInfoResponseData)dataMsg).getConfigurationsList() + "]");
            }
        };
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetConfigurationInfoRequest,
                requestForInfo).queue(this.m_TargetSystemID, EncryptType.NONE, infoRequestHandler);
         To create a remote configuration, send a message setting any
         parameter. This example creates a parameter called 'logLevel' of
         type INT32. The parameter value is "2". The log levels are
         1: Error
         2: Warning
         3: Info
         4: Debug
         Setting a log level gets all the levels above it. So, setting a log
         level of '2' also includes '1'.
         A ConfigAdminMessageType.SetPropertyRequest creates the
         configuration if a configuration does not exist; otherwise, it
         updates the configuration. If a configuration does not already
         exist, then a ConfigAdminMessageType.SetPropertyRequest must be the
         first call to the remote system.
         Build a parameter to send
        final Multitype mtype = Multitype.
                newBuilder().                    Start the builder
                setType(Type.INT32).             Designate it as type INT32
                setInt32Value(2).                Assign a value to the variable
                build();                        
        Build the property to be set
        final SimpleTypesMapEntry prop = SimpleTypesMapEntry.newBuilder().setKey(logWriterProp).setValue(mtype).build();
         Build a message using the above payload
        final SetPropertyRequestData setPropertyRequest = SetPropertyRequestData.
                newBuilder().
                setPid(logWriterPid).
                addProperties(prop).
                build();
         Create the response handler 
        final ResponseHandler setPropertyHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                 The response should be a non-null response with a namespace type Namespace.ConfigAdmin
                System.out.println(PRINT_TAG_CA + "Response to namespace is " + payload.getNamespace());
                 The message namespace should be of type ConfigAdminMessageType.SetPropertyResponse
                System.out.println(PRINT_TAG_CA + "Namespace response type is "
                        + ((ConfigAdminNamespace)namespaceMsg).getType());
            }
        };
         Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.SetPropertyRequest,
                setPropertyRequest).queue(this.m_TargetSystemID, EncryptType.NONE, setPropertyHandler);
         The response will be handled by configAdminEventHandler.handleEvent and by the remote handler above
                      REQUEST A PARAMETER
         Request the value of a specific parameter belonging to a known
         configuration from a specific remote controller software.
         This example requests the current log level from the LogWriter.
        final GetPropertyRequestData requestProperty = GetPropertyRequestData.
                newBuilder().
                setPid(logWriterPid).
                setKey(logWriterProp).
                build();
         Create the response handler 
        final ResponseHandler requestPropHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                 Get the type and value of the property
                 Getting the type is important because a property may be overridden by a different type of data.
                 For example, one analyst might remotely assign a parameter called "ID" parameter as a string, while
                 another analyst may habitually assign a parameter with the same name ("ID") as an integer value.
                 Get the parameter data type and value
                final Multitype value = ((GetPropertyResponseData)dataMsg).getValue();
                System.out.println(PRINT_TAG_CA + "The property type is " + value.getType());
                 Because this is a demo and we know the type is a String, we'll skip using any conditional logic
                System.out.println(PRINT_TAG_CA + "The value is " + value.getStringValue());
            }
        };
         Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetPropertyRequest,
                requestProperty).queue(this.m_TargetSystemID, EncryptType.NONE, requestPropHandler);
         The response will be handled by configAdminEventHandler.handleEvent and the above handler
                      REQUEST THE LIST OF PARAMETER KEYS
         This is useful when you need to see what parameter keys are on the
         remote device. If you use an invalid PID, a non-null response is
         returned with an empty array of data.
         Currently, the two keys in the configuration should be "logLevel"
         and "service.pid". All configurations have a "service.pid" property,
         equal to the value used in setPid (below).
        final GetPropertyKeysRequestData requestPropertyKeys = GetPropertyKeysRequestData
                .newBuilder()
                .setPid(logWriterPid)
                .build();
         Develop the response handler 
        final ResponseHandler propKeysHandler = new ResponseHandler()
        {
            @Override
            public void handleResponse(final TerraHarvestMessage msg, final TerraHarvestPayload payload, 
                    final Message namespaceMsg, final Message dataMsg)
            {
                final GetPropertyKeysResponseData keysData = (GetPropertyKeysResponseData)dataMsg;
                System.out.println(PRINT_TAG_CA + "Keys are " + keysData.getKeyList() + " with "
                        + keysData.getKeyCount() + " keys");
            }
        };
         Construct and send a TerraHarvestMessage
        this.m_MessageFactory.createConfigAdminMessage(ConfigAdminMessageType.GetPropertyKeysRequest,
                requestPropertyKeys).queue(this.m_TargetSystemID, EncryptType.NONE, propKeysHandler);
         The response will be handled by configAdminEventHandler.handleEvent and the above handler
    }
public void runConfigAdminDemo ( ) throws IOException { final String logWriterPid = "mil.dod.th.ose.logging.LogWriter" ; final String logWriterProp = "logLevel" ; final GetConfigurationInfoRequestData requestForInfo = GetConfigurationInfoRequestData . newBuilder ( ) . setFilter ( "(service.Pid=" + logWriterPid + ")" ) . setIncludeProperties ( false ) . build ( ) ; final ResponseHandler infoRequestHandler = new ResponseHandler ( ) { @ Override public void handleResponse ( final TerraHarvestMessage msg , final TerraHarvestPayload payload , final Message namespaceMsg , final Message dataMsg ) { System . out . println ( PRINT_TAG_CA + "The response to the GetConfigurationInfoRequest has a payload with data type" ) ; System . out . println ( PRINT_TAG_CA + " '" + ( ( ConfigAdminNamespace ) namespaceMsg ) . getType ( ) + "'" ) ; System . out . println ( PRINT_TAG_CA + "The configuration list: [" + ( ( GetConfigurationInfoResponseData ) dataMsg ) . getConfigurationsList ( ) + "]" ) ; } } ; this . m_MessageFactory . createConfigAdminMessage ( ConfigAdminMessageType . GetConfigurationInfoRequest , requestForInfo ) . queue ( this . m_TargetSystemID , EncryptType . NONE , infoRequestHandler ) ; final Multitype mtype = Multitype . newBuilder ( ) . setType ( Type . INT32 ) . setInt32Value ( 2 ) . build ( ) ; final SimpleTypesMapEntry prop = SimpleTypesMapEntry . newBuilder ( ) . setKey ( logWriterProp ) . setValue ( mtype ) . build ( ) ; final SetPropertyRequestData setPropertyRequest = SetPropertyRequestData . newBuilder ( ) . setPid ( logWriterPid ) . addProperties ( prop ) . build ( ) ; final ResponseHandler setPropertyHandler = new ResponseHandler ( ) { @ Override public void handleResponse ( final TerraHarvestMessage msg , final TerraHarvestPayload payload , final Message namespaceMsg , final Message dataMsg ) { System . out . println ( PRINT_TAG_CA + "Response to namespace is " + payload . getNamespace ( ) ) ; System . out . println ( PRINT_TAG_CA + "Namespace response type is " + ( ( ConfigAdminNamespace ) namespaceMsg ) . getType ( ) ) ; } } ; this . m_MessageFactory . createConfigAdminMessage ( ConfigAdminMessageType . SetPropertyRequest , setPropertyRequest ) . queue ( this . m_TargetSystemID , EncryptType . NONE , setPropertyHandler ) ; final GetPropertyRequestData requestProperty = GetPropertyRequestData . newBuilder ( ) . setPid ( logWriterPid ) . setKey ( logWriterProp ) . build ( ) ; final ResponseHandler requestPropHandler = new ResponseHandler ( ) { @ Override public void handleResponse ( final TerraHarvestMessage msg , final TerraHarvestPayload payload , final Message namespaceMsg , final Message dataMsg ) { final Multitype value = ( ( GetPropertyResponseData ) dataMsg ) . getValue ( ) ; System . out . println ( PRINT_TAG_CA + "The property type is " + value . getType ( ) ) ; System . out . println ( PRINT_TAG_CA + "The value is " + value . getStringValue ( ) ) ; } } ; this . m_MessageFactory . createConfigAdminMessage ( ConfigAdminMessageType . GetPropertyRequest , requestProperty ) . queue ( this . m_TargetSystemID , EncryptType . NONE , requestPropHandler ) ; final GetPropertyKeysRequestData requestPropertyKeys = GetPropertyKeysRequestData . newBuilder ( ) . setPid ( logWriterPid ) . build ( ) ; final ResponseHandler propKeysHandler = new ResponseHandler ( ) { @ Override public void handleResponse ( final TerraHarvestMessage msg , final TerraHarvestPayload payload , final Message namespaceMsg , final Message dataMsg ) { final GetPropertyKeysResponseData keysData = ( GetPropertyKeysResponseData ) dataMsg ; System . out . println ( PRINT_TAG_CA + "Keys are " + keysData . getKeyList ( ) + " with " + keysData . getKeyCount ( ) + " keys" ) ; } } ; this . m_MessageFactory . createConfigAdminMessage ( ConfigAdminMessageType . GetPropertyKeysRequest , requestPropertyKeys ) . queue ( this . m_TargetSystemID , EncryptType . NONE , propKeysHandler ) ; }
The ConfigurationAdmin shows how to manipulate properties on remote controller software.
The ConfigurationAdmin shows how to manipulate properties on remote controller software .
// The PID is the identifier for a configuration via the OSGi-provided ConfigurationAdmin service //--------------------------------------------------------------------- //              REQUEST THE CONFIGURATION INFO // Users may request configuration info to see which configurations are // present on an instance of controller software. //--------------------------------------------------------------------- // Build the request // Start a new builder // Get the LogWriter bundle // Don't include configuration property information // Finalize construction // Create a response handler using an anonymous class // The response handler can be null when appropriate // Get the data from the response // Queue the message to the other controller // The response is handled by configAdminEventHandler.handleEvent and by the ResponseHandler //--------------------------------------------------------------------- //              UPDATE OR CREATE A REMOTE CONFIGURATION  // A remote configuration must be created before it can be used (such // as reading values from it). Typically, one would be pre-loaded on // the controller software. But in the situation that one is not, the // user can create one remotely using a SetPropertyRequest. // // To create a remote configuration, send a message setting any // parameter. This example creates a parameter called 'logLevel' of // type INT32. The parameter value is "2". The log levels are // 1: Error // 2: Warning // 3: Info // 4: Debug // Setting a log level gets all the levels above it. So, setting a log // level of '2' also includes '1'. // // A ConfigAdminMessageType.SetPropertyRequest creates the // configuration if a configuration does not exist; otherwise, it // updates the configuration. If a configuration does not already // exist, then a ConfigAdminMessageType.SetPropertyRequest must be the // first call to the remote system. //--------------------------------------------------------------------- // Build a parameter to send // Start the builder // Designate it as type INT32 // Assign a value to the variable // Finalize construction //Build the property to be set // Build a message using the above payload // Create the response handler  // The response should be a non-null response with a namespace type Namespace.ConfigAdmin // The message namespace should be of type ConfigAdminMessageType.SetPropertyResponse // Construct and send a TerraHarvestMessage // The response will be handled by configAdminEventHandler.handleEvent and by the remote handler above //--------------------------------------------------------------------- //              REQUEST A PARAMETER // Request the value of a specific parameter belonging to a known // configuration from a specific remote controller software. // This example requests the current log level from the LogWriter. //--------------------------------------------------------------------- // Build the request // Create the response handler  // Get the type and value of the property // Getting the type is important because a property may be overridden by a different type of data. // For example, one analyst might remotely assign a parameter called "ID" parameter as a string, while // another analyst may habitually assign a parameter with the same name ("ID") as an integer value. // Get the parameter data type and value // Because this is a demo and we know the type is a String, we'll skip using any conditional logic // Construct and send a TerraHarvestMessage // The response will be handled by configAdminEventHandler.handleEvent and the above handler //--------------------------------------------------------------------- //              REQUEST THE LIST OF PARAMETER KEYS // This is useful when you need to see what parameter keys are on the // remote device. If you use an invalid PID, a non-null response is // returned with an empty array of data. // Currently, the two keys in the configuration should be "logLevel" // and "service.pid". All configurations have a "service.pid" property, // equal to the value used in setPid (below). //--------------------------------------------------------------------- // Build the request // Develop the response handler  // Construct and send a TerraHarvestMessage // The response will be handled by configAdminEventHandler.handleEvent and the above handler