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.javabridge;
020
021import org.apache.commons.lang.NotImplementedException;
022import org.apache.reef.annotations.audience.Interop;
023import org.apache.reef.annotations.audience.Private;
024import org.apache.reef.driver.context.ContextMessage;
025
026/**
027 * The Java-CLR bridge object for {@link org.apache.reef.driver.context.ContextMessage}.
028 */
029@Private
030@Interop(
031    CppFiles = { "Clr2JavaImpl.h", "ContextMessageClr2Java.cpp" },
032    CsFiles = { "IContextMessageClr2Java.cs", "ContextMessage.cs" })
033public final class ContextMessageBridge extends NativeBridge implements ContextMessage {
034
035  private ContextMessage jcontextMessage;
036  private String contextMessageId;
037  private String messageSourceId;
038  private byte[] message;
039
040  public ContextMessageBridge(final ContextMessage contextMessage) {
041    jcontextMessage = contextMessage;
042    contextMessageId = contextMessage.getId();
043    messageSourceId = contextMessage.getMessageSourceID();
044    message = contextMessage.get();
045  }
046
047  @Override
048  public void close() throws Exception {
049
050  }
051
052  @Override
053  public byte[] get() {
054    return message;
055  }
056
057  @Override
058  public String getId() {
059    return contextMessageId;
060  }
061
062  @Override
063  public String getMessageSourceID() {
064    return messageSourceId;
065  }
066
067  @Override
068  public long getSequenceNumber(){
069    // TODO[REEF-1085] once REEF.NET supports sequence numbers, ensure the numbers
070    // can propagate between C# and Java implementations
071    throw new NotImplementedException("A Java-CLR bridge lacks support of sequence numbers on the REEF.NET side.");
072  }
073}