Package net.jxta.endpoint

Examples of net.jxta.endpoint.Message


    /**
     * create an ack Message from the input
     * @param msg
     */    
    public static Message createAckMessageFrom(Message msg) {
        Message ackMsg = new Message();
       
        //echo the mode
        String mode = MODE_WEB;
        MessageElement modeMsgElement =
            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


        } catch (IOException ex) {
            //deliberate no-op
            ;
        }
       
        Message ackMsg = new Message();
       
        //echo the mode
        String mode = MODE_WEB;
        MessageElement modeMsgElement =
            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,
                              new ByteArrayMessageElement(MESSAGE_ACK_IDS_LIST,
                                                       null,
                                                       listAckIds,
                                                       null));
        }
View Full Code Here

     * @param instName
     */
    public static Message createBroadcastMessage(ReplicationState state, boolean isResponse, String instName) {
        String instanceName = ReplicationUtil.getInstanceName();
        //String instanceName = instName;
        Message msg = new Message();
        String mode = state.getMode();
        String id = (String)state.getId();
        String appid = state.getAppId();
        String versionString = Long.toString(state.getVersion());
        Long lastAccess = new Long(state.getLastAccess());
        Long maxInactive = new Long(state.getMaxInactiveInterval());       
        String extraParam = state.getExtraParam();
        String queryResult = (String)state.getQueryResult();
        String theCommand = state.getCommand();
        //String theCommand = MESSAGE_BROADCAST_QUERY;
        byte[] data = state.getState();
        byte[] trunkData = state.getTrunkState();
        byte[] containerExtraParamData = state.getContainerExtraParamsState();
        HashMap properties = (HashMap)state.getProperties();
        byte[] propertiesState = null;
        try {
            propertiesState = ReplicationUtil.getByteArray(properties);
        } catch (Exception ex) {}        
        /*
        if(isResponse) {
            theCommand = RETURN_BROADCAST_MSG_COMMAND;
        }
         */
        //is nack message
        boolean isNack = state._isNack;
      
        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

     */
    private void sendTestPropagatedMessages(OutputPipe pipe) {
        String instanceName = ReplicationUtil.getInstanceName();
        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

     */
    public void pipeMsgEvent(PipeMsgEvent event) {
        if(_logger.isLoggable(Level.FINEST)) {
            _logger.finest("JxtaBiDiPipeWrapper>>pipeMsgEvent");
        }
        Message msg = null;
        try {
            // grab the message from the event
            msg = event.getMessage();
            if(_logger.isLoggable(Level.FINEST)) {
                _logger.finest("JxtaBiDiPipeWrapper>>pipeMsgEvent:msg=" + msg);
            }          
            if (msg == null) {
                if(_logger.isLoggable(Level.FINEST)) {
                    _logger.finest("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);
            if(msgElement != null) {
                if(_logger.isLoggable(Level.FINEST)) {
                    _logger.finest("msgElement=" + msgElement.toString());
                }               
            }
View Full Code Here

            JxtaReplicationSender.createInstance();
        jxtaReplicationSender.sendOverPipe(msg);
    }
   
    private void sendResponse(Message msg) {
        Message responseMsg =
            this.alterIncomingMessageToResponse(msg);
        this.sendMessage(responseMsg);
    }
View Full Code Here

  if (_logger.isLoggable(Level.FINE)) {
      _logger.fine("JxtaUnicastPipeUtil>>sendOverPropagatedPipe:toInstance=" + instanceName);
  }
  //use this to create our outputPipe
  RouteAdvertisement routeAdv = state.getRouteAdvertisement();
  Message msg = ReplicationState.createBroadcastMessage(state, isResponse, instanceName);
  //add routeAdvertisement element for return route (self-addressed stamped envelope)
  if (!isResponse) {
      JxtaUtil.addRoute(msg);
  }
  sendOverUnicastPipe(routeAdv, instanceName, (String) state.getId(),
View Full Code Here

     *  all incoming messages must have an InstanceNameMessage element
     *@param  event  message event
     */
    public void pipeMsgEvent(PipeMsgEvent event) {

        Message msg = null;
        try {
            // grab the message from the event
            msg = event.getMessage();
            //displayKeyMessageElements(msg);
          
            if (msg == null) {
                 if (_logger.isLoggable(Level.FINEST)) {
                    _logger.finest("Received an empty message, returning");
                 }               
                return;
            }

            ReplicationUtil repUtil = ReplicationUtil.createReplicationUtil();

            if (repUtil.isInstanceLoadBalancedByCLB()) {
                MessageProcessor.getInstance().pipeMsgEvent(event, null);
                return;
            }
            // get the message element named InstanceNameMessage

            MessageElement instanceNameMsgElement =
                msg.getMessageElement(InstanceNameMessage, InstanceNameMessage);
            //ignore broadcasts from yourself
            String returnInstance = null;
            if(instanceNameMsgElement != null) {
                returnInstance = instanceNameMsgElement.toString();
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("InputPipeWrapper:incoming propagated msg from: " + returnInstance);
                }               
            }
            if(returnInstance.equalsIgnoreCase(getInstanceName())) {
                return;
            }
           
            MessageElement readyMsgElement = msg.getMessageElement(ReadyMessage, ReadyMessage);
            if(readyMsgElement != null) {
                try {
                    Thread.currentThread().sleep(2000L);
                } catch(InterruptedException ex) {}               
                if (_pipelogger.isLoggable(Level.FINE)) {
                    _pipelogger.fine("readyMsgElement=" + readyMsgElement.toString() + " from: " + returnInstance)
                }
                JoinNotificationEventHandler.checkAndDoJoinFor(returnInstance);
            }
           
            MessageElement bulkMsgElement = msg.getMessageElement(BULK_MESSAGE_MODE, BULK_MESSAGE_MODE);
            if (bulkMsgElement != null) {
                processBulkMessage(msg, bulkMsgElement);
                return;
            }           
                  
            MessageElement idMsgElement = msg.getMessageElement(MESSAGE_ID, MESSAGE_ID);
            if(idMsgElement != null) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("idMsgElement=" + idMsgElement.toString());
                }
            }
            MessageElement commandMsgElement =
                msg.getMessageElement(MESSAGE_COMMAND, MESSAGE_COMMAND);            
            if(commandMsgElement != null) {
                String theCommand = commandMsgElement.toString();
                if(isBroadcastMethod(theCommand)) {
                    //processQueryMessage(msg, idMsgElement, returnInstance);
                    ReplicationMessageRouter receiver = getRouter();
View Full Code Here

        if(pipeWrapper == null) {
            //no pipe wrapper - just return
            return false;
        }
        JxtaBiDiPipe thePipe = pipeWrapper.getPipe();
        Message theMsg = this.createMessage(state, isResponse);
        if(pipeWrapper.isPipeClosed()) {
            //no pipe - just return
            return false;
        }
        result = sendMessageOverPipe(theMsg, thePipe, pipeWrapper);
View Full Code Here

        if(pipeWrapper == null) {
            //no pipe wrapper - just return
            return false;
        }
        JxtaBiDiPipe thePipe = pipeWrapper.getPipe();
        Message theMsg = this.createMessage(state, isResponse);
        if(pipeWrapper.isPipeClosed()) {
            //no pipe - just return
            return false;
        }
        result = sendMessageOverPipe(theMsg, thePipe, pipeWrapper);
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.