Skip to content

Commit e1ba76c

Browse files
committed
Minor fixes from code review
1 parent 685c145 commit e1ba76c

8 files changed

Lines changed: 21 additions & 21 deletions

File tree

java/org/apache/catalina/tribes/group/ChannelCoordinator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ protected synchronized void internalStart(int svc) throws ChannelException {
213213
*
214214
* @param svc int value of <BR>
215215
* DEFAULT - will shutdown all services <BR>
216-
* MBR_RX_SEQ - starts the membership receiver <BR>
217-
* MBR_TX_SEQ - starts the membership broadcaster <BR>
218-
* SND_TX_SEQ - starts the replication transmitter<BR>
219-
* SND_RX_SEQ - starts the replication receiver<BR>
216+
* MBR_RX_SEQ - stops the membership receiver <BR>
217+
* MBR_TX_SEQ - stops the membership broadcaster <BR>
218+
* SND_TX_SEQ - stops the replication transmitter<BR>
219+
* SND_RX_SEQ - stops the replication receiver<BR>
220220
*
221221
* @throws ChannelException if a startup error occurs or the service is already started.
222222
*/
@@ -260,7 +260,9 @@ protected synchronized void internalStop(int svc) throws ChannelException {
260260
}
261261

262262
startLevel = (startLevel & (~svc));
263-
setChannel(null);
263+
if (startLevel == 0) {
264+
setChannel(null);
265+
}
264266
} catch (Exception e) {
265267
throw new ChannelException(e);
266268
}

java/org/apache/catalina/tribes/group/GroupChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public class GroupChannel extends ChannelInterceptorBase implements ManagedChann
119119
protected final List<ChannelListener> channelListeners = new CopyOnWriteArrayList<>();
120120

121121
/**
122-
* If set to true, the GroupChannel will check to make sure that
122+
* If set to true, the GroupChannel will throw an error upon start if two interceptors
123+
* are using the same option flag.
123124
*/
124125
protected boolean optionCheck = false;
125126

java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,9 @@ public void messageReceived(ChannelMessage msg) {
162162
*/
163163
@Override
164164
public void setEncryptionAlgorithm(String algorithm) {
165-
if (null == getEncryptionAlgorithm()) {
166-
throw new IllegalStateException(sm.getString("encryptInterceptor.algorithm.required"));
165+
if (algorithm == null) {
166+
throw new IllegalArgumentException(sm.getString("encryptInterceptor.algorithm.required"));
167167
}
168-
169168
int pos = algorithm.indexOf('/');
170169
if (pos < 0) {
171170
throw new IllegalArgumentException(sm.getString("encryptInterceptor.algorithm.required"));

java/org/apache/catalina/tribes/io/XByteBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ public static byte[] createDataPackage(ChannelData cdata) {
473473
* @return the output buffer
474474
*/
475475
public static byte[] createDataPackage(byte[] data, int doff, int dlength, byte[] buffer, int bufoff) {
476-
if ((buffer.length - bufoff) > getDataPackageLength(dlength)) {
476+
if ((buffer.length - bufoff) < getDataPackageLength(dlength)) {
477477
throw new ArrayIndexOutOfBoundsException(sm.getString("xByteBuffer.unableCreate"));
478478
}
479479
System.arraycopy(START_DATA, 0, buffer, bufoff, START_DATA.length);
480-
toBytes(data.length, buffer, bufoff + START_DATA.length);
480+
toBytes(dlength, buffer, bufoff + START_DATA.length);
481481
System.arraycopy(data, doff, buffer, bufoff + START_DATA.length + 4, dlength);
482-
System.arraycopy(END_DATA, 0, buffer, bufoff + START_DATA.length + 4 + data.length, END_DATA.length);
482+
System.arraycopy(END_DATA, 0, buffer, bufoff + START_DATA.length + 4 + dlength, END_DATA.length);
483483
return buffer;
484484
}
485485

java/org/apache/catalina/tribes/membership/cloud/DNSMembershipProvider.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.Serializable;
2121
import java.net.InetAddress;
22-
import java.net.URLEncoder;
2322
import java.net.UnknownHostException;
2423
import java.nio.charset.StandardCharsets;
2524
import java.util.ArrayList;
@@ -132,7 +131,6 @@ public void start(int level) throws Exception {
132131
if (log.isDebugEnabled()) {
133132
log.debug(sm.getString("cloudMembershipProvider.start", dnsServiceName));
134133
}
135-
dnsServiceName = URLEncoder.encode(dnsServiceName, StandardCharsets.UTF_8);
136134

137135
// Fetch initial members
138136
heartbeat();
@@ -204,11 +202,12 @@ public boolean accept(Serializable msg, Member sender) {
204202
byte[] host = sender.getHost();
205203
int i = 0;
206204
StringBuilder buf = new StringBuilder();
207-
buf.append(host[i++] & 0xff);
208-
for (; i < host.length; i++) {
209-
buf.append('.').append(host[i] & 0xff);
205+
if (host.length > 0 ) {
206+
buf.append(host[i++] & 0xff);
207+
for (; i < host.length; i++) {
208+
buf.append('.').append(host[i] & 0xff);
209+
}
210210
}
211-
212211
byte[] id = digest(buf.toString().getBytes(StandardCharsets.US_ASCII));
213212
member.setUniqueId(id);
214213
member.setMemberAliveTime(-1);

java/org/apache/catalina/tribes/transport/nio/NioSender.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ private void configureSocket() throws IOException {
186186
socketChannel.socket().setSendBufferSize(getTxBufSize());
187187
socketChannel.socket().setReceiveBufferSize(getRxBufSize());
188188
socketChannel.socket().setSoTimeout((int) getTimeout());
189-
socketChannel.socket().setSoLinger(getSoLingerOn(), getSoLingerOn() ? getSoLingerTime() : 0);
190189
socketChannel.socket().setTcpNoDelay(getTcpNoDelay());
191190
socketChannel.socket().setKeepAlive(getSoKeepAlive());
192191
socketChannel.socket().setReuseAddress(getSoReuseAddress());

java/org/apache/catalina/tribes/util/Arrays.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static boolean contains(byte[] source, int srcoffset, byte[] key, int key
6363
}
6464
boolean match = true;
6565
int pos = keyoffset;
66-
for (int i = srcoffset; match && i < length; i++) {
66+
for (int i = srcoffset; match && i < srcoffset + length; i++) {
6767
match = (source[i] == key[pos++]);
6868
}
6969
return match;

java/org/apache/catalina/tribes/util/UUIDGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.juli.logging.LogFactory;
2424

2525
/**
26-
* Smple generation of a UUID.
26+
* Simple generation of a UUID.
2727
*/
2828
public class UUIDGenerator {
2929
/**

0 commit comments

Comments
 (0)