equip.data
Class DataProxyImpl

java.lang.Object
  extended byequip.runtime.Object
      extended byequip.runtime.ValueBase
          extended byequip.net.ServiceProxy
              extended byequip.data.DataProxy
                  extended byequip.data.DataProxyImpl
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable

public class DataProxyImpl
extends DataProxy
implements java.lang.Runnable

The normal implementation of the IDL'd dataspace API, DataProxy; implements a dataspace client, delegating most of the work to an instance of class DataDelegate.

Note 1: you should NOT normally create these directly; use the singleton DataManager to allow sharing of dataspace replicas within a single application.

Note 2: you will probably find the IDataspace API easier to use and more familar in terms of Java idiom (see DataspaceBean).


Nested Class Summary
(package private)  class DataProxyImpl.ActivateThread
           
(package private)  class DataProxyImpl.MyDeactivateCallback
           
(package private)  class DataProxyImpl.WaitCallback
           
 
Field Summary
(package private)  int ackSeq
           
(package private)  boolean activateAsyncFlag
           
(package private)  boolean activeFlag
           
(package private)  DeactivateCallback callback
           
(package private)  DeactivateCallback deactivateCallback
           
(package private)  ValueBase deactivateClosure
           
(package private)  GUID defaultAgentId
           
(package private)  DataDelegatePeerTCP driver
           
(package private)  int lastAckSeq
           
(package private)  boolean persistFlag
           
(package private)  DataDelegatePeer serverPeer
           
(package private)  boolean waitInited
           
(package private)  DataSession waitSession
           
 
Fields inherited from class equip.data.DataProxy
initialItems
 
Fields inherited from class equip.net.ServiceProxy
serviceMoniker
 
Constructor Summary
DataProxyImpl()
           
DataProxyImpl(GUID responsible)
           
 
Method Summary
 boolean activate(DeactivateCallback callback, ValueBase closure)
          Request activation of the service proxy, i.e. connect to server.
 void activateAsync()
          Create a thread to repeatedly attempt to activate this dataspace (assuming that it is a client) whenever its activation fails.
 boolean activateInternal(DeactivateCallback callback, ValueBase closure, boolean startInputThread)
           
 void addEvent(Event event)
          Add a new event into the dataspace.
 void addItem(ItemData item, int locked, boolean processBound, boolean local, Lease itemLease)
          add item event helper - create and publish an AddEvent.
 void beginBusy()
          this dangerous internal API lets you suspend the enactment of events; also make a matching call to endBusy().
 DataSession createSession(DataCallback callback, ValueBase closure)
          Create a new data session in which to express interest in events and data items and to get callbacks/notifications.
 void deactivate()
          Request deactivation of an (active) service proxy, i.e.
 void deleteItem(GUID id, boolean local)
          delete item event helper - create and publish an DeleteEvent.
 void deleteSession(DataSession session)
          Delete a DataSession previously created with createSession(equip.data.DataCallback, equip.runtime.ValueBase); effectively any remaining EventPatterns will be removed.
 void endBusy()
          this dangerous internal API lets you resume the enactment of events; only call to match a previous call to beginBusy().
 double getConnectionStrength()
           
 ItemData getItem(GUID id)
          Get an ItemData from the local dataspace by item GUID.
 ItemBinding getItemBinding(GUID id)
          Get an ItemBinding from the local dataspace by item GUID.
 GUID getResponsible()
          get responsible (replica) ID
 int getUnsentEvents()
          return number of unsent events - connection and outboundEvents
(package private)  void init(GUID responsible)
           
(package private)  void initWaitForEvents()
           
(package private)  void jbInit()
           
 void notifyDeactivate(ServiceProxy proxy, ValueBase closure)
           
 void queueEvent(Event event)
          (always) Queued add of a new event into the dataspace.
 void run()
           
 void setDefaultAgent(GUID defaultAgentId)
          Set a default GUID to be used as the default owner and/or requestor for locally generated events and data items.
 void setPersist(boolean persistFlag)
          Whether this dataspace replica should try to associate persistently with its server/peer.
 void terminate()
          Destroy this dataspace, terminating any communication and threads and (hopefully) allowing all resources to be released/GCed.
 void updateItem(ItemData item, boolean local, boolean reliable)
          update item event helper - create and publish an UpdateEvent with default priority (0).
 void updateItem2(ItemData item, boolean local, boolean reliable, int priority)
          update item event helper - create and publish an UpdateEvent.
 void waitForEvents(boolean local)
          Block and wait for all pending events to be enacted.
 
