JavaSpaces - Objects Returning (Both Read / Take) With All Values as Null

162 views Asked by At

I've been trying to set up some JavaSpaces stuff, but the problem I've been having is strange.

Assume this is the object (not using Object in this case, just trying to obfuscate / generalise) I'm trying to place:

import net.jini.core.entry.*;

public class Object implements Entry {
   private String stuff;

   public Object() {}

   public Object ( String s) {
      stuff = s;
   }    

   public String getStuff() { return this.stuff; }
}

And this is the write method:

public void simpleWriteObject(Object object)
{
    try {
        space.write(object, null, 10000);
    } catch (Exception e)
    {

    }
}

(I've tried it with multiple write methods, including a full transaction one that claims it was submitted successfully.)

Now the read is:

public Object readObject()
{
    JavaSpace space = getSpace();

    Object objectTemplate = new Object();

    try {
        Object object = (Object) space.read(objectTemplate, null, LONG.TIME);
        return object;
    } catch (Exception e)
    {
        System.out.println("An error occurred. Error: " + e);
        return null;
    }
}

The problem is that a null object doesn't get returned, I get a completely instantiated object with all the values set to null (as if the object is being created using the no arguments constructor).

So in this case, I'd get an object with [stuff = null] in it:

@Test
void takeObjectFromSpace() {
    Object object = new Object("HelloWorld");
    objectInteration.simpleWriteObject();
    System.out.println(objectInteraction.readObject().getStuff());
}

In reality, if there is nothing in the space it should return a full null object, but it doesn't.

Does anyone have any ideas?

1

There are 1 answers

0
MachinaMandala On BEST ANSWER

(Found the solution to my own question.)

All objects that implement Entry must have all their variables as Public.