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 goldengate.commandexec.utils.LocalExecDefaultResult;
24 import goldengate.common.logging.GgSlf4JLoggerFactory;
25
26 import java.net.InetAddress;
27 import java.net.InetSocketAddress;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
30
31 import org.jboss.netty.bootstrap.ServerBootstrap;
32 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
33 import org.jboss.netty.logging.InternalLoggerFactory;
34
35 /**
36 * LocalExec server Main method.
37 *
38 *
39 */
40 public class LocalExecServer {
41
42 static ExecutorService threadPool;
43 static ExecutorService threadPool2;
44
45 /**
46 * Takes 3 optional arguments:<br>
47 * - no argument: implies 127.0.0.1 + 9999 port<br>
48 * - arguments:<br>
49 * "addresse" "port"<br>
50 * "addresse" "port" "default delay"<br>
51 * @param args
52 * @throws Exception
53 */
54 public static void main(String[] args) throws Exception {
55 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
56 int port = 9999;
57 InetAddress addr;
58 long delay = LocalExecDefaultResult.MAXWAITPROCESS;
59 if (args.length >=2) {
60 addr = InetAddress.getByName(args[0]);
61 port = Integer.parseInt(args[1]);
62 if (args.length > 2) {
63 delay = Long.parseLong(args[2]);
64 }
65 } else {
66 byte []loop = {127,0,0,1};
67 addr = InetAddress.getByAddress(loop);
68 }
69 threadPool = Executors.newCachedThreadPool();
70 threadPool2 = Executors.newCachedThreadPool();
71 // Configure the server.
72 ServerBootstrap bootstrap = new ServerBootstrap(
73 new NioServerSocketChannelFactory(threadPool, threadPool2));
74
75 // Configure the pipeline factory.
76 bootstrap.setPipelineFactory(new LocalExecServerPipelineFactory(delay));
77
78 // Bind and start to accept incoming connections only on local address.
79 bootstrap.bind(new InetSocketAddress(addr, port));
80 }
81 }