summaryrefslogtreecommitdiff
path: root/java/newclient/src/main/java/org/apache/qpid/nclient/core/PhaseFactory.java
blob: 21602fec8e7725b42960985746fc411fa1d3d0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.apache.qpid.nclient.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.qpid.nclient.config.ClientConfiguration;

public class PhaseFactory
{
    /**
     * This method will create the pipe and return a reference
     * to the top of the pipeline.
     * 
     * The application can then use this (top most) phase and all
     * calls will propogated down the pipe.
     * 
     * Simillar calls orginating at the bottom of the pipeline
     * will be propogated to the top.
     * 
     * @param ctx
     * @return
     * @throws AMQPException
     */
    public static Phase createPhasePipe(PhaseContext ctx) throws AMQPException
    {
	Map<Integer,Phase> phaseMap = new HashMap<Integer,Phase>();
	List<String> list = ClientConfiguration.get().getList(QpidConstants.PHASE_PIPE + "." + QpidConstants.PHASE);
	for(String s:list)
	{
	    try
	    {
		Phase temp = (Phase)Class.forName(ClientConfiguration.get().getString(s)).newInstance();
		phaseMap.put(ClientConfiguration.get().getInt(s + "." + QpidConstants.INDEX),temp) ;
	    }
	    catch(Exception e)
	    {
		throw new AMQPException("Error loading phase " + ClientConfiguration.get().getString(s),e);
	    }    
	}
	
	Phase current = null;
	Phase prev = null;
	Phase next = null;
	//Lets build the phase pipe.
	for (int i=0; i<phaseMap.size();i++)
	{
	   current = phaseMap.get(i);	   
	   if (1+1 < phaseMap.size())
	   {
	       next = phaseMap.get(i+1);
	   }
	   current.init(ctx, next, prev);
	   prev = current;
	   next = null;
	}
	
	return current;
    }
}