/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.storm.messaging;

import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import org.apache.storm.Config;

public class TransportFactory {
    public static final Logger LOG = LoggerFactory.getLogger(TransportFactory.class);

    public static IContext makeContext(Map storm_conf) {

        //get factory class name
        String transport_plugin_klassName = (String)storm_conf.get(Config.STORM_MESSAGING_TRANSPORT);
        LOG.info("Storm peer transport plugin:"+transport_plugin_klassName);

        IContext transport;
        try {
            //create a factory class
            Class klass = Class.forName(transport_plugin_klassName);
            //obtain a context object
            Object obj = klass.newInstance();
            if (obj instanceof IContext) {
                //case 1: plugin is a IContext class
                transport = (IContext)obj;
                //initialize with storm configuration
                transport.prepare(storm_conf);
            } else {
                //case 2: Non-IContext plugin must have a makeContext(storm_conf) method that returns IContext object
                Method method = klass.getMethod("makeContext", Map.class);
                LOG.debug("object:"+obj+" method:"+method);
                transport = (IContext) method.invoke(obj, storm_conf);
            }
        } catch(Exception e) {
            throw new RuntimeException("Fail to construct messaging plugin from plugin "+transport_plugin_klassName, e);
        } 
        return transport;
    }
}

@@ -421,16 +421,20 @@
 se at%0A *
+ %3Cp%3E
 %0A * http
@@ -474,16 +474,20 @@
 E-2.0%0A *
+ %3Cp%3E
 %0A * Unle
@@ -852,21 +852,31 @@
 ort 
-java.util.Map
+org.apache.storm.Config
 ;%0Aim
@@ -930,16 +930,17 @@
 actory;%0A
+%0A
 import j
@@ -971,39 +971,29 @@
 %0Aimport 
-org.apache.storm.Config
+java.util.Map
 ;%0A%0Apubli
@@ -1102,24 +1102,207 @@
 ry.class);%0A%0A
+    static private final String JXIO_CONTEXT = %22org.apache.storm.messaging.jxio.Context%22;%0A    static private final String NETTY_CONTEXT = %22org.apache.storm.messaging.netty.Context%22;%0A%0A
     public s
@@ -1424,16 +1424,23 @@
 sName = 
+null;//
 (String)
@@ -1489,16 +1489,451 @@
 SPORT);%0A
+        String transport_mode = (String) storm_conf.get(Config.STORM_MESSAGING_TRANSFER_MODE);%0A%0A        //choose which plugin used%0A        if (%22RDMA%22.equals(transport_mode))%0A            transport_plugin_klassName = JXIO_CONTEXT;%0A        else if (%22Netty%22.equals(transport_mode))%0A            transport_plugin_klassName = NETTY_CONTEXT;%0A        else%0A            throw new RuntimeException(%22can't read context (%22 + transport_mode + %22) %22);%0A
         
@@ -1971,17 +1971,19 @@
 plugin:%22
-+
+ + 
 transpor
@@ -2370,16 +2370,17 @@
 Context)
+ 
 obj;%0A   
@@ -2730,13 +2730,17 @@
 ct:%22
-+obj+
+ + obj + 
 %22 me
@@ -2745,17 +2745,19 @@
 method:%22
-+
+ + 
 method);
@@ -2857,16 +2857,17 @@
  %7D catch
+ 
 (Excepti
@@ -2962,17 +2962,19 @@
 plugin %22
-+
+ + 
 transpor
@@ -3006,17 +3006,16 @@
        %7D
- 
 %0A       

Add property for select which messaging plugin use.