当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了Java中codeu.chat.common.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Message类属于codeu.chat.common包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newMessage

import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Message newMessage(Uuid author, Uuid conversation, String body) {

  Message response = null;

  try (final Connection connection = source.connect()) {

    Serializers.INTEGER.write(connection.out(), NetworkCode.NEW_MESSAGE_REQUEST);
    Uuid.SERIALIZER.write(connection.out(), author);
    Uuid.SERIALIZER.write(connection.out(), conversation);
    Serializers.STRING.write(connection.out(), body);

    if (Serializers.INTEGER.read(connection.in()) == NetworkCode.NEW_MESSAGE_RESPONSE) {
      response = Serializers.nullable(Message.SERIALIZER).read(connection.in());
    } else {
      LOG.error("Response from server failed.");
    }
  } catch (Exception ex) {
    System.out.println("ERROR: Exception during call on server. Check log for details.");
    LOG.error(ex, "Exception during call on server.");
  }

  return response;
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:25,代码来源:Controller.java

示例2: getMessages

import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Collection<Message> getMessages(Collection<Uuid> ids) {

  final Collection<Message> messages = new ArrayList<>();

  try (final Connection connection = source.connect()) {

    Serializers.INTEGER.write(connection.out(), NetworkCode.GET_MESSAGES_BY_ID_REQUEST);
    Serializers.collection(Uuid.SERIALIZER).write(connection.out(), ids);

    if (Serializers.INTEGER.read(connection.in()) == NetworkCode.GET_MESSAGES_BY_ID_RESPONSE) {
      messages.addAll(Serializers.collection(Message.SERIALIZER).read(connection.in()));
    } else {
      LOG.error("Response from server failed.");
    }
  } catch (Exception ex) {
    System.out.println("ERROR: Exception during call on server. Check log for details.");
    LOG.error(ex, "Exception during call on server.");
  }

  return messages;
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:23,代码来源:View.java

示例3: createSendToRelayEvent

import codeu.chat.common.Message; //导入依赖的package包/类
private Runnable createSendToRelayEvent(final Uuid userId,
                                        final Uuid conversationId,
                                        final Uuid messageId) {
  return new Runnable() {
    @Override
    public void run() {
      final User user = view.findUser(userId);
      final ConversationHeader conversation = view.findConversation(conversationId);
      final Message message = view.findMessage(messageId);
      relay.write(id,
                  secret,
                  relay.pack(user.id, user.name, user.creation),
                  relay.pack(conversation.id, conversation.title, conversation.creation),
                  relay.pack(message.id, message.content, message.creation));
    }
  };
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:18,代码来源:Server.java

示例4: countRecentMessages

import codeu.chat.common.Message; //导入依赖的package包/类
private int countRecentMessages(Time lastUpdate, Uuid searchConversation) {

    // Given a time value for the last time that a check for recent messages was
    // requested and the UUID of the conversation to search through, return a count
    // of messages in the specified conversation that were created after the
    // specified time.

    int newMessages = 0;

    final ConversationPayload searchConversationPayload = model.conversationPayloadById().first(searchConversation);
    Message currentMessage = model.messageById().first(searchConversationPayload.firstMessage);

    while(currentMessage != null) {
      if(lastUpdate.compareTo(currentMessage.creation) < 0) {
        newMessages++;
      }
      currentMessage = model.messageById().first(currentMessage.next);
    }
    return newMessages;
  }
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:21,代码来源:View.java

示例5: testAddMessage

import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {

  final User user = controller.newUser("user");

  assertFalse(
      "Check that user has a valid reference",
      user == null);

  final ConversationHeader conversation = controller.newConversation(
      "conversation",
      user.id);

  assertFalse(
      "Check that conversation has a valid reference",
      conversation == null);

  final Message message = controller.newMessage(
      user.id,
      conversation.id,
      "Hello World");

  assertFalse(
      "Check that the message has a valid reference",
      message == null);
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:27,代码来源:BasicControllerTest.java

示例6: createSendToRelayEvent

import codeu.chat.common.Message; //导入依赖的package包/类
private Runnable createSendToRelayEvent(final Uuid userId,
                                        final Uuid conversationId,
                                        final Uuid messageId) {
  return new Runnable() {
    @Override
    public void run() {
      final User user = view.findUser(userId);
      final Conversation conversation = view.findConversation(conversationId);
      final Message message = view.findMessage(messageId);
      relay.write(id,
                  secret,
                  relay.pack(user.id, user.name, user.creation),
                  relay.pack(conversation.id, conversation.title, conversation.creation),
                  relay.pack(message.id, message.content, message.creation));
    }
  };
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:18,代码来源:Server.java

示例7: getMessages

import codeu.chat.common.Message; //导入依赖的package包/类
@Override
public Collection<Message> getMessages(Uuid conversation, Time start, Time end) {

  final Conversation foundConversation = model.conversationById().first(conversation);

  final List<Message> foundMessages = new ArrayList<>();

  Message current = (foundConversation == null) ?
      null :
      model.messageById().first(foundConversation.firstMessage);

  while (current != null && current.creation.compareTo(start) < 0) {
    current = model.messageById().first(current.next);
  }

  while (current != null && current.creation.compareTo(end) <= 0) {
    foundMessages.add(current);
    current = model.messageById().first(current.next);
  }

  return foundMessages;
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:23,代码来源:View.java

示例8: testAddMessage

import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {

  final User user = controller.newUser("user");

  assertFalse(
      "Check that user has a valid reference",
      user == null);

  final Conversation conversation = controller.newConversation(
      "conversation",
      user.id);

  assertFalse(
      "Check that conversation has a valid reference",
      conversation == null);

  final Message message = controller.newMessage(
      user.id,
      conversation.id,
      "Hello World");

  assertFalse(
      "Check that the message has a valid reference",
      message == null);
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:27,代码来源:BasicControllerTest.java

示例9: add

import codeu.chat.common.Message; //导入依赖的package包/类
public MessageContext add(String messageBody) {

    final Message message = controller.newMessage(user.id,
                                                  conversation.id,
                                                  messageBody);

    return message == null ?
        null :
        new MessageContext(message, view);
  }
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:11,代码来源:ConversationContext.java

示例10: restoreJsonObjects

import codeu.chat.common.Message; //导入依赖的package包/类
private void restoreJsonObjects(String lineBeingRead) {
  // lineElements[0] will contain the proper identifier (Convo, Message, User)
  // Then, according to the identifier, the proper object will be restored
  String[] lineElements = lineBeingRead.split(";");

  switch (lineElements[0]) {
    // Each case will feed the object directly into model except Messages
    case "User":
      User loadUser = gson.fromJson(lineElements[1], User.class);
      model.add(loadUser);
      break;
    case "Convo":
      ConversationHeader loadConvo = gson.fromJson(lineElements[1], ConversationHeader.class);
      model.add(loadConvo);
      break;
    case "Message":
      // Message object cannot be directly fed into model
      // Instead, each value, and the original conversation value, is
      // passed into the Controller method
      Uuid messageConvo = gson.fromJson(lineElements[1], Uuid.class);
      Message loadMessage = gson.fromJson(lineElements[2], Message.class);
      controller.newMessage(loadMessage.id, loadMessage.author, messageConvo, loadMessage.content, loadMessage.creation);
      break;
    default:
      break;
  }
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:28,代码来源:Server.java

示例11: addToContributions

import codeu.chat.common.Message; //导入依赖的package包/类
private void addToContributions(Message newCurrentMessage, boolean newFoundMessage, Time lastUpdate, Uuid searchUser) {
  // go through every message
  while(currentMessage != null && foundMessage == false) {
    // check for a matching user UUID and a creation time after the last status update
    if(lastUpdate.compareTo(currentMessage.creation) < 0 && currentMessage.author.equals(searchUser)) {
      // add the conversation's title to the collection and break the loop for this conversation
      contributions.add(convoPayloadId.title);
      foundMessage = true;
    }
    currentMessage = model.messageById().first(currentMessage.next);
  }
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:13,代码来源:View.java

示例12: testAddMessage

import codeu.chat.common.Message; //导入依赖的package包/类
@Test
public void testAddMessage() {

  final User user = controller.newUser(userId, "user", Time.now());

  assertFalse(
      "Check that user has a valid reference",
      user == null);
  assertTrue(
      "Check that the user has the correct id",
      Uuid.equals(user.id, userId));

  final ConversationHeader conversation = controller.newConversation(
      conversationId,
      "conversation",
      user.id,
      Time.now());

  assertFalse(
      "Check that conversation has a valid reference",
      conversation == null);
  assertTrue(
      "Check that the conversation has the correct id",
      Uuid.equals(conversation.id, conversationId));

  final Message message = controller.newMessage(
      messageId,
      user.id,
      conversation.id,
      "Hello World",
      Time.now());

  assertFalse(
      "Check that the message has a valid reference",
      message == null);
  assertTrue(
      "Check that the message has the correct id",
      Uuid.equals(message.id, messageId));
}
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:40,代码来源:RawControllerTest.java

示例13: getAllMessages

import codeu.chat.common.Message; //导入依赖的package包/类
private void getAllMessages(ConversationSummary conversation) {
  messageListModel.clear();

  for (final Message m : clientContext.message.getConversationContents(conversation)) {
    // Display author name if available.  Otherwise display the author UUID.
    final String authorName = clientContext.user.getName(m.author);

    final String displayString = String.format("%s: [%s]: %s",
        ((authorName == null) ? m.author : authorName), m.creation, m.content);

    messageListModel.addElement(displayString);
  }
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:14,代码来源:MessagePanel.java

示例14: addMessage

import codeu.chat.common.Message; //导入依赖的package包/类
public void addMessage(Uuid author, Uuid conversation, String body) {
  final boolean validInputs = isValidBody(body) && (author != null) && (conversation != null);

  final Message message = (validInputs) ? controller.newMessage(author, conversation, body) : null;

  if (message == null) {
    System.out.format("Error: message not created - %s.\n",
        (validInputs) ? "server error" : "bad input value");
  } else {
    LOG.info("New message:, Author= %s UUID= %s", author, message.id);
    current = message;
  }
  updateMessages(false);
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:15,代码来源:ClientMessage.java

示例15: showAllMessages

import codeu.chat.common.Message; //导入依赖的package包/类
public void showAllMessages() {
  if (conversationContents.size() == 0) {
    System.out.println(" Current Conversation has no messages");
  } else {
    for (final Message m : conversationContents) {
      printMessage(m, userContext);
    }
  }
}
 
开发者ID:google,项目名称:codeu_project_2017,代码行数:10,代码来源:ClientMessage.java


注:本文中的codeu.chat.common.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。