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.runtime.mesos.util; 020 021import org.apache.reef.wake.EventHandler; 022import org.apache.reef.wake.remote.RemoteIdentifierFactory; 023import org.apache.reef.wake.remote.RemoteManager; 024import org.apache.reef.wake.remote.RemoteManagerFactory; 025import org.apache.reef.wake.remote.RemoteMessage; 026 027import javax.inject.Inject; 028 029/** 030 * Since the existing RemoteManager cannot use an additional codec, 031 * we need this additional RemoteManager to use MesosMessageCodec. 032 * TODO[JIRA REEF-103]: Replace this class once Tang's namespace feature is enabled 033 */ 034public final class MesosRemoteManager { 035 private final RemoteManager raw; 036 private final RemoteIdentifierFactory factory; 037 038 @Inject 039 MesosRemoteManager(final RemoteIdentifierFactory factory, 040 final MesosErrorHandler mesosErrorHandler, 041 final MesosRemoteManagerCodec codec, 042 final RemoteManagerFactory remoteManagerFactory) { 043 this.factory = factory; 044 this.raw = remoteManagerFactory.getInstance("MESOS_EXECUTOR", codec, mesosErrorHandler); 045 046 047 } 048 049 public <T> EventHandler<T> getHandler( 050 final String destinationIdentifier, final Class<? extends T> messageType) { 051 return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType); 052 } 053 054 public <T, U extends T> AutoCloseable registerHandler( 055 final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) { 056 return this.raw.registerHandler(messageType, theHandler); 057 } 058 059 public String getMyIdentifier() { 060 return this.raw.getMyIdentifier().toString(); 061 } 062}