|
|
|
@ -19,6 +19,8 @@ package sample.atmosphere;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.atmosphere.config.managed.Decoder;
|
|
|
|
|
import org.atmosphere.config.managed.Encoder;
|
|
|
|
|
import org.atmosphere.config.service.Disconnect;
|
|
|
|
@ -26,29 +28,27 @@ import org.atmosphere.config.service.ManagedService;
|
|
|
|
|
import org.atmosphere.config.service.Ready;
|
|
|
|
|
import org.atmosphere.cpr.AtmosphereResource;
|
|
|
|
|
import org.atmosphere.cpr.AtmosphereResourceEvent;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
@ManagedService(path = "/chat")
|
|
|
|
|
public class ChatService {
|
|
|
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(ChatService.class);
|
|
|
|
|
private final Log logger = LogFactory.getLog(ChatService.class);
|
|
|
|
|
|
|
|
|
|
@Ready
|
|
|
|
|
public void onReady(AtmosphereResource resource) {
|
|
|
|
|
this.logger.info("Connected", resource.uuid());
|
|
|
|
|
this.logger.info("Connected " + resource.uuid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Disconnect
|
|
|
|
|
public void onDisconnect(AtmosphereResourceEvent event) {
|
|
|
|
|
this.logger.info("Client {} disconnected [{}]", event.getResource().uuid(),
|
|
|
|
|
event.isCancelled() ? "cancelled" : "closed");
|
|
|
|
|
this.logger.info("Client " + event.getResource().uuid() + " disconnected ["
|
|
|
|
|
+ (event.isCancelled() ? "cancelled" : "closed") + "]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@org.atmosphere.config.service.Message(encoders = JacksonEncoderDecoder.class, decoders = JacksonEncoderDecoder.class)
|
|
|
|
|
public Message onMessage(Message message) throws IOException {
|
|
|
|
|
this.logger.info("Author {} sent message {}", message.getAuthor(),
|
|
|
|
|
message.getMessage());
|
|
|
|
|
this.logger.info("Author " + message.getAuthor() + " sent message "
|
|
|
|
|
+ message.getMessage());
|
|
|
|
|
return message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|