Link walking with a java client

Deepak Balasubramanyam deepak.balu at gmail.com
Sun May 27 00:35:02 EDT 2012


Hi,

I have a cluster that contains 2 buckets. A bucket named 'usersMine'
contains the key 'user2', which is linked to several keys (about 10) under
a bucket named userPreferences. The relationship exists under the name
'myPref'. A user and a preference have String values.

I can successfully traverse the link over HTTP using the following URL -

curl -v localhost:8091/riak/usersMine/user2/_,myPref,1

------------------------ ------------------------ ------------------------
> User-Agent: curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e
zlib/1.2.3.4 libidn/1.22 librtmp/2.3
> Host: localhost:8091
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
< Expires: Sun, 27 May 2012 04:12:39 GMT
< Date: Sun, 27 May 2012 04:02:39 GMT
< Content-Type: multipart/mixed; boundary=IYGfKNqjGdco9ddfyjRP1Utzfi2
< Content-Length: 3271
<

--IYGfKNqjGdco9ddfyjRP1Utzfi2
Content-Type: multipart/mixed; boundary=3YVES0x2tFnUDOdTzfn1OGS6uMt

--3YVES0x2tFnUDOdTzfn1OGS6uMt
X-Riak-Vclock: a85hYGBgzGDKBVIcMRuuc/nvy7mSwZTImMfKUKpodpIvCwA=
Location: /riak/userPreferences/preference3004
Content-Type: text/plain; charset=UTF-8
Link: </riak/userPreferences>; rel="up"
Etag: 5GucnGSk4TjQc8BO1eNLyI
Last-Modified: Sun, 27 May 2012 03:54:29 GMT

junk

<< ------------------------ Truncated ------------------------ >>
junk
--3YVES0x2tFnUDOdTzfn1OGS6uMt--

--IYGfKNqjGdco9ddfyjRP1Utzfi2--
------------------------ ------------------------ ------------------------

However when I use the java client to walk the link, I get a
ClassCastException.

------------------------ ------------------------ ------------------------
Java code:
------------------------ ------------------------ ------------------------
    private void getAllLinks()
    {
        String user="user2";
        IRiakClient riakClient = null;
        try
        {
            long past = System.currentTimeMillis();
            riakClient = RiakFactory.pbcClient("localhost",8081);
            Bucket userBucket =
riakClient.fetchBucket("usersMine").execute();
            DefaultRiakObject user1 =(DefaultRiakObject)
userBucket.fetch(user).execute();
            List links = user1.getLinks();
            System.out.println(links.size());
            WalkResult execute =
riakClient.walk(user1).addStep("userPreferences", "myPref",true).execute();
            Iterator iterator = execute.iterator();
            while(iterator.hasNext())
            {
                Object next = iterator.next();
                System.out.println(next);
            }
            long now = System.currentTimeMillis();
            System.out.println("Retrieval in " + (now-past) + " ms");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            if(riakClient != null)
            {
                riakClient.shutdown();
            }
        }
    }

------------------------ ------------------------ ------------------------
Stack:
------------------------ ------------------------ ------------------------
java.lang.ClassCastException: java.lang.String cannot be cast to
java.util.List
at
com.basho.riak.client.raw.pbc.PBClientAdapter.linkWalkSecondPhase(PBClientAdapter.java:380)
at
com.basho.riak.client.raw.pbc.PBClientAdapter.linkWalk(PBClientAdapter.java:325)
at com.basho.riak.client.query.LinkWalk.execute(LinkWalk.java:63)
at com.chatterbox.persistence.riak.RiakTest.getAllLinks(RiakTest.java:81)
at com.chatterbox.persistence.riak.RiakTest.main(RiakTest.java:25)
------------------------ ------------------------ ------------------------

At line 380 on PBClientAdapter, an enhanced for loop attempts to iterate
over a Collection<List<String>> while the actual value is a List<String>.
This causes the exception. The value of the variable 'step' at the time of
the exception is [userPreferences, preference3000, myPref].

Am i doing something wrong ? The java code retrieves links in a fashion
that is similar to the HTTP retrieval, so I am puzzled by the ClassCast.

Thanks
Deepak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20120527/c57cd609/attachment.html>


More information about the riak-users mailing list