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.io.network.impl; 020 021import org.apache.reef.io.network.TransportFactory; 022import org.apache.reef.wake.EventHandler; 023import org.apache.reef.wake.impl.SyncStage; 024import org.apache.reef.wake.remote.NetUtils; 025import org.apache.reef.wake.remote.impl.TransportEvent; 026import org.apache.reef.wake.remote.transport.Transport; 027import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport; 028 029import javax.inject.Inject; 030 031/** 032 * Factory that creates a messaging transport 033 */ 034public class MessagingTransportFactory implements TransportFactory { 035 036 @Inject 037 public MessagingTransportFactory() { 038 } 039 040 /** 041 * Creates a transport 042 * 043 * @param port a listening port 044 * @param clientHandler a transport client side handler 045 * @param serverHandler a transport server side handler 046 * @param exHandler a exception handler 047 */ 048 @Override 049 public Transport create(final int port, 050 final EventHandler<TransportEvent> clientHandler, 051 final EventHandler<TransportEvent> serverHandler, 052 final EventHandler<Exception> exHandler) { 053 054 final Transport transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), 055 port, new SyncStage<>(clientHandler), new SyncStage<>(serverHandler), 3, 10000); 056 057 transport.registerErrorHandler(exHandler); 058 return transport; 059 } 060}