Methods inherited from class equip.data.DataProxy
_equals_helper, _matches_helper, equals, getModuleName, matches, readObject, writeObject
 
Methods inherited from class equip.net.ServiceProxy
_equals_helper, _matches_helper
 
Methods inherited from class equip.runtime.ValueBase
_equals_helper, _matches_helper, clone
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultAgentId

GUID defaultAgentId

serverPeer

DataDelegatePeer serverPeer

driver

DataDelegatePeerTCP driver

persistFlag

boolean persistFlag

activeFlag

boolean activeFlag

activateAsyncFlag

boolean activateAsyncFlag

callback

DeactivateCallback callback

deactivateCallback

DeactivateCallback deactivateCallback

deactivateClosure

ValueBase deactivateClosure

waitInited

boolean waitInited

waitSession

DataSession waitSession

ackSeq

int ackSeq

lastAckSeq

int lastAckSeq
Constructor Detail

DataProxyImpl

public DataProxyImpl()

DataProxyImpl

public DataProxyImpl(GUID responsible)
Method Detail

init

void init(GUID responsible)

setPersist

public void setPersist(boolean persistFlag)
Description copied from class: DataProxy
Whether this dataspace replica should try to associate persistently with its server/peer. A persistent association will not be garbage collected when the underlying network connection is removed or fails. This option is largely untested at the moment, and should really have a Lease mechanism to handle garbage collection: use with care.

Note that replicas are identified to each other by the responsible GUID of each.

Specified by:
setPersist in class DataProxy
Parameters:
persistFlag - Whether to connect persistently.

addEvent

public void addEvent(Event event)
Description copied from class: DataProxy
Add a new event into the dataspace. Note that if the dataspace is already busy (e.g. in an event notification callback) then the event will be queued internally for subsequent asynchronous delivery.

Specified by:
addEvent in class DataProxy
Parameters:
event - The event to published.

queueEvent

public void queueEvent(Event event)
(always) Queued add of a new event into the dataspace.

Specified by:
queueEvent in class DataProxy
Parameters:
event - The event to published.

getItemBinding

public ItemBinding getItemBinding(GUID id)
Description copied from class: DataProxy
Get an ItemBinding from the local dataspace by item GUID.

Specified by:
getItemBinding in class DataProxy
Parameters:
id - The item's GUID.
Returns:
The item's binding to the dataspace replica, or null if unknown.

getItem

public ItemData getItem(GUID id)
Description copied from class: DataProxy
Get an ItemData from the local dataspace by item GUID.

Specified by:
getItem in class DataProxy
Parameters:
id - The item's GUID.
Returns:
The item's value in the dataspace replica, or null if unknown.

setDefaultAgent

public void setDefaultAgent(GUID defaultAgentId)
Description copied from class: DataProxy
Set a default GUID to be used as the default owner and/or requestor for locally generated events and data items.

Specified by:
setDefaultAgent in class DataProxy
Parameters:
defaultAgentId - GUID to use as default owner/requestor

addItem

public void addItem(ItemData item,
                    int locked,
                    boolean processBound,
                    boolean local,
                    Lease itemLease)
Description copied from class: DataProxy
add item event helper - create and publish an AddEvent.

Specified by:
addItem in class DataProxy
Parameters:
item - The value of the new item (including id).
locked - See ItemBindingInfo.locked.
processBound - See ItemBindingInfo.processBound.
local - See ItemBindingInfo.local.
itemLease - See ItemBindingInfo.itemLease.

updateItem

public void updateItem(ItemData item,
                       boolean local,
                       boolean reliable)
Description copied from class: DataProxy
update item event helper - create and publish an UpdateEvent with default priority (0). NOTE: if this is an item with a lease and you want the lease to be renewed then use an addItem repeatedly instead (with the new Lease value in the ItemBinding).

Specified by:
updateItem in class DataProxy
Parameters:
item - The new value of the item (including original id).
local - See EventMetadata.local.
reliable - See EventMetadata.reliable.

updateItem2

public void updateItem2(ItemData item,
                        boolean local,
                        boolean reliable,
                        int priority)
Description copied from class: DataProxy
update item event helper - create and publish an UpdateEvent. NOTE: if this is an item with a lease and you want the lease to be renewed then use an addItem repeatedly instead (with the new Lease value in the ItemBinding).

