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.common.utils; 020 021import org.apache.reef.wake.EventHandler; 022import org.apache.reef.wake.remote.RemoteIdentifierFactory; 023import org.apache.reef.wake.remote.RemoteMessage; 024 025import javax.inject.Inject; 026import java.util.logging.Level; 027import java.util.logging.Logger; 028 029/** 030 * Wrapper for org.apache.reef.wake.remote.RemoteManager. 031 */ 032public class RemoteManager { 033 034 private static final Logger LOG = Logger.getLogger(RemoteManager.class.getName()); 035 036 private final org.apache.reef.wake.remote.RemoteManager raw; 037 private final RemoteIdentifierFactory factory; 038 039 @Inject 040 public RemoteManager(final org.apache.reef.wake.remote.RemoteManager raw, 041 final RemoteIdentifierFactory factory) { 042 this.raw = raw; 043 this.factory = factory; 044 LOG.log(Level.FINE, "Instantiated 'RemoteManager' with remoteId: {0}", this.getMyIdentifier()); 045 } 046 047 public final org.apache.reef.wake.remote.RemoteManager raw() { 048 return this.raw; 049 } 050 051 public void close() throws Exception { 052 this.raw.close(); 053 } 054 055 public <T> EventHandler<T> getHandler( 056 final String destinationIdentifier, final Class<? extends T> messageType) { 057 return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType); 058 } 059 060 public <T, U extends T> AutoCloseable registerHandler( 061 final String sourceIdentifier, final Class<U> messageType, 062 final EventHandler<T> theHandler) { 063 return this.raw.registerHandler(factory.getNewInstance(sourceIdentifier), messageType, theHandler); 064 } 065 066 public <T, U extends T> AutoCloseable registerHandler( 067 final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) { 068 return this.raw.registerHandler(messageType, theHandler); 069 } 070 071 // TODO[JIRA REEF-547]: This method uses deprecated raw.registerErrorHandler. 072 /** 073 * @deprecated in 0.14, will be deleted in 0.15 074 */ 075 @Deprecated 076 public AutoCloseable registerErrorHandler(final EventHandler<Exception> theHandler) { 077 return this.raw.registerErrorHandler(theHandler); 078 } 079 080 public String getMyIdentifier() { 081 return this.raw.getMyIdentifier().toString(); 082 } 083} 084