⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.java

📁 《精通RMI:Java与EJB企业级应用开发》书籍的源代码. 本书是讲述RMI技术的经典著作
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package masteringrmi.chat.interfaces;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 *   This is the Message object. A Message is the core object in the chat system.
 *   The system can be extended by introducing new message types. Since the content
 *   is an Object it can be anything including images. You must also extend the ChatGUI
 *   if you want to present new types Messages in the user interface.
 *      
 *   @author Rickard 謆erg (rickard@dreambean.com)
 *   @version $Revision:$
 */
public final class Message
   implements java.io.Externalizable
{
   // Constants -----------------------------------------------------
   private static final long serialVersionUID = 1L;
   
   // Pre-defined name for messages sent from the system
   public static final String SYSTEM = "System";
   
   // Pre-defined types of messages
   // This is the most common type: a text message
   public static final String TEXT = "Text"; 
      
   // Pre-defined types for control messages
   public static final String TOPIC_CREATED = "TopicCreated";
   public static final String TOPIC_REMOVED = "TopicRemoved";
   
   public static final String USER_JOINED = "UserJoined";
   public static final String USER_LEFT = "UserLeft";
   
   public static final String GREETING  = "Greeting";
   
   // Attributes ----------------------------------------------------
   String sender;
   String type;
   Object content;
   
   // Constructors --------------------------------------------------
   public Message()
   {
      // Used by Externalizable
   }
   
   public Message(String sender, String type, Object content)
   {
      this.sender = sender;
      this.type = type;
      this.content = content;
   }
   
   // Public --------------------------------------------------------
   public String getSender() 
   { 
      return sender; 
   }
   
   public String getType() 
   { 
      return type; 
   }
   
   public Object getContent() 
   { 
      return content; 
   }
   
   // Private -------------------------------------------------------
   // We use externalization instead of serialization since it is 
   // significantly faster in this case, and we are not worried about
   // inheritance hierarchies
   public void writeExternal(java.io.ObjectOutput out)
      throws java.io.IOException
   {
      out.writeUTF(sender);
      out.writeUTF(type);
      out.writeObject(content);
   }
   
   public void readExternal(java.io.ObjectInput in)
      throws java.io.IOException, ClassNotFoundException
   {
      sender = in.readUTF();
      type   = in.readUTF();
      content = in.readObject();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -