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 029public class RemoteManager { 030 031 private static final Logger LOG = Logger.getLogger(RemoteManager.class.getName()); 032 033 private final org.apache.reef.wake.remote.RemoteManager raw; 034 private final RemoteIdentifierFactory factory; 035 036 @Inject 037 public RemoteManager(final org.apache.reef.wake.remote.RemoteManager raw, 038 final RemoteIdentifierFactory factory) { 039 this.raw = raw; 040 this.factory = factory; 041 LOG.log(Level.FINE, "Instantiated 'RemoteManager' with remoteId: {0}", this.getMyIdentifier()); 042 } 043 044 public final org.apache.reef.wake.remote.RemoteManager raw() { 045 return this.raw; 046 } 047 048 public void close() throws Exception { 049 this.raw.close(); 050 } 051 052 public <T> EventHandler<T> getHandler( 053 final String destinationIdentifier, final Class<? extends T> messageType) { 054 return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType); 055 } 056 057 public <T, U extends T> AutoCloseable registerHandler( 058 final String sourceIdentifier, final Class<U> messageType, 059 final EventHandler<T> theHandler) { 060 return this.raw.registerHandler(factory.getNewInstance(sourceIdentifier), messageType, theHandler); 061 } 062 063 public <T, U extends T> AutoCloseable registerHandler( 064 final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) { 065 return this.raw.registerHandler(messageType, theHandler); 066 } 067 068 public AutoCloseable registerErrorHandler(final EventHandler<Exception> theHandler) { 069 return this.raw.registerErrorHandler(theHandler); 070 } 071 072 public String getMyIdentifier() { 073 return this.raw.getMyIdentifier().toString(); 074 } 075} 076