Class CMEvent

java.lang.Object
kr.ac.konkuk.ccslab.cm.entity.CMObject
kr.ac.konkuk.ccslab.cm.event.CMEvent
Direct Known Subclasses:
CMConcurrencyEvent, CMConsistencyEvent, CMDataEvent, CMDummyEvent, CMFileEvent, CMFileSyncEvent, CMInterestEvent, CMMqttEvent, CMMultiServerEvent, CMSessionEvent, CMSNSEvent, CMUserEvent

public abstract class CMEvent extends CMObject
This class represents a CM event.
The CMEvent class is the superclass of every CM event. The CMEvent class includes the common header fields of a CM event such as sender, receiver, which session and group (handler session and group names) should handle this event and which session and group members (distribution session and group names) this event should be forwarded to.

CM nodes (a client or a server) communicate with each other by exchanging CM events.
CM application can send and receive a CM event through event-transmission methods of the CM stub module (CMStub).

  • Field Details

    • m_strSender

      protected String m_strSender
    • m_strReceiver

      protected String m_strReceiver
    • m_strHandlerSession

      protected String m_strHandlerSession
    • m_strHandlerGroup

      protected String m_strHandlerGroup
    • m_strDistributionSession

      protected String m_strDistributionSession
    • m_strDistributionGroup

      protected String m_strDistributionGroup
    • m_nID

      protected int m_nID
    • m_nByteNum

      protected int m_nByteNum
    • m_bytes

      protected ByteBuffer m_bytes
  • Constructor Details

    • CMEvent

      public CMEvent()
      Creates an empty CMEvent object.
    • CMEvent

      public CMEvent(ByteBuffer msg)
      Creates a CMEvent object.
      This CM object marshalls a given bytes of a message.
      Parameters:
      msg - - the bytes of a message
  • Method Details

    • marshall

      public ByteBuffer marshall()
      Marshals the CM event.
      This method changes the event fields into bytes in the ByteBuffer so that the event can be sent through the communication channel.
      If the subclass of the CMEvent class is instantiated and the object calls this method, it conducts marshalling of both the event header and the event body fields.
      Returns:
      a reference to the ByteBuffer object that includes the marshalled event fields. If the instance of the subclass of the CMEvent calls this method, the ByteBuffer object includes both the marshalled event header and body fields.
    • unmarshall

      public CMEvent unmarshall(ByteBuffer msg)
      Unmarshals the given ByteBuffer to the CM event.
      This method changes bytes in the ByteBuffer to the corresponding event fields of this event object.
      If the subclass of the CMEvent class is instantiated and the object calls this method, it conducts unmarshalling of both the event header and the event body fields.
      Parameters:
      msg - - the bytes to be unmarshalled
      Returns:
      a reference to the CMEvent object.
    • setID

      public void setID(int id)
      Sets the event ID field.
      When the event object is initialized, the event ID is set to -1.
      Parameters:
      id - - the event ID
    • getID

      public int getID()
      Returns the event ID.
      Returns:
      an event ID, or -1 if this event does not set any ID.
    • setSender

      public void setSender(String strName)
      Sets the sender name.
      Parameters:
      strName - - the sender name
    • getSender

      public String getSender()
      Returns the sender name.
      Returns:
      a sender name.
    • setReceiver

      public void setReceiver(String strName)
      Sets the receiver name.
      Parameters:
      strName - - the receiver name.
    • getReceiver

      public String getReceiver()
      Returns the receiver name.
      Returns:
      a receiver name.
    • setHandlerSession

      public void setHandlerSession(String sName)
      Sets a session for handling this event.
      The session name determines which session deals with this event.
      When the event object is initialized, the session for handling this event is set to the empty string (""). The empty session name specifies that this event is internally handled by the CMInteractionManager of the receiver CM.
      Parameters:
      sName - - the session name
    • setHandlerGroup

      public void setHandlerGroup(String gName)
      Sets a group for handling this event.
      The group name determines which group deals with this event.
      When the event object is initialized, the group for handling this event is set to the empty string (""). If the group name is empty and the specific session name is set, this event is internally handled by the CMSessionManager of the receiver CM. If both the group and the session are empty, this event is internally handled by the CMInteractionManager of the receiver CM. If both the group and the session are set to specific names, this event is internally handled by the CMGroupManager of the receiver CM.
      Parameters:
      gName - - the group name
    • setDistributionSession

      public void setDistributionSession(String sName)
      Sets a session to which this event will be forwarded by the server.
      The session name determines to which session the server will forward this event after it receives and processes this event. Normally, session and group for the distribution of the event are determined by CM when the client calls CMStub.send(CMEvent, String), CMStub.cast(CMEvent, String, String), or CMStub.broadcast(CMEvent) methods.

      When the event object is initialized, the session for distribution is set to the empty string (""). If the session name is empty, the server does not forward this event. If the session is set to a specific name, the distribution target is determined by the group name for the distribution. If the session name is "CM_ALL_SESSION", the server forwards this event to members of all sessions and groups. If the session name is "CM_ONE_USER", the distribution target is one user whose name should be set in the group name for the distribution.

      Parameters:
      sName - - the session name for the distribution of this event.
      The sName value can be a session name, "CM_ALL_SESSION", or "CM_ONE_USER".
      See Also:
    • setDistributionGroup

      public void setDistributionGroup(String gName)
      Sets a group to which this event will be forwarded by the server.
      The group name determines to which group the server will forward this event after it receives and processes this event. Normally, session and group for the distribution of the event are determined by CM when the client calls CMStub.send(CMEvent, String), CMStub.cast(CMEvent, String, String), or CMStub.broadcast(CMEvent) methods.

      When the event object is initialized, the group for distribution is set to the empty string (""). If the group name is empty, the server does not forward this event. If the group is set to a specific name, the server forwards this event to the corresponding group members. If the group name is CM_ALL_GROUP", the server forwards this event to members of all groups. If the group name is a specific user name (and if the session name is "CM_ONE_USER"), the server forwards this event to the corresponding specific user.

      Parameters:
      gName - - the group name for the distribution of this event.
      The gName value can be a group name, "CM_ALL_GROUP", or a specific user name.
      See Also:
    • getHandlerSession

      public String getHandlerSession()
      Returns a session name for handling this event.
      The session name determines which session deals with this event.
      Returns:
      - a session name for handling this event.
      See Also:
    • getHandlerGroup

      public String getHandlerGroup()
      Returns a group name for handling this event.
      The group name determines which group deals with this event.
      Returns:
      - a group name for handling this event.
      See Also:
    • getDistributionSession

      public String getDistributionSession()
      Returns a target session to which the server forwards this event.
      The session name determines to which session the server will forward this event after it receives and processes this event.
      Returns:
      - a session name for distributing this event.
      See Also:
    • getDistributionGroup

      public String getDistributionGroup()
      Returns a target group to which the server forwards this event.
      The group name determines to which group the server will forward this event after it receives and processes this event.
      Returns:
      - a group name for distributing this event.
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class CMObject
    • toString

      public String toString()
      Overrides:
      toString in class CMObject
    • allocate

      protected boolean allocate()
    • marshallHeader

      protected void marshallHeader()
    • unmarshallHeader

      protected void unmarshallHeader(ByteBuffer msg)
    • marshallBody

      protected abstract void marshallBody()
    • unmarshallBody

      protected abstract void unmarshallBody(ByteBuffer msg)
    • setByteNum

      protected void setByteNum(int nByteNum)
    • getByteNum

      protected int getByteNum()
    • putStringToByteBuffer

      protected void putStringToByteBuffer(String str)
    • getStringFromByteBuffer

      protected String getStringFromByteBuffer(ByteBuffer buf)
    • putInt2BytesToByteBuffer

      protected void putInt2BytesToByteBuffer(int num)
    • getInt2BytesFromByteBuffer

      protected int getInt2BytesFromByteBuffer(ByteBuffer buf)