1 /**
2 This file is part of GoldenGate Project (named also GoldenGate or GG).
3
4 Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 individual contributors.
7
8 All GoldenGate Project is free software: you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published
10 by the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GoldenGate is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>.
20 */
21 package goldengate.commandexec.client;
22
23 import org.jboss.netty.channel.Channel;
24 import org.jboss.netty.channel.ChannelPipeline;
25 import org.jboss.netty.channel.ChannelPipelineFactory;
26 import org.jboss.netty.channel.Channels;
27 import org.jboss.netty.channel.group.ChannelGroup;
28 import org.jboss.netty.channel.group.DefaultChannelGroup;
29 import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
30 import org.jboss.netty.handler.codec.frame.Delimiters;
31 import org.jboss.netty.handler.codec.string.StringDecoder;
32 import org.jboss.netty.handler.codec.string.StringEncoder;
33
34 /**
35 * Creates a newly configured {@link ChannelPipeline} for a new channel for LocalExecClientTest.
36 *
37 *
38 *
39 */
40 public class LocalExecClientPipelineFactory implements ChannelPipelineFactory {
41
42 private final ChannelGroup channelGroup;
43
44 public LocalExecClientPipelineFactory() {
45 channelGroup = new DefaultChannelGroup("LocalExecClient");
46 }
47
48 public ChannelPipeline getPipeline() throws Exception {
49 // Create a default pipeline implementation.
50 ChannelPipeline pipeline = Channels.pipeline();
51
52 // Add the text line codec combination first,
53 pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
54 Delimiters.lineDelimiter()));
55 pipeline.addLast("decoder", new StringDecoder());
56 pipeline.addLast("encoder", new StringEncoder());
57
58 // and then business logic.
59 LocalExecClientHandler localExecClientHandler = new LocalExecClientHandler(this);
60 pipeline.addLast("handler", localExecClientHandler);
61
62 return pipeline;
63 }
64 /**
65 * Add a channel to the ExecClient Group
66 * @param channel
67 */
68 public void addChannel(Channel channel) {
69 channelGroup.add(channel);
70 }
71 /**
72 * remove a channel to the ExecClient Group
73 * @param channel
74 */
75 public void removeChannel(Channel channel) {
76 channelGroup.remove(channel);
77 }
78 /**
79 * Release internal resources
80 */
81 public void releaseResources() {
82 channelGroup.close();
83 }
84 }