Search in sources :

Example 1 with Serializer

use of org.springframework.core.serializer.Serializer in project spring-integration by spring-projects.

the class TcpNetConnection method send.

@Override
@SuppressWarnings("unchecked")
public synchronized void send(Message<?> message) throws Exception {
    if (this.socketOutputStream == null) {
        int writeBufferSize = this.socket.getSendBufferSize();
        this.socketOutputStream = new BufferedOutputStream(this.socket.getOutputStream(), writeBufferSize > 0 ? writeBufferSize : 8192);
    }
    Object object = this.getMapper().fromMessage(message);
    this.lastSend = System.currentTimeMillis();
    try {
        ((Serializer<Object>) this.getSerializer()).serialize(object, this.socketOutputStream);
        this.socketOutputStream.flush();
    } catch (Exception e) {
        this.publishConnectionExceptionEvent(new MessagingException(message, "Failed TCP serialization", e));
        this.closeConnection(true);
        throw e;
    }
    if (logger.isDebugEnabled()) {
        logger.debug(getConnectionId() + " Message sent " + message);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) BufferedOutputStream(java.io.BufferedOutputStream) MessagingException(org.springframework.messaging.MessagingException) IOException(java.io.IOException) SoftEndOfStreamException(org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) Serializer(org.springframework.core.serializer.Serializer)

Example 2 with Serializer

use of org.springframework.core.serializer.Serializer in project spring-integration by spring-projects.

the class TcpNioConnection method send.

@Override
@SuppressWarnings("unchecked")
public void send(Message<?> message) throws Exception {
    synchronized (this.socketChannel) {
        if (this.bufferedOutputStream == null) {
            int writeBufferSize = this.socketChannel.socket().getSendBufferSize();
            this.bufferedOutputStream = new BufferedOutputStream(this.getChannelOutputStream(), writeBufferSize > 0 ? writeBufferSize : 8192);
        }
        Object object = this.getMapper().fromMessage(message);
        this.lastSend = System.currentTimeMillis();
        try {
            ((Serializer<Object>) this.getSerializer()).serialize(object, this.bufferedOutputStream);
            this.bufferedOutputStream.flush();
        } catch (Exception e) {
            this.publishConnectionExceptionEvent(new MessagingException(message, "Failed TCP serialization", e));
            this.closeConnection(true);
            throw e;
        }
        if (logger.isDebugEnabled()) {
            logger.debug(getConnectionId() + " Message sent " + message);
        }
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) BufferedOutputStream(java.io.BufferedOutputStream) MessagingException(org.springframework.messaging.MessagingException) SoftEndOfStreamException(org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) Serializer(org.springframework.core.serializer.Serializer)

Example 3 with Serializer

use of org.springframework.core.serializer.Serializer in project spring-integration by spring-projects.

the class JdbcChannelMessageStore method setSerializer.

/**
 * A converter for serializing messages to byte arrays for storage.
 * @param serializer The serializer to set
 */
@SuppressWarnings("unchecked")
public void setSerializer(Serializer<? super Message<?>> serializer) {
    Assert.notNull(serializer, "The provided serializer must not be null.");
    this.serializer = new SerializingConverter((Serializer<Object>) serializer);
}
Also used : SerializingConverter(org.springframework.core.serializer.support.SerializingConverter) Serializer(org.springframework.core.serializer.Serializer)

Aggregations

Serializer (org.springframework.core.serializer.Serializer)3 BufferedOutputStream (java.io.BufferedOutputStream)2 IOException (java.io.IOException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 SoftEndOfStreamException (org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException)2 MessagingException (org.springframework.messaging.MessagingException)2 SocketException (java.net.SocketException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 SerializingConverter (org.springframework.core.serializer.support.SerializingConverter)1