Packagecom.adobe.rtc.sharedModel
Classpublic class SharedObject
InheritanceSharedObject Inheritance flash.events.EventDispatcher
ImplementsISessionSubscriber

SharedObject is used to store data in an unordered hash (key-value) across the LCCS services; elements can only be accessed using its key.

A SharedObject can be used in situations where you need to access a property using its key value as opposed to index. Similar to SharedCollection and SharedProperty,this component supports "piggybacking" on existing CollectionNodes, through its collectionNode property and its subscribe method. Developers can avoid CollectionNode proliferation in their applications by pre-supplying a CollectionNode (to the collectionNode property) and a nodeName (in the subscribe method) for the SharedObject to use. If none is supplied, the SharedObject will create its own collectionNode (named for the uniqueID supplied in subscribe()) for sending and receiving messages.

Using shared objects
   
  protected var _collectionNode:CollectionNode;
  protected var _sharedObject:com.adobe.rtc.sharedModel.SharedObject;
  
  protected function initializeSharedObject():void
  {
   _collectionNode=new CollectionNode();
   _collectionNode.connectSession="YOUR APPS CONNECT SESSION";
   _collectionNode.sharedID="tmpCollectionNode";
   _sharedObject=new com.adobe.rtc.sharedModel.SharedObject();
   _sharedObject.collectionNode=_collectionNode;
   _sharedObject.connectSession=sess;
   _sharedObject.nodeName="sharedHash";
   _sharedObject.sharedID="tmpCollectionNode";
   //Subscribe to your collection nodes that does the magic :)
   _collectionNode.subscribe();
     _sharedObject.subscribe();
   _sharedObject.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSharedObjSync);
   _sharedObject.addEventListener(SharedObjectEvent.PROPERTY_REMOVE,onSharedObjChange);
   _sharedObject.addEventListener(SharedObjectEvent.PROPERTY_ADD,onSharedObjChange);
   _sharedObject.addEventListener(SharedObjectEvent.PROPERTY_CHANGE,onSharedObjChange);
  }
  
  protected function onSharedObjSync(p_evt:CollectionNodeEvent):void
  {
   if (_sharedObject.isSynchronized) {
    _sharedObject.setProperty("key1", "demo1");
    _sharedObject.setProperty("key2", 2);
    // Modifying the property "key1"
    _sharedObject.setProperty("key1", "key1 Mutated");
    // Removing the demo1 property from SharedObject
    _sharedObject.removeProperty("key2");
    // Removing all the properties from the SharedObject
    _sharedObject.removeAll();
   }
  }
  
  protected function onSharedObjChange(p_evt:SharedObjectEvent):void
  {
   if (_sharedObject.isSynchronized) {
    var key:String = p_evt.propertyName;
    // Example of SharedObject.getProperty
    // Check if the SharedObject is empty
   }
  }

See also

com.adobe.rtc.sharedModel.SharedCollection
com.adobe.rtc.sharedModel.SharedProperty


Public Properties
 PropertyDefined by
  collectionNode : CollectionNode
Specifies an existing collectionNode to use in case a developer wishes to supply their own, and avoid having the sharedObject create a new one.
SharedObject
  connectSession : IConnectSession
The IConnectSession with which this component is associated.
SharedObject
  isSynchronized : Boolean
[read-only] Returns whether or not the SharedObject has retrieved any information previously stored on the service, and is currently connected to the service.
SharedObject
  nodeName : String
Sets the Node name for the node being created
SharedObject
  sharedID : String
Defines the logical location of the component on the service - typically this assigns the sharedID of the collectionNode used by the component.
SharedObject
  values : Object
[read-only] Return all the items in the shared object as one big hashMap (Object)
SharedObject
Public Methods
 MethodDefined by
  
The SharedObject constructor
SharedObject
  
close():void
Disposes all listeners to the network and framework classes.
SharedObject
  
getProperty(p_propertyName:String):*
Returns the value of the given property name
SharedObject
  
getUserRole(p_userID:String):int
Returns the role of a given user for the SharedObject.
SharedObject
  
hasProperty(p_propertyName:String):Boolean
Returns whether the given property exists or not in the shared object
SharedObject
  
isEmpty():Boolean
Check if the shared object is empty
SharedObject
  
removeAll():void
Remove all the items in the shared object.
SharedObject
  
removeProperty(p_propertyName:String):void
Remove the property from the shared object
SharedObject
  
Sets the Node Configuration on a already defined node that holds the sharedObject
SharedObject
  
setProperty(p_propertyName:String, p_value:Object = null):void
Add or Update the value of a given property name in a shared object
SharedObject
  
setUserRole(p_userID:String, p_userRole:int):void
Sets the role of a given user for the SharedObject.
SharedObject
  
