Package org.apache.directmemory.serialization

Examples of org.apache.directmemory.serialization.Serializer


            g.writeNumberField( DirectMemoryConstants.EXPIRES_IN_FIELD_NAME, request.getExpiresIn() );

            // FIXME take care of NPE
            // cache content generation
            Serializer serializer = request.getSerializer();
            // if no Object users are able to pass a string content
            byte[] bytes = request.getObject() != null
                ? request.getSerializer().serialize( request.getObject() )
                : request.getCacheContent();

            g.writeFieldName( DirectMemoryConstants.CACHE_CONTENT_FIELD_NAME );
            g.writeBinary( bytes );

            if ( serializer != null )
            {
                g.writeStringField( DirectMemoryConstants.SERIALIZER_FIELD_NAME, serializer.getClass().getName() );
            }

            g.writeEndObject();
            g.close();
        }
View Full Code Here


                        .newCacheService();

        String serializerClassName = (String) args.get( "serializerClassName" );
        if ( serializerClassName != null )
        {
            Serializer serializer;
            try
            {
                serializer = SerializerFactory.createNewSerializer( serializerClassName );
            }
            catch ( SerializerNotFoundException e )
View Full Code Here

        throws Exception
    {
        Wine wine = new Wine();
        wine.setName( "Bordeaux" );

        Serializer serializer = SerializerFactory.createNewSerializer();

        DirectMemoryRequest dmRq =
            new DirectMemoryRequest().setKey( "101" ).setUpdate( true ).setExpiresIn( 123 ).setObject(
                wine ).setSerializer( serializer );
        String rq = DirectMemoryWriter.instance().generateJsonRequest( dmRq );
        log.info( "rq:" + rq );

        dmRq = DirectMemoryParser.instance().buildRequest( new ByteArrayInputStream( rq.getBytes() ) );
        assertNotNull( dmRq );

        assertEquals( "101", dmRq.getKey() );
        assertTrue( dmRq.isUpdate() );
        assertEquals( 123, dmRq.getExpiresIn() );

        wine = serializer.deserialize( dmRq.getCacheContent(), Wine.class );
        assertEquals( "Bordeaux", wine.getName() );

    }
View Full Code Here

            g.writeNumberField( DirectMemoryConstants.EXPIRES_IN_FIELD_NAME, request.getExpiresIn() );

            // FIXME take care of NPE
            // cache content generation
            Serializer serializer = request.getSerializer();
            // if no Object users are able to pass a string content
            byte[] bytes = request.getObject() != null
                ? request.getSerializer().serialize( request.getObject() )
                : request.getCacheContent();

            g.writeFieldName( DirectMemoryConstants.CACHE_CONTENT_FIELD_NAME );
            g.writeBinary( bytes );

            if ( serializer != null )
            {
                g.writeStringField( DirectMemoryConstants.SERIALIZER_FIELD_NAME, serializer.getClass().getName() );
            }

            g.writeEndObject();
            g.close();
        }
View Full Code Here

        String sizeStr = String.valueOf( args.get( "size" ) );
        final int limit = sizeStr == null ? 1024 : Integer.parseInt( sizeStr );
        String initialSizeValue = (String) args.get( "initialSize" );
        final int initialSize = Math.min( initialSizeValue == null ? 1024 : Integer.parseInt( initialSizeValue ), limit );

        Serializer serializer = null;
        String serializerClassName = (String) args.get( "serializerClassName" );
        if ( serializerClassName != null )
        {
            try
            {
View Full Code Here

    {
        verifyPerRequestParameters( directMemoryRequest );
        DirectMemoryResponse response = this.directMemoryHttpClient.get( directMemoryRequest );
        if ( response.isFound() && response.getCacheContent() != null && response.getCacheContent().length > 0 )
        {
            Serializer serializer = directMemoryRequest.getSerializer();
            if ( serializer == null )
            {
                serializer = clientConfiguration.getSerializer();
            }
            response.setResponse(
                serializer.deserialize( response.getCacheContent(), directMemoryRequest.getObjectClass() ) );
        }
        return response;
    }
View Full Code Here

        throws DirectMemoryException, IOException
    {

        try
        {
            Serializer serializer = getSerializer( req );
            String res = serializer.deserialize( cacheResponseContent, String.class );
            resp.setContentType( MediaType.TEXT_PLAIN );
            return res.getBytes();
        }
        catch ( SerializerNotFoundException e )
        {
View Full Code Here

        throws DirectMemoryException, IOException
    {
        DirectMemoryRequest request = new DirectMemoryRequest();
        try
        {
            Serializer serializer = getSerializer( req );
            request.setCacheContent( serializer.serialize( IOUtils.toString( req.getInputStream() ) ) );
        }
        catch ( SerializerNotFoundException e )
        {
            throw new DirectMemoryException( e.getMessage(), e );
        }
View Full Code Here

    @Test
    public void storeObject()
        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent( serializer.serialize( bordeaux ) );

        String rq = writer.generateJsonRequest( directMemoryRequest );

        MockHttpServletRequest putRequest = new MockHttpServletRequest();

        putRequest.setContentType( MediaType.APPLICATION_JSON );

        putRequest.setServletPath( "cache" );

        putRequest.setPathInfo( "/bordeaux" );

        putRequest.setContent( rq.getBytes() );

        MockHttpServletResponse putResponse = new MockHttpServletResponse();

        directMemoryServlet.doPut( putRequest, putResponse );

        assertEquals( HttpServletResponse.SC_OK, putResponse.getStatus() );

        // now retrieve the content

        MockHttpServletRequest getRequest = new MockHttpServletRequest();

        getRequest.addHeader( "Accept", MediaType.APPLICATION_JSON );

        getRequest.setPathInfo( "/bordeaux" );

        MockHttpServletResponse getResponse = new MockHttpServletResponse();

        directMemoryServlet.doGet( getRequest, getResponse );

        assertEquals( HttpServletResponse.SC_OK, getResponse.getStatus() );

        assertEquals( MediaType.APPLICATION_JSON, getResponse.getContentType() );

        DirectMemoryResponse response =
            parser.buildResponse( new ByteArrayInputStream( getResponse.getContentAsByteArray() ) );

        Wine wineFromCache = serializer.deserialize( response.getCacheContent(), Wine.class );

        assertEquals( bordeaux.getName(), wineFromCache.getName() );
        assertEquals( bordeaux.getDescription(), wineFromCache.getDescription() );

    }
View Full Code Here

    @Test
    public void storeExpiredObject()
        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent(
                serializer.serialize( bordeaux ) ).setExpiresIn( 3 );

        String rq = writer.generateJsonRequest( directMemoryRequest );

        MockHttpServletRequest putRequest = new MockHttpServletRequest();
View Full Code Here

TOP

Related Classes of org.apache.directmemory.serialization.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.