1 /**
2 * Copyright 2009, Frederic Bregier, and individual contributors by the @author
3 * tags. See the COPYRIGHT.txt in the distribution for a full listing of
4 * individual contributors.
5 *
6 * This is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation; either version 3.0 of the License, or (at your option)
9 * any later version.
10 *
11 * This software is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this software; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
19 * site: http://www.fsf.org.
20 */
21 package goldengate.ftp.exec.config;
22
23 /**
24 * Circular Value used by passive connections to find the next valid port to
25 * propose to the client.
26 *
27 * @author Frederic Bregier
28 *
29 */
30 public class CircularIntValue {
31 /**
32 * Min value
33 */
34 private final int min;
35
36 /**
37 * Max value
38 */
39 private final int max;
40
41 /**
42 * Current Value
43 */
44 private Integer current;
45
46 /**
47 * Create a circular range of values
48 *
49 * @param min
50 * @param max
51 */
52 public CircularIntValue(int min, int max) {
53 this.min = min;
54 this.max = max;
55 current = this.min;
56 }
57
58 /**
59 * Get the next value
60 *
61 * @return the next value
62 */
63 public int getNext() {
64 synchronized (current) {
65 if (current >= max) {
66 current = min;
67 } else {
68 current++;
69 }
70 return current;
71 }
72 }
73 }