All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quotemedia.streamer.client.impl.MessageDecoder Maven / Gradle / Ivy

package com.quotemedia.streamer.client.impl;

import com.quotemedia.streamer.messages.smessage.SMessage;
import com.quotemedia.streamer.messages.smessage.SMessageDecoder;
import org.atmosphere.wasync.Decoder;
import org.atmosphere.wasync.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class MessageDecoder implements Decoder {
    private static final Logger log = LoggerFactory.getLogger(MessageDecoder.class);
    private final SMessageDecoder decoder;

    public MessageDecoder() {
        this.decoder = new SMessageDecoder();
    }

    @Override
    public final Object decode(final Event evt, final String s) {
        if (Event.MESSAGE.equals(evt)) {
            return this.decodesmessage(s);
        }
        return null;
    }

    private SMessage decodesmessage(final String in) {
        if (in == null) {
            return null;
        }
        try {
            return this.decoder.decode(in);
        } catch (final Exception e) {
            log.warn("Problem decoding message. Reason {}: {}.", e.getClass().getSimpleName(), e.getMessage());
            log.debug("Problem decoding message.", e);
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy