Package net.jxta.endpoint

Examples of net.jxta.endpoint.StringMessageElement


        } catch (Exception ex) {}
       
        long sendStartTime = state.getSendStartTime();
        //String data = "Message #" + i;
        msg.addMessageElement(MESSAGE_MODE,
                              new StringMessageElement(MESSAGE_MODE,
                                                       mode,
                                                       null));
        if(mode != null && mode.equalsIgnoreCase(BULK_MESSAGE_MODE)) {
            msg.addMessageElement(BULK_MESSAGE_MODE,
                    new StringMessageElement(BULK_MESSAGE_MODE,
                                             "BULK",
                                             null));
        }
        msg.addMessageElement(MESSAGE_ID,
                              new StringMessageElement(MESSAGE_ID,
                                                       id,
                                                       null));
        msg.addMessageElement(MESSAGE_ID,
                              new StringMessageElement(MESSAGE_ID,
                                                       id,
                                                       null));
        msg.addMessageElement(MESSAGE_APPID,
                              new StringMessageElement(MESSAGE_APPID,
                                                       appid,
                                                       null));
        msg.addMessageElement(MESSAGE_VERSION,
                              new StringMessageElement(MESSAGE_VERSION,
                                                       version.toString(),
                                                       null));        
        String theCommand = command;
        if(isResponse) {
            theCommand = RETURN_MSG_COMMAND;
        }
        msg.addMessageElement(MESSAGE_COMMAND,
                              new StringMessageElement(MESSAGE_COMMAND,
                                                       theCommand,
                                                       null));       
        msg.addMessageElement(MESSAGE_LAST_ACCESS,
                              new StringMessageElement(MESSAGE_LAST_ACCESS,
                                                       lastAccess.toString(),
                                                       null));
        msg.addMessageElement(MESSAGE_MAX_INACTIVE,
                              new StringMessageElement(MESSAGE_MAX_INACTIVE,
                                                       maxInactive.toString(),
                                                       null));
        if(extraParam != null) {
            msg.addMessageElement(MESSAGE_EXTRA_PARAM,
                              new StringMessageElement(MESSAGE_EXTRA_PARAM,
                                                       extraParam,
                                                       null));
        }
        if(queryResult != null) {
            msg.addMessageElement(MESSAGE_QUERY_RESULT,
                                  new StringMessageElement(MESSAGE_QUERY_RESULT,
                                                           queryResult.toString(),
                                                           null));
        }
        if(instanceName != null) {
            msg.addMessageElement(MESSAGE_INSTANCE_NAME,
                              new StringMessageElement(MESSAGE_INSTANCE_NAME,
                                                       instanceName,
                                                       null));
        }
        if(data != null) {
            msg.addMessageElement(MESSAGE_DATA,
                              new ByteArrayMessageElement(MESSAGE_DATA,
                                                       null,
                                                       data,
                                                       null));
        }
        if(trunkData != null) {
            msg.addMessageElement(MESSAGE_TRUNK_DATA,
                              new ByteArrayMessageElement(MESSAGE_TRUNK_DATA,
                                                       null,
                                                       trunkData,
                                                       null));
        }
        if(containerExtraParamData != null) {
            msg.addMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
                              new ByteArrayMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
                                                       null,
                                                       containerExtraParamData,
                                                       null));
        }
        if(propertiesState != null) {
            msg.addMessageElement(MESSAGE_PROPERTIES_DATA,
                              new ByteArrayMessageElement(MESSAGE_PROPERTIES_DATA,
                                                       null,
                                                       propertiesState,
                                                       null));
        }       
        //is ack required
        String ackRequiredString = "N";
        if(ackRequired) {
            ackRequiredString = "Y";
        }
        msg.addMessageElement(MESSAGE_ACK_REQUIRED,
                              new StringMessageElement(MESSAGE_ACK_REQUIRED,
                                                       ackRequiredString,
                                                       null));
        //a property not sent but available for quick-ack case
        msg.setMessageProperty(MESSAGE_ACK_REQUIRED, ackRequiredString);
        List ackIdsList = state.getAckIdsList();
        if(state.getAckIdsList() != null) {
            msg.setMessageProperty(MESSAGE_ACK_LIST_PROPERTY, ackIdsList);
        }
        //send start time for measurements
        if(sendStartTime != -1) {
            msg.addMessageElement(MESSAGE_SEND_START_TIME,
                                  new StringMessageElement(MESSAGE_SEND_START_TIME,
                                                           "" + sendStartTime,
                                                           null));
            msg.setMessageProperty(MESSAGE_SEND_START_TIME, ""+sendStartTime);
        }


        msg.addMessageElement(MESSAGE_BIDI_STYLE,
                              new StringMessageElement(MESSAGE_BIDI_STYLE,
                                                       "" + state.isBiDiStyle(),
                                                       null));
       
        if(_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationState:createMessage:Sending Message id:" + id + " appid:" + appid + " command:" + command);
View Full Code Here


     */    
    public static Message createBulkMessage(long msgID, int totalStates, byte[] data, boolean ackRequired) {
        Message msg = new Message();
       
        msg.addMessageElement(BULK_MESSAGE_MODE,
                new StringMessageElement(BULK_MESSAGE_MODE,
                                         "BULK",
                                         null));
       
        msg.addMessageElement(BULK_MESSAGE_ID,
                new StringMessageElement(BULK_MESSAGE_ID,
                                         ""+msgID,
                                         null));
       
        msg.setMessageProperty(BULK_MESSAGE_ID, ""+msgID);
       

        if (data != null) {
            msg.addMessageElement(MESSAGE_TOTAL_STATES,
                    new StringMessageElement(MESSAGE_TOTAL_STATES,
                                             ""+totalStates,
                                             null));
           
            msg.addMessageElement(MESSAGE_DATA,
                              new ByteArrayMessageElement(MESSAGE_DATA,
                                                       null,
                                                       data,
                                                       null));
        }
       
        //is ack required
        String ackRequiredString = "N";
        if(ackRequired) {
            ackRequiredString = "Y";
        }
        msg.addMessageElement(MESSAGE_ACK_REQUIRED,
                              new StringMessageElement(MESSAGE_ACK_REQUIRED,
                                                       ackRequiredString,
                                                       null));
       
        //send start time for measurements
        long sendStartTime = System.currentTimeMillis();
        msg.addMessageElement(MESSAGE_SEND_START_TIME,
                              new StringMessageElement(MESSAGE_SEND_START_TIME,
                                                       "" + sendStartTime,
                                                       null));
        msg.setMessageProperty(MESSAGE_SEND_START_TIME, ""+sendStartTime);

        if(_logger.isLoggable(Level.INFO)) {
View Full Code Here

            msg.getMessageElement(MESSAGE_MODE, MESSAGE_MODE);
        if(modeMsgElement != null) {
            mode = modeMsgElement.toString();
        }       
        ackMsg.addMessageElement(MESSAGE_MODE,
                              new StringMessageElement(MESSAGE_MODE,
                                                       mode,
                                                       null));        
        //echo the id
        MessageElement idMsgElement =
        msg.getMessageElement(MESSAGE_ID, MESSAGE_ID);
        String id = idMsgElement.toString();
        ackMsg.addMessageElement(MESSAGE_ID,
                              new StringMessageElement(MESSAGE_ID,
                                                       id,
                                                       null));
        //echo the appid
        MessageElement appidMsgElement =
            msg.getMessageElement(MESSAGE_APPID, MESSAGE_APPID);
        String appid = appidMsgElement.toString();
        ackMsg.addMessageElement(MESSAGE_APPID,
                              new StringMessageElement(MESSAGE_APPID,
                                                       appid,
                                                       null));
        //********** test begin**********************
        //get the current command
        MessageElement commandMsgElement =
            msg.getMessageElement(MESSAGE_COMMAND, MESSAGE_COMMAND);
        String previousCommand = commandMsgElement.toString();
        String theCommand = RETURN_MSG_COMMAND;
        if(previousCommand.equals(ReplicationState.HC_COMMAND)) {
            theCommand = RETURN_HC_MSG_COMMAND;
        }
        //this is a return command
        /* FIXME replace next line with above - need to test
        String theCommand = RETURN_MSG_COMMAND;
         */       
        //********** test end  **********************
       

        ackMsg.addMessageElement(MESSAGE_COMMAND,
                              new StringMessageElement(MESSAGE_COMMAND,
                                                       theCommand,
                                                       null));

        return ackMsg;
    }
View Full Code Here

            msg.getMessageElement(MESSAGE_MODE, MESSAGE_MODE);
        if(modeMsgElement != null) {
            mode = modeMsgElement.toString();
        }       
        ackMsg.addMessageElement(MESSAGE_MODE,
                              new StringMessageElement(MESSAGE_MODE,
                                                       mode,
                                                       null));
       
        ackMsg.addMessageElement(BULK_MESSAGE_MODE,
                new StringMessageElement(BULK_MESSAGE_MODE,
                                         "BULK",
                                         null));
       
        //echo the id
        MessageElement idMsgElement =
        msg.getMessageElement(MESSAGE_ID, MESSAGE_ID);
        String id = idMsgElement.toString();
        ackMsg.addMessageElement(MESSAGE_ID,
                              new StringMessageElement(MESSAGE_ID,
                                                       id,
                                                       null));
        //echo the appid
        MessageElement appidMsgElement =
            msg.getMessageElement(MESSAGE_APPID, MESSAGE_APPID);
        String appid = appidMsgElement.toString();
        ackMsg.addMessageElement(MESSAGE_APPID,
                              new StringMessageElement(MESSAGE_APPID,
                                                       appid,
                                                       null));
        //********** test begin**********************
        //get the current command
        MessageElement commandMsgElement =
            msg.getMessageElement(MESSAGE_COMMAND, MESSAGE_COMMAND);
        String previousCommand = commandMsgElement.toString();
        String theCommand = RETURN_MSG_COMMAND;
        if(previousCommand.equals(ReplicationState.HC_COMMAND)) {
            theCommand = RETURN_HC_MSG_COMMAND;
        }
        //this is a return command
        /* FIXME replace next line with above - need to test
        String theCommand = RETURN_MSG_COMMAND;
         */       
        //********** test end  **********************
       

        ackMsg.addMessageElement(MESSAGE_COMMAND,
                              new StringMessageElement(MESSAGE_COMMAND,
                                                       theCommand,
                                                       null));
        //serialized list of ids to ack back to
        if(listAckIds != null) {
            ackMsg.addMessageElement(MESSAGE_ACK_IDS_LIST,
View Full Code Here

      
        if(_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationState>>createBroadcastMessage:instanceName=" + instanceName + " theCommand=" + theCommand);
        }        
        msg.addMessageElement(MESSAGE_MODE,
                              new StringMessageElement(MESSAGE_MODE,
                                                       mode,
                                                       null));
        if(mode != null && mode.equalsIgnoreCase(BULK_MESSAGE_MODE)) {
            msg.addMessageElement(BULK_MESSAGE_MODE,
                    new StringMessageElement(BULK_MESSAGE_MODE,
                                             "BULK",
                                             null));
        }       
        msg.addMessageElement(MESSAGE_ID,
                              new StringMessageElement(MESSAGE_ID,
                                                       id,
                                                       null));       
        msg.addMessageElement(MESSAGE_APPID,
                              new StringMessageElement(MESSAGE_APPID,
                                                       appid,
                                                       null));
        msg.addMessageElement(MESSAGE_VERSION,
                              new StringMessageElement(MESSAGE_VERSION,
                                                       versionString,
                                                       null));
        if(extraParam != null) {
            msg.addMessageElement(MESSAGE_EXTRA_PARAM,
                              new StringMessageElement(MESSAGE_EXTRA_PARAM,
                                                       extraParam,
                                                       null));
        }
        if(queryResult != null) {
            msg.addMessageElement(MESSAGE_QUERY_RESULT,
                              new StringMessageElement(MESSAGE_QUERY_RESULT,
                                                       queryResult,
                                                       null));
        }       
        msg.addMessageElement(MESSAGE_COMMAND,
                              new StringMessageElement(MESSAGE_COMMAND,
                                                       theCommand,
                                                       null));
        msg.addMessageElement(MESSAGE_LAST_ACCESS,
                              new StringMessageElement(MESSAGE_LAST_ACCESS,
                                                       lastAccess.toString(),
                                                       null));
        msg.addMessageElement(MESSAGE_MAX_INACTIVE,
                              new StringMessageElement(MESSAGE_MAX_INACTIVE,
                                                       maxInactive.toString(),
                                                       null));       
        msg.addMessageElement(InstanceNameMessage,
                              new StringMessageElement(InstanceNameMessage,
                                                       instanceName,
                                                       null));
        msg.addMessageElement(MESSAGE_INSTANCE_NAME,
                              new StringMessageElement(MESSAGE_INSTANCE_NAME,
                                                       instanceName,
                                                       null));
        //is nack message
        String isNackString = "N";
        if(isNack) {
            isNackString = "Y";
        }
        msg.addMessageElement(MESSAGE_IS_NACK,
                              new StringMessageElement(MESSAGE_IS_NACK,
                                                       isNackString,
                                                       null));         
        if(data != null) {
            msg.addMessageElement(MESSAGE_DATA,
                              new ByteArrayMessageElement(MESSAGE_DATA,
                                                       null,
                                                       data,
                                                       null));
        }
        if(trunkData != null) {
            msg.addMessageElement(MESSAGE_TRUNK_DATA,
                              new ByteArrayMessageElement(MESSAGE_TRUNK_DATA,
                                                       null,
                                                       trunkData,
                                                       null));
        }
        if(containerExtraParamData != null) {
            msg.addMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
                              new ByteArrayMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
                                                       null,
                                                       containerExtraParamData,
                                                       null));
        }
        if(propertiesState != null) {
            msg.addMessageElement(MESSAGE_PROPERTIES_DATA,
                              new ByteArrayMessageElement(MESSAGE_PROPERTIES_DATA,
                                                       null,
                                                       propertiesState,
                                                       null));
        }       

        msg.addMessageElement(ORIGINATING_INSTANCE_NAME,
                new StringMessageElement(ORIGINATING_INSTANCE_NAME, ReplicationUtil.getInstanceName(), null));
       
        return msg;
    }
View Full Code Here

            //send back response if it isn't already a response
            if( !(msgElement.toString()).startsWith("RETURN_MSG_COMMAND")) {
                Message returnMsg = new Message();
                String returnData = "ReturnMessage  :"+ msgElement.toString();
                returnMsg.addMessageElement(SenderMessage,
                                      new StringMessageElement(SenderMessage,
                                                               returnData,
                                                               null));
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("SendingResponse :" + returnData);
                }
View Full Code Here

        try {
            for (int i = 0; i < 1; i++) {
                Message msg = new Message();
                String data = "Propagated Message #" + i + " From Instance " + instanceName;
                msg.addMessageElement(SenderMessage,
                                      new StringMessageElement(SenderMessage,
                                                               data,
                                                               null));
                msg.addMessageElement(InstanceNameMessage,
                                      new StringMessageElement(InstanceNameMessage,
                                                               instanceName,
                                                               null));
                if(i == 0) {
                    String readyMsgString = MESSAGE_READY;
                    msg.addMessageElement(ReadyMessage,
                                          new StringMessageElement(ReadyMessage,
                                                                   readyMsgString,
                                                                   null));
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("Sending :" + readyMsgString + ":" + instanceName);
                    }
View Full Code Here

        this.sendMessage(responseMsg);
    }
   
    private Message alterIncomingMessageToResponse(Message msg) {
        msg.replaceMessageElement(MESSAGE_COMMAND,
                              new StringMessageElement(MESSAGE_COMMAND,
                                                       RETURN_MSG_COMMAND,
                                                       null));
        return msg;
    }
View Full Code Here

            //send back response if it isn't already a response
            if (!(msgElement.toString()).startsWith("RETURN_MSG_COMMAND")) {
                Message returnMsg = new Message();
                String returnData = "ReturnMessage  :" + msgElement.toString();
                returnMsg.addMessageElement(SenderMessage,
                        new StringMessageElement(SenderMessage,
                                returnData,
                                null));
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("SendingResponse :" + returnData);
                }
View Full Code Here

            try {
                for (int i = 0; i < ITERATIONS; i++) {
                    Message msg = new Message();
                    String data = "Message #" + i + " From Instance " + instanceName;
                    msg.addMessageElement(MESSAGE_MODE,
                              new StringMessageElement(MESSAGE_MODE,
                                                       MODE_STARTUP,
                                                       null));
                    msg.addMessageElement(SenderMessage,
                                          new StringMessageElement(SenderMessage,
                                                                   data,
                                                                   null));                   
                    if (_pipelogger.isLoggable(Level.FINE)) {
                        _pipelogger.fine("Sending :" + data);
                    }
View Full Code Here

TOP

Related Classes of net.jxta.endpoint.StringMessageElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.