Specified by:
updateItem2 in class DataProxy
Parameters:
item - The new value of the item (including original id).
local - See EventMetadata.local.
reliable - See EventMetadata.reliable.
priority - See EventMetadata.priority.

deleteItem

public void deleteItem(GUID id,
                       boolean local)
Description copied from class: DataProxy
delete item event helper - create and publish an DeleteEvent.

Specified by:
deleteItem in class DataProxy
Parameters:
id - The GUID of the item to be deleted.
local - See EventMetadata.local.

createSession

public DataSession createSession(DataCallback callback,
                                 ValueBase closure)
Description copied from class: DataProxy
Create a new data session in which to express interest in events and data items and to get callbacks/notifications. See also information about DataCallback and (usually easier to use) DataCallbackPost.

Specified by:
createSession in class DataProxy
Parameters:
callback - Event-handling subclass of DataCallback or DataCallbackPost, notified about events matching any EventPatterns that are added to new session.
closure - Optional application parameter provided to the callback notification (can be null).
Returns:
A new DataSession to which EventPatterns can be added to cause replication and/or notifications of events and items.

deleteSession

public void deleteSession(DataSession session)
Description copied from class: DataProxy
Delete a DataSession previously created with DataProxy.createSession(equip.data.DataCallback, equip.runtime.ValueBase); effectively any remaining EventPatterns will be removed.

In C++ the caller will still hold the last reference to the data session object, which must be released in order for the session object to actually be deleted.

Specified by:
deleteSession in class DataProxy
Parameters:
session - The DataSession object returned from DataProxy.createSession(equip.data.DataCallback, equip.runtime.ValueBase) to be deleted from the dataspace.

activateAsync

public void activateAsync()
Description copied from class: DataProxy
Create a thread to repeatedly attempt to activate this dataspace (assuming that it is a client) whenever its activation fails. This is an alternative to ServiceProxy.activate(equip.net.DeactivateCallback, equip.runtime.ValueBase) and ServiceProxy.deactivate() which are also implemented for direct control over activation.

Specified by:
activateAsync in class DataProxy

activate

public boolean activate(DeactivateCallback callback,
                        ValueBase closure)
Description copied from class: ServiceProxy
Request activation of the service proxy, i.e. connect to server.

Specified by:
activate in class ServiceProxy
Returns:
success (true = ok). If true, and callback!=null then if the communication fails before deactivate is intiated then callback will be notified.

activateInternal

public boolean activateInternal(DeactivateCallback callback,
                                ValueBase closure,
                                boolean startInputThread)

deactivate

public void deactivate()
Description copied from class: ServiceProxy
Request deactivation of an (active) service proxy, i.e. disconnect from server.

Specified by:
deactivate in class ServiceProxy

notifyDeactivate

public void notifyDeactivate(ServiceProxy proxy,
                             ValueBase closure)

run

public void run()
Specified by:
run in interface java.lang.Runnable

getConnectionStrength

public double getConnectionStrength()

getUnsentEvents

public int getUnsentEvents()
return number of unsent events - connection and outboundEvents


initWaitForEvents

void initWaitForEvents()

waitForEvents

public void waitForEvents(boolean local)
Description copied from class: DataProxy
Block and wait for all pending events to be enacted. Be careful or this will deadlock, so make sure nothing else is going on in that thread!. Only in Java, at the moment (2003-10-16).

Specified by:
waitForEvents in class DataProxy
Parameters:
local - Wait only for local events (if false, then also send a message to the server dataspace and wait for it to come back as well).

jbInit

void jbInit()

beginBusy

public void beginBusy()
Description copied from class: DataProxy
this dangerous internal API lets you suspend the enactment of events; also make a matching call to DataProxy.endBusy(). Easy to deadlock with unmatched calls!

Specified by:
beginBusy in class DataProxy

endBusy

public void endBusy()
Description copied from class: DataProxy
this dangerous internal API lets you resume the enactment of events; only call to match a previous call to DataProxy.beginBusy(). Easy to deadlock - or break synchronization - with unmatched calls!

Specified by:
endBusy in class DataProxy

getResponsible

public GUID getResponsible()
get responsible (replica) ID

Specified by:
getResponsible in class DataProxy
Returns:
The dataspace replica's own GUID.

terminate

public void terminate()
Destroy this dataspace, terminating any communication and threads and (hopefully) allowing all resources to be released/GCed.

Specified by:
terminate in class DataProxy