Class ClientSharedObject

All Implemented Interfaces:
IEventDispatcher, IAttributeStore, ICastingAttributeStore, IPersistable, IServiceHandlerProvider, IClientSharedObject, ISharedObjectBase, ISharedObjectHandlerProvider, ISharedObjectStatistics, IStatisticsBase, AttributeStoreMXBean, Constants

public class ClientSharedObject extends SharedObject implements IClientSharedObject, IEventDispatcher
Works with client-side shared object
  • Field Details

    • log

      protected static org.slf4j.Logger log
  • Constructor Details

    • ClientSharedObject

      public ClientSharedObject(String name, boolean persistent)
      Create new client SO with
      Parameters:
      name - Shared Object name
      persistent - Persistence flag
  • Method Details

    • connect

      public void connect(IConnection conn)
      Connect the shared object using the passed connection.
      Specified by:
      connect in interface IClientSharedObject
      Parameters:
      conn - Attach SO to given connection
    • disconnect

      public void disconnect()
      Disconnect the shared object.
      Specified by:
      disconnect in interface IClientSharedObject
    • isConnected

      public boolean isConnected()
      Check if the shared object is connected to the server.
      Specified by:
      isConnected in interface IClientSharedObject
      Returns:
      is connected
    • addSharedObjectListener

      public void addSharedObjectListener(ISharedObjectListener listener)
      Register object that will be notified about update events.
      Specified by:
      addSharedObjectListener in interface ISharedObjectBase
      Parameters:
      listener - the object to notify
    • removeSharedObjectListener

      public void removeSharedObjectListener(ISharedObjectListener listener)
      Unregister object to not longer receive update events.
      Specified by:
      removeSharedObjectListener in interface ISharedObjectBase
      Parameters:
      listener - the object to unregister
    • dispatchEvent

      public void dispatchEvent(IEvent e)
      Dispatches event
      Specified by:
      dispatchEvent in interface IEventDispatcher
      Parameters:
      e - Event object
    • notifyConnect

      protected void notifyConnect()
      Notify listeners on event
    • notifyDisconnect

      protected void notifyDisconnect()
      Notify listeners on disconnect
    • notifyUpdate

      protected void notifyUpdate(String key, Object value)
      Notify listeners on update
      Parameters:
      key - Updated attribute key
      value - Updated attribute value
    • notifyUpdate

      protected void notifyUpdate(String key, Map<String,Object> value)
      Notify listeners on map attribute update
      Parameters:
      key - Updated attribute key
      value - Updated attribute value
    • notifyDelete

      protected void notifyDelete(String key)
      Notify listeners on attribute delete
      Parameters:
      key - Attribute name
    • notifyClear

      protected void notifyClear()
      Notify listeners on clear
    • notifySendMessage

      protected void notifySendMessage(String method, List<?> params)
      Broadcast send event to listeners
      Parameters:
      method - Method name
      params - Params
    • setAttribute

      public boolean setAttribute(String name, Object value)
      Set an attribute on this object.
      Specified by:
      setAttribute in interface IAttributeStore
      Overrides:
      setAttribute in class SharedObject
      Parameters:
      name - the name of the attribute to change
      value - the new value of the attribute
      Returns:
      true if the attribute value was added or changed, otherwise false
    • setAttributes

      public boolean setAttributes(IAttributeStore values)
      Set multiple attributes on this object.
      Specified by:
      setAttributes in interface IAttributeStore
      Overrides:
      setAttributes in class SharedObject
      Parameters:
      values - the attributes to set
      Returns:
      true if the attribute values changed otherwise false
    • setAttributes

      public boolean setAttributes(Map<String,Object> values)
      Set multiple attributes on this object.
      Specified by:
      setAttributes in interface IAttributeStore
      Overrides:
      setAttributes in class SharedObject
      Parameters:
      values - the attributes to set
      Returns:
      true if the attribute values changed otherwise false
    • removeAttribute

      public boolean removeAttribute(String name)
      Remove an attribute.
      Specified by:
      removeAttribute in interface AttributeStoreMXBean
      Specified by:
      removeAttribute in interface IAttributeStore
      Overrides:
      removeAttribute in class SharedObject
      Parameters:
      name - the name of the attribute to remove
      Returns:
      true if the attribute was found and removed otherwise false
    • sendMessage

      public void sendMessage(String handler, List<?> arguments)
      Broadcast event to event handler
      Specified by:
      sendMessage in interface ISharedObjectBase
      Overrides:
      sendMessage in class SharedObject
      Parameters:
      handler - Event handler
      arguments - Arguments
    • removeAttributes

      public void removeAttributes()
      Remove all attributes.
      Specified by:
      removeAttributes in interface AttributeStoreMXBean
      Specified by:
      removeAttributes in interface IAttributeStore
      Overrides:
      removeAttributes in class SharedObject
    • clear

      public boolean clear()
      Deletes all the attributes and sends a clear event to all listeners. The persistent data object is also removed from a persistent shared object.
      Specified by:
      clear in interface ISharedObjectBase
      Overrides:
      clear in class SharedObject
      Returns:
      true on success, false otherwise
    • close

      public void close()
      Detaches a reference from this shared object, reset it's state, this will destroy the reference immediately. This is useful when you don't want to proxy a shared object any longer.
      Specified by:
      close in interface ISharedObjectBase
      Overrides:
      close in class SharedObject
    • registerServiceHandler

      public void registerServiceHandler(Object handler)
      Register an object that provides methods which handle calls without a service name to a shared object.
      Specified by:
      registerServiceHandler in interface ISharedObjectHandlerProvider
      Parameters:
      handler - the handler object
    • unregisterServiceHandler

      public void unregisterServiceHandler(String name)
      Unregister the shared object handler for calls without a service name.
      Specified by:
      unregisterServiceHandler in interface IServiceHandlerProvider
      Specified by:
      unregisterServiceHandler in interface ISharedObjectHandlerProvider
      Parameters:
      name - the name of the handler
    • registerServiceHandler

      public void registerServiceHandler(String name, Object handler)
      Register an object that provides methods which can be called from a client.
      Example:
      If you registered a handler with the name "
       one.two
       
      " that provides a method "
       callMe
       
      ", you can call a method "
       one.two.callMe
       
      " from the client.
      Specified by:
      registerServiceHandler in interface IServiceHandlerProvider
      Parameters:
      name - the name of the handler
      handler - the handler object
    • getServiceHandler

      public Object getServiceHandler(String name)
      Return a previously registered service handler.
      Specified by:
      getServiceHandler in interface IServiceHandlerProvider
      Parameters:
      name - the name of the handler to return
      Returns:
      the previously registered handler
    • getServiceHandlerNames

      public Set<String> getServiceHandlerNames()
      Get list of registered service handler names.
      Specified by:
      getServiceHandlerNames in interface IServiceHandlerProvider
      Returns:
      the names of the registered handlers
    • getAttribute

      public Object getAttribute(String name, Object defaultValue)
      Return the value for a given attribute and set it if it doesn't exist. This is a utility function that internally performs the following code:
       if (!hasAttribute(name))
           setAttribute(name, defaultValue);
       return getAttribute(name);
       
      Specified by:
      getAttribute in interface IAttributeStore
      Overrides:
      getAttribute in class SharedObject
      Parameters:
      name - the name of the attribute to get
      defaultValue - the value of the attribute to set if the attribute doesn't exist
      Returns:
      the attribute value