
org.objectweb.dream.serializator.DeSerializator Maven / Gradle / Ivy
/**
* Dream
* Copyright (C) 2003-2004 INRIA Rhone-Alpes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: [email protected]
*
* Initial developer(s): Vivien Quema
* Contributor(s):
*/
package org.objectweb.dream.serializator;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.objectweb.dream.message.Message;
import org.objectweb.dream.message.codec.CodecInputOutput;
import org.objectweb.dream.message.codec.MessageCodec;
import org.objectweb.dream.pool.ObjectPoolItf;
import org.objectweb.dream.pool.Recyclable;
import org.objectweb.dream.pool.RecyclableFactoryType;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.dreamannotation.DreamMonolog;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;
import org.objectweb.fractal.fraclet.annotation.annotations.Service;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
/**
* Basic implementation of the {@link DeSerializatorItf}interface.
*/
@DreamComponent(controllerDesc = "dreamUnstoppablePrimitive")
@Provides(interfaces = {@Interface(name = "recyclable-factory", signature = RecyclableFactoryType.class)})
public class DeSerializator
implements
DeSerializatorItf,
RecyclableFactoryType
{
// ---------------------------------------------------------------------------
// Client interfaces
// ---------------------------------------------------------------------------
@Requires(name = "message-codec")
protected MessageCodec messageCodecItf;
@Requires(name = "object-pool")
protected ObjectPoolItf objectPoolItf;
// --------------------------------------------------------------------------
// Services interfaces
// --------------------------------------------------------------------------
/**
* Component reference
*/
@Service
Component weaveableC;
/**
* Logger of the component
*/
@DreamMonolog()
protected Logger logger;
// ---------------------------------------------------------------------------
// Implementation of the SerializatorItf interface
// ---------------------------------------------------------------------------
/**
* @see DeSerializatorItf#deserialize(byte[])
*/
public Message deserialize(byte[] byteArray) throws IOException
{
CodecInputOutput codecInputOutput = (CodecInputOutput) objectPoolItf
.newInstance();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
byteArray);
codecInputOutput.setInput(byteArrayInputStream);
logger.log(BasicLevel.DEBUG, "read message");
Message message = messageCodecItf.decode(codecInputOutput);
objectPoolItf.recycleInstance((Recyclable) codecInputOutput);
return message;
}
// ---------------------------------------------------------------------------
// Implementation of the RecyclableFactory interface
// ---------------------------------------------------------------------------
/**
* @see org.objectweb.dream.pool.RecyclableFactoryType#newInstance()
*/
public Recyclable newInstance()
{
return new CodecInputOutputByteArray();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy