Java MemCached Client cannot read user-defined object into ByteArrayOutputStream

Greg Whalin greg at meetup.com
Fri Apr 6 12:45:48 UTC 2007


You need to make sure you make your object serializable (implement
Serializable or Externalizable).

gw

On 4/6/07, janicellh <janicellh at gmail.com> wrote:
>
> Hi,
>
> I am planning to use the Java MemCached Client from your website to
> store a complex and serialized object into MemCached Server. However,
> it only works for String data type but not any other user-defined
> object. Please advice. I would appreaciate if you could help me to
> resolve the issue ASAP.
>
> I think the problem will probably caused at the following line whereby
> the client trying to read the value character by character:
>
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
>                         boolean eol = false;
>                         while ( in.read( b, 0, 1 ) != -1 ) {
>
>
> I have downloaded the java_memcached-release_1.5.1.jar from
> http://www.whalin.com/memcached/#download.
>
> Here is the example of the object to be stored:
>
> UserRecord ur = new UserRecord();
> ur.setId("test");
> ur.setName("test");
> List<Role> ls = new ArrayList<Role>();
> Role r = new Role(1, 'admin');
> ls.add(r);
> r = new Role(1, 'user');
> ls.add(r);
> ur.setRoles(ls);
>
>
> Below is the recap from console output:
>
> ---------------------------------------------------------------------------------
>
> DEBUG --- SockIOPool.initialize(509) | ++++ initializing pool with
> following settings:
> DEBUG --- SockIOPool.initialize(510) | ++++ initial size: 3
> DEBUG --- SockIOPool.initialize(511) | ++++ min spare   : 3
> DEBUG --- SockIOPool.initialize(512) | ++++ max spare   : 10
> DEBUG --- SockIOPool.initialize(533) | ++++ added 127.0.0.1:11211 to
> server bucket
> DEBUG --- SockIOPool.initialize(537) | +++ creating initial
> connections (3) for host: 127.0.0.1:11211
> DEBUG --- SockIOPool.createSocket(643) | ++++ created socket
> (Socket[addr=/127.0.0.1,port=11211,localport=4608]) for host:
> 127.0.0.1:11211
> DEBUG --- SockIOPool.initialize(547) | ++++ created and added socket:
> Socket[addr=/127.0.0.1,port=11211,localport=4608] for host
> 127.0.0.1:11211
> DEBUG --- SockIOPool.createSocket(643) | ++++ created socket
> (Socket[addr=/127.0.0.1,port=11211,localport=4611]) for host:
> 127.0.0.1:11211
> DEBUG --- SockIOPool.initialize(547) | ++++ created and added socket:
> Socket[addr=/127.0.0.1,port=11211,localport=4611] for host
> 127.0.0.1:11211
> DEBUG --- SockIOPool.createSocket(643) | ++++ created socket
> (Socket[addr=/127.0.0.1,port=11211,localport=4612]) for host:
> 127.0.0.1:11211
> DEBUG --- SockIOPool.initialize(547) | ++++ created and added socket:
> Socket[addr=/127.0.0.1,port=11211,localport=4612] for host
> 127.0.0.1:11211
> DEBUG --- SockIOPool.getSock(703) | cache socket pick
> http%253A%252F%252Fphishing.filter.test%252Flookup null
> DEBUG --- SockIOPool.getConnection(885) | ++++ moving socket for host
> (127.0.0.1:11211) to busy pool ... socket:
> Socket[addr=/127.0.0.1,port=11211,localport=4612]
> INFO --- MemCachedClient.set(647) | ++++ serializing for key:
> http%253A%252F%252Fphishing.filter.test%252Flookup for class:
> com.fsecure.nrs.litmus.url.model.UrlRecord
> ERROR --- MemCachedClient.set(719) | ++++ exception thrown while
> writing bytes to server on set
> ERROR --- MemCachedClient.set(720) | ++++ Stream appears to be dead,
> so closing it down
> java.io.IOException: ++++ Stream appears to be dead, so closing it down
>         at com.danga.MemCached.SockIOPool$SockIO.readLine(SockIOPool.java
> :1580)
>         at com.danga.MemCached.MemCachedClient.set(MemCachedClient.java
> :700)
>         at com.danga.MemCached.MemCachedClient.set(MemCachedClient.java
> :423)
> DEBUG --- SockIOPool$SockIO.trueClose(1441) | ++++ Closing socket for
> real: Socket[addr=/127.0.0.1,port=11211,localport=4612]
> DEBUG --- SockIOPool.checkIn(1036) | ++++ calling check-in on socket:
> Socket[addr=/127.0.0.1,port=11211,localport=4612] for host:
> 127.0.0.1:11211
> DEBUG --- SockIOPool.checkIn(1041) | ++++ removing socket
> (Socket[addr=/127.0.0.1,port=11211,localport=4612]) from busy pool for
> host: 127.0.0.1:11211
>
> --
>
> Thanks.
>
>
> Regards,
> Janice Lee
>
>


-- 
Greg Whalin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070406/3790e2c0/attachment.htm


More information about the memcached mailing list