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 openr66.client;
22  
23  import java.sql.Timestamp;
24  
25  import goldengate.common.database.data.AbstractDbData;
26  import goldengate.common.database.exception.GoldenGateDatabaseException;
27  import goldengate.common.logging.GgInternalLoggerFactory;
28  import goldengate.common.logging.GgSlf4JLoggerFactory;
29  import openr66.context.ErrorCode;
30  import openr66.context.R66Result;
31  import openr66.database.DbConstant;
32  import openr66.database.data.DbTaskRunner;
33  import openr66.protocol.exception.OpenR66DatabaseGlobalException;
34  import openr66.protocol.utils.ChannelUtils;
35  import openr66.protocol.utils.R66Future;
36  
37  import org.jboss.netty.logging.InternalLoggerFactory;
38  
39  /**
40   * Client to submit a transfer
41   *
42   * @author Frederic Bregier
43   *
44   */
45  public class SubmitTransfer extends AbstractTransfer {
46  
47      public SubmitTransfer(R66Future future, String remoteHost,
48              String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, long id,
49              Timestamp starttime) {
50          super(SubmitTransfer.class,
51                  future, filename, rulename, fileinfo, isMD5, remoteHost, blocksize, id, starttime);
52      }
53  
54      public void run() {
55          if (logger == null) {
56              logger = GgInternalLoggerFactory.getLogger(SubmitTransfer.class);
57          }
58          DbTaskRunner taskRunner = this.initRequest();
59          taskRunner.changeUpdatedInfo(AbstractDbData.UpdatedInfo.TOSUBMIT);
60          try {
61              taskRunner.update();
62          } catch (GoldenGateDatabaseException e) {
63              logger.debug("Cannot prepare task", e);
64              R66Result result = new R66Result(new OpenR66DatabaseGlobalException(e), null, true,
65                      ErrorCode.Internal, taskRunner);
66              future.setResult(result);
67              future.setFailure(e);
68              return;
69          }
70          R66Result result = new R66Result(null,false,ErrorCode.InitOk, taskRunner);
71          future.setResult(result);
72          future.setSuccess();
73      }
74      /**
75       *
76       * @param args
77       *          configuration file, the remoteHost Id, the file to transfer,
78       *          the rule, file transfer information as arguments and
79       *          optionally isMD5=1 for true or 0 for false(default)
80       *          and the blocksize if different than default
81       */
82      public static void main(String[] args) {
83          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
84          if (logger == null) {
85              logger = GgInternalLoggerFactory.getLogger(SubmitTransfer.class);
86          }
87          if (! getParams(args, true)) {
88              logger.error("Wrong initialization");
89              if (DbConstant.admin != null && DbConstant.admin.isConnected) {
90                  DbConstant.admin.close();
91              }
92              ChannelUtils.stopLogger();
93              System.exit(1);
94          }
95          R66Future future = new R66Future(true);
96          SubmitTransfer transaction = new SubmitTransfer(future,
97                  rhost, localFilename, rule, fileInfo, ismd5, block, DbConstant.ILLEGALVALUE, ttimestart);
98          transaction.run();
99          future.awaitUninterruptibly();
100         DbTaskRunner runner = future.getResult().runner;
101         if (future.isSuccess()) {
102             logger.warn("Prepare transfer in\n    SUCCESS\n    "+runner.toShortString()+
103                             "<REMOTE>"+rhost+"</REMOTE>");
104         } else {
105             if (runner != null) {
106                 logger.error("Prepare transfer in\n    FAILURE\n     "+runner.toShortString()+
107                             "<REMOTE>"+rhost+"</REMOTE>", future.getCause());
108             } else {
109                 logger.error("Prepare transfer in\n    FAILURE\n     ", future.getCause());
110             }
111             DbConstant.admin.close();
112             ChannelUtils.stopLogger();
113             System.exit(future.getResult().code.ordinal());
114         }
115         DbConstant.admin.close();
116     }
117 
118 }