View Javadoc

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.ssl.server;
22  
23  import static org.jboss.netty.channel.Channels.pipeline;
24  
25  import java.util.concurrent.ExecutorService;
26  import java.util.concurrent.Executors;
27  
28  import org.jboss.netty.channel.ChannelPipeline;
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  import goldengate.commandexec.server.LocalExecServerHandler;
35  import goldengate.commandexec.server.LocalExecServerPipelineFactory;
36  import goldengate.commandexec.utils.LocalExecDefaultResult;
37  import goldengate.common.crypto.ssl.GgSslContextFactory;
38  
39  /**
40   * Version with SSL support
41   *
42   * @author Frederic Bregier
43   *
44   */
45  public class LocalExecSslServerPipelineFactory extends LocalExecServerPipelineFactory {
46  
47      private final GgSslContextFactory ggSslContextFactory;
48      private final ExecutorService executor = Executors.newCachedThreadPool();
49  
50      private long delay = LocalExecDefaultResult.MAXWAITPROCESS;
51  
52      /**
53       * Constructor with default delay
54       * @param ggSslContextFactory
55       */
56      public LocalExecSslServerPipelineFactory(GgSslContextFactory ggSslContextFactory) {
57          // Default delay
58          this.ggSslContextFactory = ggSslContextFactory;
59      }
60  
61      /**
62       * Constructor with a specific default delay
63       * @param ggSslContextFactory
64       * @param newdelay
65       */
66      public LocalExecSslServerPipelineFactory(GgSslContextFactory ggSslContextFactory, long newdelay) {
67          delay = newdelay;
68          this.ggSslContextFactory = ggSslContextFactory;
69      }
70  
71      public ChannelPipeline getPipeline() throws Exception {
72          // Create a default pipeline implementation.
73          ChannelPipeline pipeline = pipeline();
74  
75          // Add SSL as first element in the pipeline
76          pipeline.addLast("ssl",
77                  ggSslContextFactory.initPipelineFactory(true,
78                          ggSslContextFactory.needClientAuthentication(), false, executor));
79          // Add the text line codec combination first,
80          pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
81                  Delimiters.lineDelimiter()));
82          pipeline.addLast("decoder", new StringDecoder());
83          pipeline.addLast("encoder", new StringEncoder());
84  
85          // and then business logic.
86          // Could change it with a new fixed delay if necessary at construction
87          pipeline.addLast("handler", new LocalExecServerHandler(this, delay));
88  
89          return pipeline;
90      }
91  
92      /**
93       * Release internal resources
94       */
95      public void releaseResources() {
96          super.releaseResources();
97          this.executor.shutdownNow();
98      }
99  
100 }