|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Problem with SharedObject API-----BEGIN PGP SIGNED MESSAGE-----
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 ISharedObjectManager#addSharedObject: 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: createClients(); connectClients(); System.out.println("Clients created and connected"); ISharedObjectManager manager = getClientSOManager(0); ISharedObject sharedObject = manager.getSharedObject(createNewID(DEMO_SHARED_OBJECT_ID)); System.out.println(sharedObject); and I get "Clients created and connected null" in the OSGi Console :-( May be I make mistake? Any ideas? Thanks. - -- Pavel Samolisov Meet me at: Vkontakte.ru: http://vkontakte.ru/id3178981 Blog: http://samolisov.blogspot.com Twitter: http://twitter.com/samolisov XMPP/Jabber: samolisov@... -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrwZVcACgkQ20T0Vos3rqAsmwCfYGz0B8CT1hcKWuZrplGWPbPF kHEAoLdaCBdC208/eUiIPSr1vSH+8uOj =eZdh -----END PGP SIGNATURE----- _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject APIHi Pavel,
Samolisov Pavel wrote: > -----BEGIN PGP SIGNED MESSAGE----- > 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 > ISharedObjectManager#addSharedObject: > > 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: > > createClients(); > connectClients(); > > System.out.println("Clients created and connected"); > > ISharedObjectManager manager = getClientSOManager(0); > > ISharedObject sharedObject = > manager.getSharedObject(createNewID(DEMO_SHARED_OBJECT_ID)); > System.out.println(sharedObject); > > and I get > > "Clients created and connected > null" > > 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: org.eclipse.ecf.tests.sharedobject.TestSharedObject 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). Scott [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. _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject API-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Thanks Scott. Tests works fine, my code works too. But I do not understand why this code is in TestSharedObject (in method initialize()): // This is a replica, so initialize the name from property name = (String) getConfig().getProperties().get(NAME_PROPERTY); Is this code a deserialization from Config to SharedObject? Why name do not replicate with SharedObject automaticaly? And another question: Does SharedObject API have any listeners that calls when shared object has been added? Scott Lewis пишет: > Hi Pavel, > > Samolisov Pavel wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> 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 >> ISharedObjectManager#addSharedObject: >> >> 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: >> >> createClients(); >> connectClients(); >> >> System.out.println("Clients created and connected"); >> >> ISharedObjectManager manager = getClientSOManager(0); >> >> ISharedObject sharedObject = >> manager.getSharedObject(createNewID(DEMO_SHARED_OBJECT_ID)); >> System.out.println(sharedObject); >> >> and I get >> >> "Clients created and connected >> null" >> >> 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: > > org.eclipse.ecf.tests.sharedobject.TestSharedObject > > 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). > > Scott > > [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. > > - -- Pavel Samolisov Meet me at: Vkontakte.ru: http://vkontakte.ru/id3178981 Blog: http://samolisov.blogspot.com Twitter: http://twitter.com/samolisov XMPP/Jabber: samolisov@... -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrxki8ACgkQ20T0Vos3rqCingCeNvqvZzIbtaarPZIyouVoBGNX m3UAoMtJoXwt5zV2hctRBek9I+EBACma =5GIK -----END PGP SIGNATURE----- _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject APIHi Pavel,
Samolisov Pavel wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Thanks Scott. > > Tests works fine, my code works too. But I do not understand why this > code is in TestSharedObject (in method initialize()): > > // This is a replica, so initialize the name from property > name = (String) getConfig().getProperties().get(NAME_PROPERTY); > > Is this code a deserialization from Config to SharedObject? Why name do > not replicate with SharedObject automaticaly? > This code is only executed on the non-primary copy of the shared object (i.e. the replicas). This code (run only on the primary copy), is responsible for serializing the state of the shared object (in this case, it's name): protected ReplicaSharedObjectDescription getReplicaDescription(ID receiver) { // Put primary state into properties and include in replica description final Map properties = new HashMap(); properties.put(NAME_PROPERTY, name); return new ReplicaSharedObjectDescription(this.getClass(), getConfig().getSharedObjectID(), getConfig().getHomeContainerID(), properties); } And then the code you quote above sets the name (for the replicas) to the value specified by the properties included in the ReplicaSharedObjectDescription. The serialization/deserialization of shared object state is done explicitly rather than implicitly...so as to give the shared object programmer some control over the serialization. I was/have been thinking of adding some implicit serialization of shared object fields (perhaps through annotations processing or some such), but for the moment everything is explicitly done (via properties). > And another question: Does SharedObject API have any listeners that > calls when shared object has been added? > Yes, indeed. An IContainerEvent of sub-type ISharedObjectActivatedEvent is sent to any/all IContainerListeners before the shared object is activated, and similarly ISharedObjectDeactivatedEvent is sent before the shared object is deactivated. The shared object itself is also asynchronously notified as well (the shared object has a message queue and a thread created for it to process it's messages...and that's how the initialize method gets called on the replicas). Scott _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject APIHello All,
Scott, thanks for you reply. It works fine. I had understood SharedObject API and blogged about it http://samolisov.blogspot.com/2009/11/ecf-osgi.html (on Russian). Scott Lewis пишет: > Hi Pavel, > > Samolisov Pavel wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Thanks Scott. >> >> Tests works fine, my code works too. But I do not understand why this >> code is in TestSharedObject (in method initialize()): >> >> // This is a replica, so initialize the name from property >> name = (String) getConfig().getProperties().get(NAME_PROPERTY); >> >> Is this code a deserialization from Config to SharedObject? Why name do >> not replicate with SharedObject automaticaly? >> > > This code is only executed on the non-primary copy of the shared > object (i.e. the replicas). This code (run only on the primary copy), > is responsible for serializing the state of the shared object (in this > case, it's name): > > protected ReplicaSharedObjectDescription getReplicaDescription(ID > receiver) { > // Put primary state into properties and include in replica > description > final Map properties = new HashMap(); > properties.put(NAME_PROPERTY, name); > return new ReplicaSharedObjectDescription(this.getClass(), > getConfig().getSharedObjectID(), getConfig().getHomeContainerID(), > properties); > } > > And then the code you quote above sets the name (for the replicas) to > the value specified by the properties included in the > ReplicaSharedObjectDescription. The serialization/deserialization of > shared object state is done explicitly rather than implicitly...so as > to give the shared object programmer some control over the > serialization. I was/have been thinking of adding some implicit > serialization of shared object fields (perhaps through annotations > processing or some such), but for the moment everything is explicitly > done (via properties). > >> And another question: Does SharedObject API have any listeners that >> calls when shared object has been added? >> > > Yes, indeed. An IContainerEvent of sub-type > ISharedObjectActivatedEvent is sent to any/all IContainerListeners > before the shared object is activated, and similarly > ISharedObjectDeactivatedEvent is sent before the shared object is > deactivated. The shared object itself is also asynchronously notified > as well (the shared object has a message queue and a thread created > for it to process it's messages...and that's how the initialize method > gets called on the replicas). > > Scott > > -- Pavel Samolisov Meet me at: Vkontakte.ru: http://vkontakte.ru/id3178981 Blog: http://samolisov.blogspot.com Twitter: http://twitter.com/samolisov XMPP/Jabber: samolisov@... _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject APIHi Pavel,
Thanks for the blogging. Any chance that we could get your blog posting converted to English and made available somehow? Are there Russion to English conversion services that would do the trick? Thanks, Scott Samolisov Pavel wrote: > Hello All, > > Scott, thanks for you reply. It works fine. > I had understood SharedObject API and blogged about it > http://samolisov.blogspot.com/2009/11/ecf-osgi.html (on Russian). > > Scott Lewis пишет: > >> Hi Pavel, >> >> Samolisov Pavel wrote: >> >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> Thanks Scott. >>> >>> Tests works fine, my code works too. But I do not understand why this >>> code is in TestSharedObject (in method initialize()): >>> >>> // This is a replica, so initialize the name from property >>> name = (String) getConfig().getProperties().get(NAME_PROPERTY); >>> >>> Is this code a deserialization from Config to SharedObject? Why name do >>> not replicate with SharedObject automaticaly? >>> >>> >> This code is only executed on the non-primary copy of the shared >> object (i.e. the replicas). This code (run only on the primary copy), >> is responsible for serializing the state of the shared object (in this >> case, it's name): >> >> protected ReplicaSharedObjectDescription getReplicaDescription(ID >> receiver) { >> // Put primary state into properties and include in replica >> description >> final Map properties = new HashMap(); >> properties.put(NAME_PROPERTY, name); >> return new ReplicaSharedObjectDescription(this.getClass(), >> getConfig().getSharedObjectID(), getConfig().getHomeContainerID(), >> properties); >> } >> >> And then the code you quote above sets the name (for the replicas) to >> the value specified by the properties included in the >> ReplicaSharedObjectDescription. The serialization/deserialization of >> shared object state is done explicitly rather than implicitly...so as >> to give the shared object programmer some control over the >> serialization. I was/have been thinking of adding some implicit >> serialization of shared object fields (perhaps through annotations >> processing or some such), but for the moment everything is explicitly >> done (via properties). >> >> >>> And another question: Does SharedObject API have any listeners that >>> calls when shared object has been added? >>> >>> >> Yes, indeed. An IContainerEvent of sub-type >> ISharedObjectActivatedEvent is sent to any/all IContainerListeners >> before the shared object is activated, and similarly >> ISharedObjectDeactivatedEvent is sent before the shared object is >> deactivated. The shared object itself is also asynchronously notified >> as well (the shared object has a message queue and a thread created >> for it to process it's messages...and that's how the initialize method >> gets called on the replicas). >> >> Scott >> >> >> > > > _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
|
|
Re: Problem with SharedObject APIHi Scott.
Google Translator translates this text http://translate.google.ru/translate?js=y&prev=_t&hl=ru&ie=UTF-8&u=http%3A%2F%2Fsamolisov.blogspot.com%2F2009%2F11%2Fecf-osgi.html&sl=ru&tl=en&history_state0= But, it brokes code examples formatting and do not translate any termins correctly. Scott Lewis пишет: > Hi Pavel, > > Thanks for the blogging. Any chance that we could get your blog > posting converted to English and made available somehow? Are there > Russion to English conversion services that would do the trick? > > Thanks, > > Scott > > Samolisov Pavel wrote: >> Hello All, >> >> Scott, thanks for you reply. It works fine. >> I had understood SharedObject API and blogged about it >> http://samolisov.blogspot.com/2009/11/ecf-osgi.html (on Russian). >> >> Scott Lewis пишет: >> >>> Hi Pavel, >>> >>> Samolisov Pavel wrote: >>> >>>> -----BEGIN PGP SIGNED MESSAGE----- >>>> Hash: SHA1 >>>> >>>> Thanks Scott. >>>> >>>> Tests works fine, my code works too. But I do not understand why this >>>> code is in TestSharedObject (in method initialize()): >>>> >>>> // This is a replica, so initialize the name from property >>>> name = (String) getConfig().getProperties().get(NAME_PROPERTY); >>>> >>>> Is this code a deserialization from Config to SharedObject? Why >>>> name do >>>> not replicate with SharedObject automaticaly? >>>> >>> This code is only executed on the non-primary copy of the shared >>> object (i.e. the replicas). This code (run only on the primary copy), >>> is responsible for serializing the state of the shared object (in this >>> case, it's name): >>> >>> protected ReplicaSharedObjectDescription getReplicaDescription(ID >>> receiver) { >>> // Put primary state into properties and include in replica >>> description >>> final Map properties = new HashMap(); >>> properties.put(NAME_PROPERTY, name); >>> return new ReplicaSharedObjectDescription(this.getClass(), >>> getConfig().getSharedObjectID(), getConfig().getHomeContainerID(), >>> properties); >>> } >>> >>> And then the code you quote above sets the name (for the replicas) to >>> the value specified by the properties included in the >>> ReplicaSharedObjectDescription. The serialization/deserialization of >>> shared object state is done explicitly rather than implicitly...so as >>> to give the shared object programmer some control over the >>> serialization. I was/have been thinking of adding some implicit >>> serialization of shared object fields (perhaps through annotations >>> processing or some such), but for the moment everything is explicitly >>> done (via properties). >>> >>> >>>> And another question: Does SharedObject API have any listeners that >>>> calls when shared object has been added? >>>> >>> Yes, indeed. An IContainerEvent of sub-type >>> ISharedObjectActivatedEvent is sent to any/all IContainerListeners >>> before the shared object is activated, and similarly >>> ISharedObjectDeactivatedEvent is sent before the shared object is >>> deactivated. The shared object itself is also asynchronously notified >>> as well (the shared object has a message queue and a thread created >>> for it to process it's messages...and that's how the initialize method >>> gets called on the replicas). >>> >>> Scott >>> >>> >>> >> >> >> > -- Pavel Samolisov Meet me at: Vkontakte.ru: http://vkontakte.ru/id3178981 Blog: http://samolisov.blogspot.com Twitter: http://twitter.com/samolisov XMPP/Jabber: samolisov@... _______________________________________________ ecf-dev mailing list ecf-dev@... https://dev.eclipse.org/mailman/listinfo/ecf-dev |
| Free embeddable forum powered by Nabble | Forum Help |