subscribe():void
Tells the component to begin synchronizing with the service.
SharedObject
Events
 EventSummaryDefined by
   Dispatched when an item to SharedObject is added.SharedObject
   Dispatched when the SharedObject has been updated in some way.SharedObject
   Dispatched when an item from SharedObject is removed.SharedObject
   The type of event emitted when the CollectionNode is about to reconnect to the server.SharedObject
   Dispatched when the SharedObject goes in and out of sync with the service.SharedObject
Property detail
collectionNodeproperty
collectionNode:CollectionNode  [read-write]

Specifies an existing collectionNode to use in case a developer wishes to supply their own, and avoid having the sharedObject create a new one.

Implementation
    public function get collectionNode():CollectionNode
    public function set collectionNode(value:CollectionNode):void
connectSessionproperty 
connectSession:IConnectSession  [read-write]

The IConnectSession with which this component is associated. Note that this may only be set once before subscribe is called; re-sessioning of components is not supported. Defaults to the first IConnectSession created in the application.

Implementation
    public function get connectSession():IConnectSession
    public function set connectSession(value:IConnectSession):void
isSynchronizedproperty 
isSynchronized:Boolean  [read-only]

Returns whether or not the SharedObject has retrieved any information previously stored on the service, and is currently connected to the service.

This property can be used as the source for data binding.

Implementation
    public function get isSynchronized():Boolean
nodeNameproperty 
nodeName:String  [read-write]

Sets the Node name for the node being created

Implementation
    public function get nodeName():String
    public function set nodeName(value:String):void
sharedIDproperty 
sharedID:String  [read-write]

Defines the logical location of the component on the service - typically this assigns the sharedID of the collectionNode used by the component. sharedIDs should be unique within a room (if they're expressing 2 unique locations). Note that this can only be assigned once (before subscribe() is called). For components with an id property, sharedID defaults to that value.

Implementation
    public function get sharedID():String
    public function set sharedID(value:String):void
valuesproperty 
values:Object  [read-only]

Return all the items in the shared object as one big hashMap (Object)

Implementation
    public function get values():Object
Constructor detail
SharedObject()constructor
public function SharedObject()

The SharedObject constructor

Method detail
close()method
public function close():void

Disposes all listeners to the network and framework classes. Recommended for proper garbage collection of the component.

getProperty()method 
public function getProperty(p_propertyName:String):*

Returns the value of the given property name

Parameters
p_propertyName:String — The key of the Property whose value is requested.

Returns
*
getUserRole()method 
public function getUserRole(p_userID:String):int

Returns the role of a given user for the SharedObject.

Parameters
p_userID:String — The user ID for the user being queried.

Returns
int
hasProperty()method 
public function hasProperty(p_propertyName:String):Boolean

Returns whether the given property exists or not in the shared object

Parameters
p_propertyName:String — The key of the Property whose presence is verified

Returns
Boolean
isEmpty()method 
public function isEmpty():Boolean

Check if the shared object is empty

Returns
Boolean
removeAll()method 
public function removeAll():void

Remove all the items in the shared object.

removeProperty()method 
public function removeProperty(p_propertyName:String):void

Remove the property from the shared object

Parameters
p_propertyName:String — The key of the Property that needs to be retracted from the sharedObject
setNodeConfiguration()method 
public function setNodeConfiguration(p_nodeConfig:NodeConfiguration):void

Sets the Node Configuration on a already defined node that holds the sharedObject

Parameters
p_nodeConfig:NodeConfiguration — The Node Configuration
setProperty()method 
public function setProperty(p_propertyName:String, p_value:Object = null):void

Add or Update the value of a given property name in a shared object

Parameters
p_propertyName:String — The key of the Property being added
 
p_value:Object (default = null) — The value of the property, defaults to null
setUserRole()method 
public function setUserRole(p_userID:String, p_userRole:int):void

Sets the role of a given user for the SharedObject.

Parameters
p_userID:String — The role value to set on the specified user.
 
p_userRole:int — The ID of the user whose role should be set.
subscribe()method 
public function subscribe():void

Tells the component to begin synchronizing with the service. For "headless" components such as this one, this method must be called explicitly.

Event detail
propertyAddevent 
Event object type: com.adobe.rtc.events.SharedObjectEvent

Dispatched when an item to SharedObject is added.

propertyChangeevent  
Event object type: com.adobe.rtc.events.SharedObjectEvent

Dispatched when the SharedObject has been updated in some way.

propertyRetractedevent  
Event object type: com.adobe.rtc.events.SharedObjectEvent

Dispatched when an item from SharedObject is removed.

reconnectevent  
Event object type: com.adobe.rtc.events.CollectionNodeEvent

The type of event emitted when the CollectionNode is about to reconnect to the server. This typically happens automatically if the SharedObject is still subscribed. The typical response to this event is to re-initialize any shared parts of a model from scratch since they are about to be re-received from the server.

synchronizationChangeevent  
Event object type: com.adobe.rtc.events.CollectionNodeEvent

Dispatched when the SharedObject goes in and out of sync with the service.





 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/sharedModel/SharedObject.html