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.server;
22
23 import static org.jboss.netty.channel.Channels.*;
24 import goldengate.commandexec.utils.LocalExecDefaultResult;
25
26 import org.jboss.netty.channel.Channel;
27 import org.jboss.netty.channel.ChannelPipeline;
28 import org.jboss.netty.channel.ChannelPipelineFactory;
29 import org.jboss.netty.channel.group.ChannelGroup;
30 import org.jboss.netty.channel.group.DefaultChannelGroup;
31 import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
32 import org.jboss.netty.handler.codec.frame.Delimiters;
33 import org.jboss.netty.handler.codec.string.StringDecoder;
34 import org.jboss.netty.handler.codec.string.StringEncoder;
35
36 /**
37 * Creates a newly configured {@link ChannelPipeline} for a new channel for LocalExecServer.
38 *
39 *
40 */
41 public class LocalExecServerPipelineFactory implements ChannelPipelineFactory {
42
43 private long delay = LocalExecDefaultResult.MAXWAITPROCESS;
44 private final ChannelGroup channelGroup = new DefaultChannelGroup("LocalExecServer");
45
46 /**
47 * Constructor with default delay
48 *
49 */
50 public LocalExecServerPipelineFactory() {
51 // Default delay
52 }
53
54 /**
55 * Constructor with a specific default delay
56 * @param newdelay
57 */
58 public LocalExecServerPipelineFactory(long newdelay) {
59 delay = newdelay;
60 }
61
62
63 public ChannelPipeline getPipeline() throws Exception {
64 // Create a default pipeline implementation.
65 ChannelPipeline pipeline = pipeline();
66
67 // Add the text line codec combination first,
68 pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
69 Delimiters.lineDelimiter()));
70 pipeline.addLast("decoder", new StringDecoder());
71 pipeline.addLast("encoder", new StringEncoder());
72
73 // and then business logic.
74 // Could change it with a new fixed delay if necessary at construction
75 pipeline.addLast("handler", new LocalExecServerHandler(this, delay));
76
77 return pipeline;
78 }
79 /**
80 * Add a channel to the ExecClient Group
81 * @param channel
82 */
83 public void addChannel(Channel channel) {
84 channelGroup.add(channel);
85 }
86 /**
87 * remove a channel to the ExecClient Group
88 * @param channel
89 */
90 public void removeChannel(Channel channel) {
91 channelGroup.remove(channel);
92 }
93 /**
94 * Release internal resources
95 */
96 public void releaseResources() {
97 channelGroup.close();
98 }
99 }