1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.ftp.core.control;
22
23 import goldengate.common.command.ReplyCode;
24 import goldengate.ftp.core.config.FtpConfiguration;
25 import goldengate.ftp.core.session.FtpSession;
26
27 import org.jboss.netty.buffer.ChannelBuffer;
28 import org.jboss.netty.buffer.ChannelBuffers;
29 import org.jboss.netty.channel.ChannelPipeline;
30 import org.jboss.netty.channel.ChannelPipelineFactory;
31 import org.jboss.netty.channel.Channels;
32 import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
33 import org.jboss.netty.handler.execution.ExecutionHandler;
34
35
36
37
38
39
40
41 public class FtpPipelineFactory implements ChannelPipelineFactory {
42
43
44
45 private static final ChannelBuffer[] delimiter = new ChannelBuffer[] {
46 ChannelBuffers.wrappedBuffer(ReplyCode.CRLF.getBytes()),
47 ChannelBuffers.wrappedBuffer(ReplyCode.CRNUL.getBytes()),
48 ChannelBuffers.wrappedBuffer(ReplyCode.LF.getBytes()) };
49
50 private static final FtpControlStringDecoder ftpControlStringDecoder = new FtpControlStringDecoder();
51
52 private static final FtpControlStringEncoder ftpControlStringEncoder = new FtpControlStringEncoder();
53
54
55
56
57 private final Class<? extends BusinessHandler> businessHandler;
58
59
60
61
62 private final FtpConfiguration configuration;
63
64
65
66
67
68
69
70 public FtpPipelineFactory(Class<? extends BusinessHandler> businessHandler,
71 FtpConfiguration configuration) {
72 this.businessHandler = businessHandler;
73 this.configuration = configuration;
74 }
75
76
77
78
79
80
81 public ChannelPipeline getPipeline() throws Exception {
82 ChannelPipeline pipeline = Channels.pipeline();
83
84 pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
85 delimiter));
86 pipeline.addLast("decoder", ftpControlStringDecoder);
87 pipeline.addLast("encoder", ftpControlStringEncoder);
88
89 pipeline.addLast("pipelineExecutor", new ExecutionHandler(configuration
90 .getFtpInternalConfiguration().getPipelineExecutor()));
91
92 BusinessHandler newbusiness = businessHandler.newInstance();
93 NetworkHandler newNetworkHandler = new NetworkHandler(new FtpSession(
94 configuration, newbusiness));
95 pipeline.addLast("handler", newNetworkHandler);
96 return pipeline;
97 }
98 }