|
Re: Purpose of the sharedobject API [message #624636 is a reply to message #624635] |
Wed, 17 December 2008 21:35 |
Scott Lewis Messages: 1038 Registered: July 2009 |
Senior Member |
|
|
Hi DI Florian,
DI Florian Hackenberger wrote:
> Hi!
>
> According to http://wiki.eclipse.org/ECF_API_Docs#Shared_Object_API the
> sharedobject API provides a protocol independent API for replicating Java
> objects in a distributed group. To me that means I should be able to do the
> following:
>
> client1:
> ISharedObjectContainer socontainer = (ISharedObjectContainer)
> client1.getAdapter(ISharedObjectContainer.class);
> TestSharedObject sharedObject = new TestSharedObject();
> sharedObject.setDummyProperty("Hello");
> socontainer.getSharedObjectManager().addSharedObject(
> IDFactory.getDefault().createStringID("dummy"), sharedObject, null);
> sharedObject.setDummyProperty("World");
>
> client2:
> socontainer = (ISharedObjectContainer)
> client2.getAdapter(ISharedObjectContainer.class);
> TestSharedObject test =
> socontainer.getSharedObjectManager().getSharedObject(IDFacto ry.getDefault().createStringID(
> "dummy"));
> sharedObject.getDummyProperty(); // Return "World"
>
> Is that the intention of the API?
It's one intention, yes.
>
> Whatever the answer to the above question is, the following code does not
> return a copy of the object on the other clients:
>
> -----------------------------------------------------------
> for(int clientIndex = 0; clientIndex < NUM_CLIENTS; clientIndex++) {
> IContainer container =
> ContainerFactory.getDefault().createContainer("ecf.generic.client ");
> IConnectContext context =
> ConnectContextFactory.createUsernamePasswordConnectContext(U SERNAME,
> PASSWORD);
>
> container.connect(IDFactory.getDefault().createStringID(Test ServerEcf.SERVER_IDENTITY),
> context);
> ISharedObjectContainer socontainer = (ISharedObjectContainer)
> container.getAdapter(ISharedObjectContainer.class);
> clients[clientIndex] = container;
> }
>
> ISharedObjectContainer socontainer = (ISharedObjectContainer)
> clients[0].getAdapter(ISharedObjectContainer.class);
> // Create TestSharedObject
> TestSharedObject sharedObject = new TestSharedObject();
> // Add shared object to container
> socontainer.getSharedObjectManager().addSharedObject(
> IDFactory.getDefault().createStringID(
> TestSharedObject.class.getName()), sharedObject, null);
>
> Thread.sleep(3000);
> for(int clientIndex = 0; clientIndex < NUM_CLIENTS; clientIndex++) {
> socontainer = (ISharedObjectContainer)
> clients[clientIndex].getAdapter(ISharedObjectContainer.class );
> ISharedObject sharedObj =
> socontainer.getSharedObjectManager().getSharedObject(IDFacto ry.getDefault().createStringID(
> TestSharedObject.class.getName()));
> if(sharedObj != null) {
> System.out.println(sharedObj.toString());
> }
> }
> -----------------------------------------------------------
>
> The shared object is only printed once. Any ideas why it does not work as
> intended? I followed the code from
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ecf/tes ts/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclips e/ecf/tests/sharedobject/AddTest.java?revision=1.1&root= RT_Project&view=markup
> but the test only tests if the shared object can be retrieved from the
> client which added the object (which defeats the purpose of the test IMO).
I added the following code to AddTest
for (int clientIndex = 0; clientIndex < getClientCount(); clientIndex++) {
socontainer = (ISharedObjectContainer) getClient(clientIndex)
.getAdapter(ISharedObjectContainer.class);
ISharedObject sharedObj = socontainer.getSharedObjectManager()
.getSharedObject(IDFactory.getDefault().createStringID("foo "));
if (sharedObj != null) {
System.out.println("foo instance=" + sharedObj.toString());
}
}
And it prints out the following:
Primary(GUID[1C812/lv18+qNPlndvoRESyWgWo=]) says Hello slewis
Replica(StringID[ecftcp://localhost:30000/server]) says Hello slewis
Replica(GUID[1N7gJ/I2gXUe8qxuycYfTrzIfyg=]) says Hello slewis
foo instance=org.eclipse.ecf.tests.sharedobject.TestSharedObject@13dd8
foo instance=org.eclipse.ecf.tests.sharedobject.TestSharedObject@1263b07
and the last two lines indicate that it is creating a replica on the
other client, and that replica can be accessed through the 'foo' id.
I noticed that you are using the TestSharedObject class name as the
id...is that being used consistently for creation and for the lookup?
I've committed the above to AddTest, and will be working some more
changes to AddTest...i.e. more complete tests for this (probably as new
test methods).
Please let me know if this helps/hurts. It's possible that their is
some bug of course and if so we'll find and fix.
Scott
|
|
|
|
Re: Purpose of the sharedobject API [message #624638 is a reply to message #624637] |
Thu, 18 December 2008 18:05 |
Scott Lewis Messages: 1038 Registered: July 2009 |
Senior Member |
|
|
Hi Florian,
DI Florian Hackenberger wrote:
> Scott Lewis wrote:
>> Please let me know if this helps/hurts. It's possible that their is
>> some bug of course and if so we'll find and fix.
>
> Thanks for correcting the test code! I found the problem with my setup. It
> seems to be required to export the java package containing the shared
> object classes. I documented this at http://wiki.eclipse.org/ECF_Pitfalls
Yes. Many thanks for adding it to ECF_Pitfalls. I created this bug to
improve the handling/reporting of this issue in the code:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259286
>
> There is one more thing however: How does the shared object propagate
> property changes to the clients?
A shared object has the ability to propogate changes using the
ISharedObjectContext (which is in turn provided by the
ISharedObjectConfig, which is given to the shared object by the
container upon initialization within the container).
On ISharedObjectContext are methods for sendMessage(...) to send
messages to all instances (primary and replicas). The shared object can
then update state with whatever protocol is requires (e.g. optimistic,
via primary, transactionally).
There are also a number of methods to support sending messages in
BaseSharedObject (all of which use the ISharedObjectContext via
getContext()). e.g. sendSharedObjectMsgTo,
sendSharedObjectMsgToPrimary. These send instances of SharedObjectMsg,
which is a class that allows delivery of an entity that resembles a closure.
Shared object instances can choose to use
ISharedObjectContext.sendMessage, or can use
BaseSharedObject.sendSharedObjectMsg.
Note there is a lot of room for further added value here...e.g. creating
messaging strategies/patterns to support different replica
synchronization needs/requirements (e.g. optimistic/pessimistic, etc).
Thanks,
Scott
|
|
|
Powered by
FUDForum. Page generated in 0.04019 seconds