001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.evaluator.context;
020
021
022import org.apache.reef.annotations.Provided;
023import org.apache.reef.annotations.audience.EvaluatorSide;
024import org.apache.reef.annotations.audience.Public;
025import org.apache.reef.io.Message;
026
027/**
028 * Evaluator-side representation of a message sent from an Evaluator to a Driver.
029 */
030@EvaluatorSide
031@Public
032@Provided
033public final class ContextMessage implements Message {
034
035  private final String messageSourceID;
036  private final byte[] theBytes;
037
038  private ContextMessage(final String messageSourceID, final byte[] theBytes) {
039    this.messageSourceID = messageSourceID;
040    this.theBytes = theBytes;
041  }
042
043  /**
044   * @param messageSourceID The message's sourceID. This will be accessible in the Driver for routing.
045   * @param theBytes        The actual content of the message, serialized into a byte[]
046   * @return a new EvaluatorMessage with the given content.
047   */
048  public static ContextMessage from(final String messageSourceID, final byte[] theBytes) {
049    assert theBytes != null && messageSourceID != null;
050    return new ContextMessage(messageSourceID, theBytes);
051  }
052
053  /**
054   * @return the message source identifier.
055   */
056  public String getMessageSourceID() {
057    return this.messageSourceID;
058  }
059
060  /**
061   * @return the message
062   */
063  @Override
064  public byte[] get() {
065    return this.theBytes;
066  }
067
068
069}