Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] Problem with SharedObject API

Hi Pavel,

Samolisov Pavel wrote:
Hash: SHA1

Hello folks,

I'm playing with SharedObject API and Generic Server/Client. I'm tring
to create shared object in one bundle and to get it in another bundle.

In the first bundle, I get SharedObjectManager and call

public static final String DEMO_SHARED_OBJECT_ID = "foo";


_server = createServer();

ISharedObjectManager manager = getServerSOManager();

ID id = manager.addSharedObject(createNewID(DEMO_SHARED_OBJECT_ID), new
MySharedObject(), null);
System.out.println("Added new SharedObject with ID = " + id.getName());

It works, I get "Added new SharedObject with ID = foo" in the OSGi console.

In another bundle activator:


System.out.println("Clients created and connected");

ISharedObjectManager manager = getClientSOManager(0);

ISharedObject sharedObject =

and I get

"Clients created and connected

in the OSGi Console :-(

May be I make mistake? Any ideas?

The shared object instance is responsible for replicating itself to remotes, and your MySharedObject class has to have code to do this replication. The default (in BaseSharedObject...which I assume MySharedObject extends), is to *not* automatically replicate the object to remote containers.

There's an example of code for replicating a shared object (and replicating the state of the primary copy...i.e. the one created via addSharedObject) onto a remote container in this test class:


This class is in the test bundle:  org.eclipse.ecf.tests.sharedobject

Note that since the replication is done asynchronously (BaseSharedObject subclasses...see [1]) that you might want to put some delay into your test code after connection (to allow the replication to complete).


[1] Note there is also the TransactionSharedObject super class, which has logic built in for replicating transactionally/all or nothing...which will block on addSharedObject until replication is complete...if desired.

Back to the top