Browse Source

autoAck setting replaced with ackMode

master
Nikita 11 years ago
parent
commit
f64ac604a9
  1. 39
      src/main/java/com/corundumstudio/socketio/AckMode.java
  2. 21
      src/main/java/com/corundumstudio/socketio/Configuration.java
  3. 12
      src/main/java/com/corundumstudio/socketio/namespace/Namespace.java
  4. 1
      src/main/java/com/corundumstudio/socketio/parser/Encoder.java

39
src/main/java/com/corundumstudio/socketio/AckMode.java

@ -0,0 +1,39 @@
/**
* Copyright 2012 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio;
public enum AckMode {
/**
* Send ack-response automatically on each ack-request
* <b>skip</b> exceptions during packet handling
*/
AUTO,
/**
* Send ack-response automatically on each ack-request
* only after <b>success</b> packet handling
*/
AUTO_SUCCESS_ONLY,
/**
* Turn off auto ack-response sending.
* Use AckRequest.sendAckData to send ack-response each time.
*
*/
MANUAL
}

21
src/main/java/com/corundumstudio/socketio/Configuration.java

@ -70,7 +70,7 @@ public class Configuration {
private AuthorizationListener authorizationListener = new SuccessAuthorizationListener();
private boolean autoAck = true;
private AckMode ackMode = AckMode.AUTO_SUCCESS_ONLY;
public Configuration() {
}
@ -114,7 +114,7 @@ public class Configuration {
setAuthorizationListener(conf.getAuthorizationListener());
setExceptionListener(conf.getExceptionListener());
setSocketConfig(conf.getSocketConfig());
setAutoAck(conf.isAutoAck());
setAckMode(conf.getAckMode());
setMaxFramePayloadLength(conf.getMaxFramePayloadLength());
}
@ -426,18 +426,21 @@ public class Configuration {
}
/**
* Send ack-response automatically on each ack-request
* Default is {@code true}
* Auto ack-response mode
* Default is {@code AckMode.AUTO_SUCCESS_ONLY}
*
* @see AckMode
*
* @param autoAck
* @param ackMode
*/
public void setAutoAck(boolean autoAck) {
this.autoAck = autoAck;
public void setAckMode(AckMode ackMode) {
this.ackMode = ackMode;
}
public boolean isAutoAck() {
return autoAck;
public AckMode getAckMode() {
return ackMode;
}
public String getTrustStoreFormat() {
return trustStoreFormat;
}

12
src/main/java/com/corundumstudio/socketio/namespace/Namespace.java

@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import com.corundumstudio.socketio.AckMode;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.BroadcastOperations;
import com.corundumstudio.socketio.Configuration;
@ -57,7 +58,6 @@ public class Namespace implements SocketIONamespace {
public static final String DEFAULT_NAME = "";
private final ScannerEngine engine = new ScannerEngine();
private final Map<UUID, SocketIOClient> allClients = new ConcurrentHashMap<UUID, SocketIOClient>();
private final ConcurrentMap<String, EventEntry<?>> eventListeners =
new ConcurrentHashMap<String, EventEntry<?>>();
private final ConcurrentMap<Class<?>, Queue<DataListener<?>>> jsonObjectListeners =
@ -66,11 +66,12 @@ public class Namespace implements SocketIONamespace {
private final Queue<ConnectListener> connectListeners = new ConcurrentLinkedQueue<ConnectListener>();
private final Queue<DisconnectListener> disconnectListeners = new ConcurrentLinkedQueue<DisconnectListener>();
private final Map<UUID, SocketIOClient> allClients = new ConcurrentHashMap<UUID, SocketIOClient>();
private final ConcurrentMap<String, Set<UUID>> roomClients = new ConcurrentHashMap<String, Set<UUID>>();
private final ConcurrentMap<UUID, Set<String>> clientRooms = new ConcurrentHashMap<UUID, Set<String>>();
private final String name;
private final boolean autoAck;
private final AckMode ackMode;
private final JsonSupport jsonSupport;
private final StoreFactory storeFactory;
private final ExceptionListener exceptionListener;
@ -81,7 +82,7 @@ public class Namespace implements SocketIONamespace {
this.jsonSupport = configuration.getJsonSupport();
this.storeFactory = configuration.getStoreFactory();
this.exceptionListener = configuration.getExceptionListener();
this.autoAck = configuration.isAutoAck();
this.ackMode = configuration.getAckMode();
}
public void addClient(SocketIOClient client) {
@ -151,13 +152,16 @@ public class Namespace implements SocketIONamespace {
}
} catch (Exception e) {
exceptionListener.onEventException(e, args, client);
if (ackMode == AckMode.AUTO_SUCCESS_ONLY) {
return;
}
}
sendAck(ackRequest);
}
private void sendAck(AckRequest ackRequest) {
if (autoAck) {
if (ackMode == AckMode.AUTO || ackMode == AckMode.AUTO_SUCCESS_ONLY) {
// send ack response if it not executed
// during {@link DataListener#onData} invocation
ackRequest.sendAckData(Collections.emptyList());

1
src/main/java/com/corundumstudio/socketio/parser/Encoder.java

@ -159,7 +159,6 @@ public class Encoder {
public void encodePacket(Packet packet, ByteBuf buffer) throws IOException {
ByteBufOutputStream out = new ByteBufOutputStream(buffer);
int start = buffer.writerIndex();
int type = packet.getType().getValue();
buffer.writeByte(toChar(type));
buffer.writeByte(Packet.SEPARATOR);

Loading…
Cancel
Save