001    package com.khubla.pragmatach.plugin.cluster.multicast;
002    
003    import com.khubla.pragmatach.framework.api.PragmatachException;
004    import com.khubla.pragmatach.plugin.cluster.serialization.GenericJSONSerializer;
005    
006    /**
007     * @author tome
008     */
009    public class MulticastMessage {
010       /**
011        * types of message
012        */
013       public final static int MESSAGETYPE_HELLO = 1;
014       public final static int MESSAGETYPE_GBYE = 2;
015       public final static int MESSAGETYPE_SOLICITUPDATE = 3;
016       public final static int MESSAGETYPE_UPDATE = 4;
017    
018       /**
019        * from string
020        */
021       public static MulticastMessage deserialize(byte[] messageBody) throws PragmatachException {
022          final MulticastMessage multicastMessage = new MulticastMessage();
023          return new GenericJSONSerializer<MulticastMessage>().deserialize(multicastMessage, new String(messageBody));
024       }
025    
026       /**
027        * to String
028        */
029       public static byte[] serialize(MulticastMessage multicastMessage) throws PragmatachException {
030          return new GenericJSONSerializer<MulticastMessage>().serialize(multicastMessage).getBytes();
031       }
032    
033       /**
034        * type
035        */
036       private int messageType;
037       /**
038        * content
039        */
040       private String messageContent;
041    
042       /**
043        * ctor
044        */
045       public MulticastMessage() {
046       }
047    
048       /**
049        * ctor
050        */
051       public MulticastMessage(int messageType, String messageContent) {
052          this.messageContent = messageContent;
053          this.messageType = messageType;
054       }
055    
056       public String getMessageContent() {
057          return messageContent;
058       }
059    
060       public int getMessageType() {
061          return messageType;
062       }
063    
064       public void setMessageContent(String messageContent) {
065          this.messageContent = messageContent;
066       }
067    
068       public void setMessageType(int messageType) {
069          this.messageType = messageType;
070       }
071    }