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.client;
22  
23  import java.util.concurrent.ExecutorService;
24  import java.util.concurrent.Executors;
25  
26  import org.jboss.netty.channel.ChannelPipeline;
27  import org.jboss.netty.channel.Channels;
28  import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
29  import org.jboss.netty.handler.codec.frame.Delimiters;
30  import org.jboss.netty.handler.codec.string.StringDecoder;
31  import org.jboss.netty.handler.codec.string.StringEncoder;
32  
33  import goldengate.commandexec.client.LocalExecClientHandler;
34  import goldengate.commandexec.client.LocalExecClientPipelineFactory;
35  import goldengate.common.crypto.ssl.GgSslContextFactory;
36  
37  /**
38   * Version with SSL support
39   *
40   *
41   * @author Frederic Bregier
42   *
43   */
44  public class LocalExecSslClientPipelineFactory extends LocalExecClientPipelineFactory {
45  
46      private final GgSslContextFactory ggSslContextFactory;
47      private final ExecutorService executor = Executors.newCachedThreadPool();
48  
49      public LocalExecSslClientPipelineFactory(GgSslContextFactory ggSslContextFactory) {
50          this.ggSslContextFactory = ggSslContextFactory;
51      }
52  
53      public ChannelPipeline getPipeline() throws Exception {
54          // Create a default pipeline implementation.
55          ChannelPipeline pipeline = Channels.pipeline();
56  
57          // Add SSL as first element in the pipeline
58          pipeline.addLast("ssl",
59                  ggSslContextFactory.initPipelineFactory(false,
60                  ggSslContextFactory.needClientAuthentication(), false, executor));
61          // Add the text line codec combination first,
62          pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
63                  Delimiters.lineDelimiter()));
64          pipeline.addLast("decoder", new StringDecoder());
65          pipeline.addLast("encoder", new StringEncoder());
66  
67          // and then business logic.
68          LocalExecClientHandler localExecClientHandler = new LocalExecClientHandler(this);
69          pipeline.addLast("handler", localExecClientHandler);
70  
71          return pipeline;
72      }
73      /**
74       * Release internal resources
75       */
76      public void releaseResources() {
77          super.releaseResources();
78          this.executor.shutdownNow();
79      }
80  
81  }