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 private static final String CLASS_NAME = RemoteManager.class.getCanonicalName(); 036 037 private final org.apache.reef.wake.remote.RemoteManager raw; 038 private final RemoteIdentifierFactory factory; 039 040 @Inject 041 public RemoteManager(final org.apache.reef.wake.remote.RemoteManager raw, 042 final RemoteIdentifierFactory factory) { 043 this.raw = raw; 044 this.factory = factory; 045 LOG.log(Level.FINE, "Instantiated RemoteManager wrapper: {0}", this.raw); 046 } 047 048 public final org.apache.reef.wake.remote.RemoteManager raw() { 049 return this.raw; 050 } 051 052 public void close() throws Exception { 053 LOG.entering(CLASS_NAME, "close"); 054 this.raw.close(); 055 LOG.exiting(CLASS_NAME, "close"); 056 } 057 058 public <T> EventHandler<T> getHandler( 059 final String destinationIdentifier, final Class<? extends T> messageType) { 060 return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType); 061 } 062 063 public <T, U extends T> AutoCloseable registerHandler( 064 final String sourceIdentifier, final Class<U> messageType, 065 final EventHandler<T> theHandler) { 066 return this.raw.registerHandler(factory.getNewInstance(sourceIdentifier), messageType, theHandler); 067 } 068 069 public <T, U extends T> AutoCloseable registerHandler( 070 final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) { 071 return this.raw.registerHandler(messageType, theHandler); 072 } 073 074 public String getMyIdentifier() { 075 return this.raw.getMyIdentifier().toString(); 076 } 077 078 @Override 079 public String toString() { 080 return "RemoteManager wrap: " + this.raw; 081 } 082}