Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Simple partitioned example help

Hi, I think this should be pretty simple. I.e., a service that listens on a routed request-event, and writes a result based on it. The driver write()'s a request and take()'s the result before writing the next request.

The request routing-key is an integer so I generate a bunch of requests, incrementing the routing-key so that I exercise each partition. I get the first result, but fail to receive any more. Any ideas what I'm doing wrong?

public class Request { @SpaceId @SpaceRouting public int requestId() {} // etc. }

public class MyService { @SpaceDataEvent public void myEventHandler(Request req, GigaSpace space) { space.write(new Result(req)); // generate the result from the request-info } //etc }

Configured thus:

<os-core:space id="jspace" url="/./TestSpace"/>
<os-core:giga-space id="gigaSpace" space="jspace" />
<bean id="service" class="kov.test.MyService" />
<os-events:polling-container id="routingEventContainer" giga-space="gigaSpace">
    <os-core:template><bean class="kov.test.common.Request" /></os-core:template>
    <os-events:listener>
        <os-events:annotation-adapter><os-events:delegate ref="service"/></os-events:annotation-adapter>
    </os-events:listener>
</os-events:polling-container>

And driven like this:

GigaSpace space = new GigaSpaceConfigurer(
                (IJSpace) SpaceFinder.find("jini://*/*/TestSpace?groups=kov")).gigaSpace();
Result result = null;
for(int i = 0; i < ITERATIONS; ++i) {
    space.write(new Request(i));
Result result = space.take(new Result());
    assertNotNull(result);
}

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2383]{quote}

asked 2008-06-16 08:23:20 -0600

kov gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Hi Ken,

Looks fine at first glance...

Are you getting an error, or the take doesn't return? Are the objects in the space? (look at gs-ui).

One small comments, not realy related, is around your SpaceDataEvent method. If you only need to write a single object (in your case the response) back to the space you can have it as a return value, and OpenSpaces will write it for you, and you will not need GigaSpace as a referece.

-Guy

answered 2008-06-16 09:02:01 -0600

guy sayar gravatar image
edit flag offensive delete link more

Comments

Thanks, Guy, once I get this working I'll look into using a return-value.

The space.take() is returning null, not erroring/throwing. One thing I hadn't mentioned is that my Result did not have a routing-key. I tried adding one (an integer, populated with the cluster instanceId), which means my take() template has a null routing-key. This seems right to me (the driver shouldn't know or care which partition it's receiving results from), but perhaps that's a problem?

kov gravatar image kov  ( 2008-06-16 09:17:21 -0600 )edit

Hi Ken,

Yes, you are correct, the app shouldn't know about partitioning. That doesnt mean you shoulnt assign a routing field. Annotate the ID as routing key, but dont assign any value to it... This should work as you expect.

The problem w/ not specifying a routing key, or an id for that sake, is that you will be using implicit indexing. This means that the space decides which fields to index and which to use for routing.

-Guy

Edited by: Guy Sayar on Jun 16, 2008 9:23 AM

guy sayar gravatar image guy sayar  ( 2008-06-16 09:23:39 -0600 )edit

To add to what Guy said, explicit partition key would allow you to ensure that multiple related objects are routed to same partitions, which is absolutely needed in the SBA architecture and would provide better efficiency in the case of remote field access.

Ilya

isterin gravatar image isterin  ( 2008-06-16 09:47:45 -0600 )edit

Right, thanks; still not working. The first request goes to the first partition, I receive the result in the driver-app, but the second request doesn't seem to reach the second-partition event-handler (although according to GS-GUI the request seems to be in the partition-space).

Here's the result-class now:

public class Result implements Serializable { private static final long serialVersionUID = 1L; private Long _result; private Integer _instance;

public Result() {}

@SpaceId
public Long getResult() { return _result; }
public void setResult(Long result) { _result = result; }

@SpaceRouting
public Integer getInstance() { return _instance; }
public void setInstance(Integer instance) { _instance = instance; }

}

kov gravatar image kov  ( 2008-06-16 09:56:01 -0600 )edit

Ken,

Just to iterate your findings - you can see the request object at partition 2, but the service does not get invoked?

Is so, it would explain why you dont get a response :)

Can you submit your pu.xml?

-Guy

guy sayar gravatar image guy sayar  ( 2008-06-16 10:02:24 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-06-16 08:23:20 -0600

Seen: 213 times

Last updated: Jun 16 '08