mil.dod.th.ose.remote/src/mil/dod/th/ose/remote/asset/AssetMessageService.java
private Message executeCommand(final AssetNamespace message, final TerraHarvestMessage request, 
            final RemoteChannel channel) throws InvalidProtocolBufferException 
    {    
        final ExecuteCommandRequestData executeCommandRequestData = 
              ExecuteCommandRequestData.parseFrom(message.getData()); 
        final Asset asset = m_AssetDirectoryService.getAssetByUuid(
                SharedMessageUtils.convertProtoUUIDtoUUID(executeCommandRequestData.getUuid())); 
        
        final CommandTypeEnum executeCommandEnum = 
                CommandTypeEnumConverter.convertProtoEnumToJava(executeCommandRequestData.getCommandType());
        
        final CommandResponseEnum responseType = 
                m_CommandConverterUtility.getResponseTypeFromCommandType(executeCommandEnum);
        
        try
        {
            final Command command = m_CommandConverterUtility.
                    getJavaCommandType(executeCommandRequestData.getCommand().toByteArray(), executeCommandEnum);
            
            //start a runnable instance to execute the command.
            m_CommandExecutorService.execute(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        final Response responseJaxb = asset.executeCommand(command);
                        
                        final Message responseProto = m_Converter.convertToProto(responseJaxb);
                        final ExecuteCommandResponseData responseData = ExecuteCommandResponseData.newBuilder().
                                        setUuid(SharedMessageUtils.convertUUIDToProtoUUID(asset.getUuid())).
                                        setResponseType(CommandResponseEnumConverter
                                                .convertJavaEnumToProto(responseType)).
                                        setResponse(responseProto.toByteString()).build();
                        m_MessageFactory.createAssetResponseMessage(request, AssetMessageType.ExecuteCommandResponse, 
                                responseData).queue(channel);
                    }
                    catch (final CommandExecutionException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Unable to execute command %s for asset %s", 
                                        executeCommandEnum, asset.getName())).queue(channel);
                    }
                    catch (final ObjectConverterException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Unable to convert command response to proto message for " 
                                        + "asset %s when executing command %s",
                                        asset.getName(), executeCommandEnum)).queue(channel);
                    }
                    catch (final InterruptedException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Execution of command %s for asset %s was interrupted.",
                                        executeCommandEnum, asset.getName())).queue(channel);
                    }
                    catch (final Exception exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, String.format(
                                "An exception occurred for asset %s while processing command %s.", 
                                asset.getName(), executeCommandEnum)).queue(channel);
                    }
                }
            });
        }
        catch (final ObjectConverterException exception)
        {
            m_MessageFactory.createBaseErrorResponse(request, exception, String.format(
                    "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s.", 
                    asset.getName(), executeCommandEnum)).queue(channel);
        }
        
        return executeCommandRequestData;
    }
/**
     * Method responsible for handling a request for an asset to execute a specific command per specifications
     * contained in the request message.  
     * @param message
     *      message containing the UUID of the asset that a command is executed on
     * @param request
     *      entire remote message for the request
     * @param channel
     *      the channel that was used to send the request
     * @return
     *      the data message for this request
     * @throws InvalidProtocolBufferException 
     *      thrown when a protocol message being parsed is invalid 
     */
