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

Ask Your Question

Howto use multiple embedded spaces (with or without the LUS)

Unfortunately thats already my 3 questions about this topic and I am sorry to spam the forum but I really dont get it how its supposed to work.

What I want to do: I run a single process/JVM and I want to create multiple embedded spaces within this process. Furthermore I want to have one or more threads that take some object from one of those spaces and either write it back into the same space or write it into some other space. All this operations run within a transaction.

My questions are:

  1. How should I create the embedded spaces? What parameters / properties should I use?
  2. Whats the difference when I turn off the LookupService (LUS) for the spaces? What do I need to change in my code to get it working without the LUS?
  3. Should I create the proxies only once and re-use them (as mentionend in the documation)? or can I create multiple proxies to access the same space?
  4. Can I still use the DistributedJiniTxManager when disabling the LUS? Is it possible to take from one space and write into another in the same transaction?

Currently I have the problem that I do not see any writes (take returns null), when turning of the LUS.
What I mean is: One thread take some object within a transaction from Space-A and writes an object to space-B. When another thread tries to take this object from Space-B without using a transaction, then the take call returns null.
This was previously working when I used a jini URL and the LUS.

A very simplistic version of my code is shown below.
I hope you can help me here because I have no clue how this is supposed to work (I already read the documenation)

The test setup:

private beforeTest() {
    txManager = new DistributedJiniTxManagerConfigurer().transactionManager();

private GigaSpace createEmbeddedSpace(final String spaceName) {
// everything works when i remove the "lus.start-embedded-lus" and "jini_lus.enabled" properties    
UrlSpaceConfigurer configurer = new UrlSpaceConfigurer("/./" + spaceName)
        .addProperty("space-config.lease_manager.expiration_time_interval", "1500")
        .addProperty("com.j_spaces.core.container.directory_services.jini_lus.start-embedded-lus", "false")
        .addProperty("com.j_spaces.core.container.directory_services.jini_lus.enabled", "false")
        .addProperty("com.j_spaces.core.container.directory_services.jndi.enabled", "false")
        .addProperty("com.j_spaces.core.container.embedded-services.httpd.enabled", "false");

    return new GigaSpaceConfigurer(configurer).transactionManager(txManager).create();

    // this metod is called for every embedded space (1-5)
protected GigaSpace getOrCreateSpace(final String spaceName) {
    GigaSpace spaceRepository = createEmbeddedSpace(spaceName);

    spacesByName.put(spaceName, spaceRepository);

    // this properties (url) are used in the establishNewConnection method shown below
    defineDeploymentProperty(spaceName, "/./" + spaceName);

    return spaceRepository;

protected GigaSpace getSpace(final String spaceName) {
   return spacesByName.get(spaceName);

The test method itself

public void messageShouldBeTransported() {
    // Given

    // When 
    // when i write this message into the own space, 
    // it should be picked up by the thread shown below and written into the destination space
    // this is what i want to test
    DummyTestMessage inboundMessage = new DummyTestMessage();


    // Then
    // i expect to see the message in the other space
    DummyTestMessage template = new DummyTestMessage();
    DummyTestMessage actualMessage = getSpace(OTHER_SPACE_NAME).take(template, SOME_TIMEOUT);
    // but the take operation always returns null.. :-(

Creating proxies in production code:

private void establishNewConnection() {
        // typically we create the proxies like this
        // this will use the deployment propertie URL as shown above
        // but I also tried to re-use the same GigaSpace instance from the test setup without creating a new one
        IJSpace javaSpace = factory.create(spaceUrl);
        synchronized (sync) {
            space = new GigaSpaceConfigurer(javaSpace)

The production code thread that actually does the work

// some other thread that processes messages written into the space with name = OWN_SPACE_NAME
public void handleNextMessage() throws TransportException {
    TransactionStatus transaction = null;
    DummyTestMessage receivedMessage = null;

    try {
        transaction = txManager.getTransaction(new DefaultTransactionDefinition());

        // take from OWN_SPACE_NAME
        receivedMessage = localSpace.takeOrdered(query, MESSAGE_POLL_TIMEOUT_MILLIS);

        if (receivedMessage != null) {
            // get the proxy to the other space by either 
            // creating a new proxy as shown in the establishNewConnection mehtod above
            // or re-using the same instance as in the test code (i tried both but none works)
            GigaSpace otherSpace = otherSpacesProvider.get(receivedMessage.getDestination()); 
            otherSpace.write(receivedMessage); // this is now the space with name = OTHER_SPACE_NAME
        } else {
    } catch (Exceptions.. ex) {


asked 2014-12-08 05:03:14 -0500

leozilla gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

You have another question that appears to be a duplicate of this one. I believe it's more or less answered in the other question.

answered 2014-12-10 10:32:39 -0500

jb 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


Asked: 2014-12-08 05:03:14 -0500

Seen: 416 times

Last updated: Dec 10 '14