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.ftp.core.command.internal;
22  
23  import goldengate.common.command.ReplyCode;
24  import goldengate.common.command.exception.Reply500Exception;
25  import goldengate.common.command.exception.Reply501Exception;
26  import goldengate.ftp.core.command.AbstractCommand;
27  
28  /**
29   * Internal limit bandwidth command that will change the global limit bandwidth
30   *
31   * @author Frederic Bregier
32   *
33   */
34  public class LIMITBANDWIDTH extends AbstractCommand {
35      /*
36       * (non-Javadoc)
37       *
38       * @see goldengate.ftp.core.command.AbstractCommand#exec()
39       */
40      public void exec() throws Reply501Exception, Reply500Exception {
41          if (!getSession().getAuth().isAdmin()) {
42              // not admin
43              throw new Reply500Exception("Command Not Allowed");
44          }
45          if (!hasArg()) {
46              // reset to default
47              getConfiguration().changeNetworkLimit(0, 0);
48              getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
49                      "Limit reset to default");
50              return;
51          }
52          String[] limits = getArgs();
53          long writeLimit = 0;
54          long readLimit = 0;
55          try {
56              if (limits.length == 1) {
57                  writeLimit = Long.parseLong(limits[0]);
58                  readLimit = writeLimit;
59              } else {
60                  writeLimit = Long.parseLong(limits[0]);
61                  readLimit = Long.parseLong(limits[1]);
62              }
63          } catch (NumberFormatException e) {
64              throw new Reply501Exception(getCommand() +
65                      " ([write and read limits in b/s] | [write limit in b/s] [read limit in b/s]");
66          }
67          getConfiguration().changeNetworkLimit(writeLimit, readLimit);
68          getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
69                  "Limit set to new values");
70      }
71  
72  }