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

Ask Your Question
0

Null Values On read

I'm probably making a very basic error as I'm new to Gigaspaces but I have an issue whereby I'm receiving null values when a processor is notified a new event being added to the space.

I have a feeder similar to that in the OrderEvent parallel processing example which is writing events to the space at a set interval. My first processor picks these up and performs some operations on them and then writes a second, different, event to the space. This event is picked up by another processor - however the properties in this event are all null.

The relevant code is as follows:

// method in first processor which takes an event of class SignedLinesSummaryEvent and returns an event of type SignedLinesCountUpdateEvent. @SpaceDataEvent public SignedLinesCountUpdateEvent updateLinesInformation(SignedLinesSummaryEvent event) { log.debug("received signed lines summary event: " + event); updateDataFromSignedLinesSummaries(event.getSummaries()); return new SignedLinesCountUpdateEvent(getSignedLinesByYear(), getSignedLinesByUnderwriter(), getSignedLinesByBroker(), getThisYearsSignedLinesByMonth()); }

//the event object which contains null instances when returned @SpaceClass(fifo=true) public class SignedLinesCountUpdateEvent {

private SortedMap<Integer, Long> signedLinesByYear;
private SortedMap<String, Long> signedLinesByUnderwriter;
private SortedMap<Integer, Long> thisYearsSignedLinesByMonth;
private SortedMap<String, Long> signedLinesByBroker;
private String status = "New";
private String id;


public SignedLinesCountUpdateEvent(){}

public SignedLinesCountUpdateEvent(SortedMap<Integer, Long> signedLinesByYear, SortedMap<String, Long> signedLinesByUnderwriter, SortedMap<String, Long> signedLinesByBroker, SortedMap<Integer, Long> thisYearsSignedLinesByMonth) {
    this.signedLinesByYear = signedLinesByYear;
    this.signedLinesByBroker = signedLinesByBroker;
    this.signedLinesByUnderwriter = signedLinesByUnderwriter;
    this.thisYearsSignedLinesByMonth = thisYearsSignedLinesByMonth;
}

@SpaceId(autoGenerate=true)
public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public SortedMap<Integer, Long> getSignedLinesByYear() {
    return signedLinesByYear;
}

public SortedMap<String, Long> getSignedLinesByUnderwriter() {
    return signedLinesByUnderwriter;
}

public SortedMap<Integer, Long> getThisYearsSignedLinesByMonth() {
    return thisYearsSignedLinesByMonth;
}

public SortedMap<String, Long> getSignedLinesByBroker() {
    return signedLinesByBroker;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

@Override
public String toString() {
    StringBuilder builder = new StringBuilder(getClass().getName());
    builder.append("[id=");
    builder.append(id);
    builder.append(", signedLinesByYear=");
    builder.append(signedLinesByYear);
    builder.append(", signedLinesByUnderwriter=");
    builder.append(signedLinesByUnderwriter);
    builder.append(", thisYearsSignedLinesByMonth=");
    builder.append(thisYearsSignedLinesByMonth);
    builder.append(", signedLinesByBroker=");
    builder.append(signedLinesByBroker);
    return builder.toString();
}

//the method which is called in the second processor with the event which contains null values.

@SpaceDataEvent public void updateSignedLinesCounts(SignedLinesCountUpdateEvent event){ log.debug("received signed lines update event: " + event); }

}

Thanks for any help!

Edited by: andym on Nov 3, 2008 11:32 AM

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

asked 2008-11-03 11:30:59 -0500

andym gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

