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.context.task;
22  
23  import goldengate.common.logging.GgInternalLogger;
24  import goldengate.common.logging.GgInternalLoggerFactory;
25  
26  import java.io.File;
27  
28  import openr66.context.R66Session;
29  import openr66.protocol.exception.OpenR66ProtocolSystemException;
30  import openr66.protocol.utils.FileUtils;
31  
32  /**
33   * Copy task
34   * @author Frederic Bregier
35   *
36   */
37  public class CopyTask extends AbstractTask {
38      /**
39       * Internal Logger
40       */
41      private static final GgInternalLogger logger = GgInternalLoggerFactory
42              .getLogger(CopyTask.class);
43  
44      /**
45       * @param argRule
46       * @param delay
47       * @param argTransfer
48       * @param session
49       */
50      public CopyTask(String argRule, int delay, String argTransfer,
51              R66Session session) {
52          super(TaskType.COPY, delay, argRule, argTransfer, session);
53      }
54  
55      /*
56       * (non-Javadoc)
57       *
58       * @see openr66.context.task.AbstractTask#run()
59       */
60      @Override
61      public void run() {
62          logger.info("Copy with " + argRule + ":" + argTransfer + " and {}",
63                  session);
64          File from = session.getFile().getTrueFile();
65          File to = new File(argRule + session.getFile().getBasename());
66          try {
67              FileUtils.copy(from, to, false, false);
68          } catch (OpenR66ProtocolSystemException e1) {
69              logger.error("Copy with " + argRule + ":" + argTransfer + " and " +
70                      session, e1);
71              futureCompletion.setFailure(new OpenR66ProtocolSystemException(e1));
72              return;
73          }
74          futureCompletion.setSuccess();
75      }
76  
77  }