Method responsible for handling a request for an asset to execute a specific command per specifications
contained in the request message.
Method responsible for handling a request for an asset to execute a specific command per specifications contained in the request message .
private Message executeCommand(final AssetNamespace message, final TerraHarvestMessage request, 
            final RemoteChannel channel) throws InvalidProtocolBufferException 
    {    
        final ExecuteCommandRequestData executeCommandRequestData = 
              ExecuteCommandRequestData.parseFrom(message.getData()); 
        final Asset asset = m_AssetDirectoryService.getAssetByUuid(
                SharedMessageUtils.convertProtoUUIDtoUUID(executeCommandRequestData.getUuid())); 
        final CommandTypeEnum executeCommandEnum = 
                CommandTypeEnumConverter.convertProtoEnumToJava(executeCommandRequestData.getCommandType());
        final CommandResponseEnum responseType = 
                m_CommandConverterUtility.getResponseTypeFromCommandType(executeCommandEnum);
        try
        {
            final Command command = m_CommandConverterUtility.
                    getJavaCommandType(executeCommandRequestData.getCommand().toByteArray(), executeCommandEnum);
            m_CommandExecutorService.execute(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        final Response responseJaxb = asset.executeCommand(command);
                        final Message responseProto = m_Converter.convertToProto(responseJaxb);
                        final ExecuteCommandResponseData responseData = ExecuteCommandResponseData.newBuilder().
                                        setUuid(SharedMessageUtils.convertUUIDToProtoUUID(asset.getUuid())).
                                        setResponseType(CommandResponseEnumConverter
                                                .convertJavaEnumToProto(responseType)).
                                        setResponse(responseProto.toByteString()).build();
                        m_MessageFactory.createAssetResponseMessage(request, AssetMessageType.ExecuteCommandResponse, 
                                responseData).queue(channel);
                    }
                    catch (final CommandExecutionException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Unable to execute command %s for asset %s", 
                                        executeCommandEnum, asset.getName())).queue(channel);
                    }
                    catch (final ObjectConverterException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Unable to convert command response to proto message for " 
                                        + "asset %s when executing command %s",
                                        asset.getName(), executeCommandEnum)).queue(channel);
                    }
                    catch (final InterruptedException exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, 
                                String.format("Execution of command %s for asset %s was interrupted.",
                                        executeCommandEnum, asset.getName())).queue(channel);
                    }
                    catch (final Exception exception)
                    {
                        m_MessageFactory.createBaseErrorResponse(request, exception, String.format(
                                "An exception occurred for asset %s while processing command %s.", 
                                asset.getName(), executeCommandEnum)).queue(channel);
                    }
                }
            });
        }
        catch (final ObjectConverterException exception)
        {
            m_MessageFactory.createBaseErrorResponse(request, exception, String.format(
                    "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s.", 
                    asset.getName(), executeCommandEnum)).queue(channel);
        }
        return executeCommandRequestData;
    }
private Message executeCommand ( final AssetNamespace message , final TerraHarvestMessage request , final RemoteChannel channel ) throws InvalidProtocolBufferException { final ExecuteCommandRequestData executeCommandRequestData = ExecuteCommandRequestData . parseFrom ( message . getData ( ) ) ; final Asset asset = m_AssetDirectoryService . getAssetByUuid ( SharedMessageUtils . convertProtoUUIDtoUUID ( executeCommandRequestData . getUuid ( ) ) ) ; final CommandTypeEnum executeCommandEnum = CommandTypeEnumConverter . convertProtoEnumToJava ( executeCommandRequestData . getCommandType ( ) ) ; final CommandResponseEnum responseType = m_CommandConverterUtility . getResponseTypeFromCommandType ( executeCommandEnum ) ; try { final Command command = m_CommandConverterUtility . getJavaCommandType ( executeCommandRequestData . getCommand ( ) . toByteArray ( ) , executeCommandEnum ) ; m_CommandExecutorService . execute ( new Runnable ( ) { @ Override public void run ( ) { try { final Response responseJaxb = asset . executeCommand ( command ) ; final Message responseProto = m_Converter . convertToProto ( responseJaxb ) ; final ExecuteCommandResponseData responseData = ExecuteCommandResponseData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( asset . getUuid ( ) ) ) . setResponseType ( CommandResponseEnumConverter . convertJavaEnumToProto ( responseType ) ) . setResponse ( responseProto . toByteString ( ) ) . build ( ) ; m_MessageFactory . createAssetResponseMessage ( request , AssetMessageType . ExecuteCommandResponse , responseData ) . queue ( channel ) ; } catch ( final CommandExecutionException exception ) { m_MessageFactory . createBaseErrorResponse ( request , exception , String . format ( "Unable to execute command %s for asset %s" , executeCommandEnum , asset . getName ( ) ) ) . queue ( channel ) ; } catch ( final ObjectConverterException exception ) { m_MessageFactory . createBaseErrorResponse ( request , exception , String . format ( "Unable to convert command response to proto message for " + "asset %s when executing command %s" , asset . getName ( ) , executeCommandEnum ) ) . queue ( channel ) ; } catch ( final InterruptedException exception ) { m_MessageFactory . createBaseErrorResponse ( request , exception , String . format ( "Execution of command %s for asset %s was interrupted." , executeCommandEnum , asset . getName ( ) ) ) . queue ( channel ) ; } catch ( final Exception exception ) { m_MessageFactory . createBaseErrorResponse ( request , exception , String . format ( "An exception occurred for asset %s while processing command %s." , asset . getName ( ) , executeCommandEnum ) ) . queue ( channel ) ; } } } ) ; } catch ( final ObjectConverterException exception ) { m_MessageFactory . createBaseErrorResponse ( request , exception , String . format ( "Unable to retrieve java command from execute request for asset %s. Cannot execute command %s." , asset . getName ( ) , executeCommandEnum ) ) . queue ( channel ) ; } return executeCommandRequestData ; }
Method responsible for handling a request for an asset to execute a specific command per specifications
 contained in the request message.
Method responsible for handling a request for an asset to execute a specific command per specifications contained in the request message .
//start a runnable instance to execute the command.