You will need also getter and setter methods for all class fields.
Without these these will not be stored in the space and the materialized object will not have its values set.
In case you are interested to use the persistency options you will need to use the @SpaceId (autogenerate (false) and set your ID into the field before writing it into the space.

Any special reason why you use notify container and not polling container ? Don't you need to consume the object once added to the space?

Shay

answered 2008-11-03 14:34:39 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Hi Shay,

Thanks for the response. Adding setters for the map properties has certainly changed the problem so I assume it's now writing the appropriate values to the space. My second processor, however, is no longer matching on the event so I'm unable to confirm. The template for the event is as follows and the only change I made was to add the setters.

<os-core:template> <bean class="org.andym.system.summary.event.SignedLinesCountUpdateEvent"> <property name="status" value="New"/> </bean> </os-core:template>

Presumably I need some sort of wildcard matching, however using null which I seem to remember being the template wildcard causes an exception.

I'm using the notify container rather than the polling container as I have a situation whereby I want to have publish-subscribe type behaviour between a server and several clients. Essentially the clients should be able to request a current state from the server when they are initialised and, once this is complete, start listening for future updates issued by the server. To this effect I need to leave events in the space once each client has processed it. I'm also hoping to find out how to configure the lease time of the space so that the events can be removed after a relevant period.

Thanks again

andym gravatar imageandym ( 2008-11-04 03:19:18 -0500 )edit

Make sure that once an instance of org.andym.system.summary.event.SignedLinesCountUpdateEvent is constructed all its fields will be null. Without this the matching will be done against the populated values + the ones you set with the <os-core:template>.

What is the exception you are getting?

Is sounds like what you need to use is the GSIterator. This is essentially a continuous query implementation that perform the following: - Fetching existing data into the client (doing this in batches) - Delivering events into the client for incoming new objects written into the space

To speed up the first phase of the GSIterator you should modify its window size.

See more: http://www.gigaspaces.com/wiki/displa...http://www.gigaspaces.com/docs/JavaDo...

In order to write objects into a space with a specific lease you should use the GigaSpace.write(T entry, long lease) method or set the GigaSpace.defaultWriteLease via GigaSpace.setDefaultWriteLease

Shay

shay hassidim gravatar imageshay hassidim ( 2008-11-04 11:36:09 -0500 )edit

many thanks Shay, that's solved it :).

andym gravatar imageandym ( 2008-11-06 01:32:43 -0500 )edit

having said that the problem has been resolved....

I'm still having trouble with the lease time of objects in the space. If I understand correctly then the lease time should, essentially, define the life of the event within the space. I.E. if I set a lease time of 5000 then events in the space should be removed after a period of 5 seconds regardless of whether they have been taken or read by any processors. Is this correct? If not can anyone point me towards something which explains the lease behaviour and is there any way of achieving this behaviour without writing a separate 'cleanup' processor? I've tried severa different ways of setting the lease period but all have had no effect.

So far I've tried:

in config:

<os-core:space id="space" url="/./signedLinesSpace"/>

<!-- OpenSpaces simplified space API built on top of IJSpace/JavaSpace. -->
<os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager" default-write-lease="5000"/>

<!-- Defines a local Jini transaction manager. -->
<os-core:local-tx-manager id="transactionManager" space="space"/>

in the processor writing the event:

gigaSpace.write(event, 5000)

as a separate bean initialised on application startup (yes I know this is horribly dirty)

GigaSpaceConfigurer config = new GigaSpaceConfigurer(gigaSpace.getSpace()); config.defaultWriteLease(5000);

Edited by: Andrew Moody on Nov 7, 2008 3:04 AM

andym gravatar imageandym ( 2008-11-07 03:00:16 -0500 )edit

What u have done should expire the object lease. (Aka time to live) after 5 seconds and remove the object from the space. There is no need to have a separate cleaner mechanism.

Why u think the object is still there?

Can u check the class count at the GS-UI and see if the number of class instances decreased?

Shay

shay hassidim gravatar imageshay hassidim ( 2008-11-07 06:52:19 -0500 )edit
0

Do u have space domain classes in a jar under pu/shared-lib folder?

Shay Sent from my BlackBerry® smartphone with SprintSpeed

answered 2008-11-03 12:43:19 -0500

shay hassidim gravatar image
edit flag offensive delete link more

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-11-03 11:30:59 -0500

Seen: 66 times

Last updated: Nov 03 '08