Package net.jxta.endpoint

Examples of net.jxta.endpoint.Message


        return pipeAdv;
    }

    public synchronized void pipeMsgEvent(PipeMsgEvent event) {
        // Extract the message.
        Message message = event.getMessage();
        MessageElementEnumeration msgEnum = message.getElements();
        MessageElement elm = null;
        JXTAClassLoader classLoader = new JXTAClassLoader();

        while (msgEnum.hasMoreElements()) {
            elm = (MessageElement) msgEnum.nextElement();
View Full Code Here


            System.out.println("failed to read/parse pipe " + "advertisement"
                    + ex.getMessage());
        }

        // create the pipe message
        Message msg = _pipeSvc.createMessage();

        //msg.setString(_TAG, data);
        //byte[] buff = new byte[MAXBUFF];
        //int size = actStream.read(buff);
        //actStream.close();
        //if (size < MAXBUFF) {
        try {
            MessageElement msgelm = msg
                    .newMessageElement(_TAG, null, actStream);
            msg.addElement(msgelm);
        } catch (java.io.IOException e) {
            // go try again;
        }

        try {
View Full Code Here

     * create a Message from the input state
     * @param state
     * @param isResponse is the created message a response
     */    
    public static Message createMessage(ReplicationState state, boolean isResponse) {
        Message msg = new Message();
        String mode = state.getMode();
        String id = (String)state.getId();
        String appid = state.getAppId();
        String command = state.getCommand();
        Long version = new Long(state.getVersion());
        Long lastAccess = new Long(state.getLastAccess());
        Long maxInactive = new Long(state.getMaxInactiveInterval());
        String extraParam = state.getExtraParam();
        //FIXME for now assuming this is a Long
        //for generality will have to serialize and use bytearray
        Integer queryResult = (Integer)state.getQueryResult();
        String instanceName = state.getInstanceName();
        if(instanceName == null) {
            //put existing instanceName for source if it is missing here
            instanceName = lookupInstanceName();
        }       
        byte[] data = state.getState();
        byte[] trunkData = state.getTrunkState();
        byte[] containerExtraParamData = state.getContainerExtraParamsState();
        boolean ackRequired = state.isAckRequired();
        HashMap properties = (HashMap)state.getProperties();
        byte[] propertiesState = null;
        try {
            propertiesState = ReplicationUtil.getByteArray(properties);
        } 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)) {
View Full Code Here

     */
    public void pipeMsgEvent(PipeMsgEvent event) {
        if(_logger.isLoggable(Level.FINE)) {
            _logger.fine("PipeWrapper>>pipeMsgEvent");
        }       
        Message msg = null;
        try {
            // grab the message from the event
            msg = event.getMessage();
            if(_logger.isLoggable(Level.FINE)) {
                _logger.fine("PipeWrapper>>pipeMsgEvent:msg=" + msg);
            }            
            if (msg == null) {
                if(_logger.isLoggable(Level.FINE)) {
                    _logger.fine("Received an empty message, returning");
                }               
                return;
            }

            // get the message element named SenderMessage
            MessageElement msgElement = msg.getMessageElement(SenderMessage, SenderMessage);
            MessageElement idMsgElement = msg.getMessageElement(MESSAGE_ID, MESSAGE_ID);
            MessageElement bulkMsgElement = msg.getMessageElement(BULK_MESSAGE_MODE, BULK_MESSAGE_MODE);
//            if (_logger.isLoggable(Level.FINE)) {
//                _logger.fine("msgElement=" + msgElement +
//                             " idMsgElement=" + idMsgElement +
//                             " bulkMsgElement=" + bulkMsgElement);
//            }            
View Full Code Here

                _logger.fine("Message  :"+ msgElement.toString());
            }
            //put comment start back 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

             */           
        }       
        if (ReplicationState.isVoidMethodReturnMessage(msg)
            && ReplicationState.isAckRequiredForMessage(msg)) {
            //send immediate ack
            Message ackMsg = ReplicationState.createAckMessageFrom(msg);
            JxtaBiDiPipe thePipe = this.getPipe();
//            long tempStart = 0L;
//            if (_logger.isLoggable(Level.FINE)) {
//                tempStart = System.currentTimeMillis();
//            }
View Full Code Here

            _logger.fine("<<checkSendImmediateBulkAck:isAckRequiredForMessage=" + ReplicationState.isAckRequiredForMessage(msg));
        }       
       if (ReplicationState.isVoidMethodReturnMessage(msg)
            && ReplicationState.isAckRequiredForMessage(msg)) {
            //FIXME send immediate ack
            Message ackMsg = ReplicationState.createBulkAckMessageFrom(msg, states);
            JxtaBiDiPipe thePipe = this.getPipe();
//            long tempStart = 0L;
//            if (_logger.isLoggable(Level.FINE)) {
//                tempStart = System.currentTimeMillis();
//            }
View Full Code Here

    * usually after waiting for congestion to clear.</li>
    * </ul>
    * @param event the event
    */
    public void messageSendFailed(OutgoingMessageEvent event) {
        Message sentMessage = (Message)event.getSource();
        printFastAckStats(sentMessage, false);
        decrementQueuedMessageCount();
    }
View Full Code Here

    */
    public void messageSendSucceeded(OutgoingMessageEvent event) {

        //System.out.println("messageSendSucceeded");
        decrementQueuedMessageCount();
        Message sentMessage = (Message)event.getSource();
        String ackRequiredString = (String)sentMessage.getMessageProperty(MESSAGE_ACK_REQUIRED);       
        printFastAckStats(sentMessage, true);           
        if(ackRequiredString.equalsIgnoreCase("Y")) {
            //System.out.println("doing fast ack...");
            //for bulk case
            MessageElement bulkMsgElement = sentMessage.getMessageElement(BULK_MESSAGE_MODE, BULK_MESSAGE_MODE);
            if(bulkMsgElement != null) {
                doFastBulkAcksFor(sentMessage, bulkMsgElement);
            } else {
                //for non bulk case
                MessageElement idMsgElement = sentMessage.getMessageElement(MESSAGE_ID, MESSAGE_ID);
                if(idMsgElement != null) {
                    doFastAckFor(sentMessage, idMsgElement);
                }
            }
        }
View Full Code Here

     * @param totalStates the number of total states
     * @param data the serialized list of ReplicationStates
     * @param ackRequired does this message require an ack
     */    
    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)) {
            _logger.info("ReplicationState:createBulkMessage:Sending BULK_Message id:" + msgID +
                         "   size: " + data.length + " startTime=" + sendStartTime);
        }
View Full Code Here

TOP

Related Classes of net.jxta.endpoint.Message

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.