BBjEnterpriseNamespace

Description

In BBj 13.0 and higher, BBjEnterpriseNamespace provides a mechanism by which two or more BBj programs on the same network can share data. It also provides methods that allow a program to be notified when that shared data is modified by some other program.

BBjEnterpriseNamespace

A BBjEnterpriseNamespace reference may be obtained by any BBj program through a call to the following method:

BBjAPI::getBBjEnterpriseNamespace(stringhost,intport,stringname,stringuser,stringpassword)

The BBjEnterpriseNamespace will be created the first time a reference is requested and will exist until the host BBjServices terminates or it is explicitly removed. The methods of a BBjEnterpriseNamespace are exactly the same as a regular BBjNamespace with the exception that only BBjStrings and BBjNumbers can be set as values.

The name of any BBjEnterpriseNamespace may be obtained by calling the method:

BBjEnterpriseNamespace::getName()


The NamedVariables within a BBjEnterpriseNamespace may be set and retrieved by calling the methods:

BBjEnterpriseNamespace::getValue(string varName)

BBjEnterpriseNamespace::getValue(string varName, longtimeoutMillis)

BBjEnterpriseNamespace::setValue(string varName, Object value)

BBjEnterpriseNamespace::setValue(string varName, Object value, long timeoutMillis)

BBjEnterpriseNamespace::setValue(string varName, BBjNumber value)

BBjEnterpriseNamespace::setValue(string varName, BBjNumber value, long timeoutMillis)


The value of a NamedVariable within a BBjEnterpriseNamespace may be locked/unlocked through calls to:

BBjEnterpriseNamespace::removeLock(string varName)

BBjEnterpriseNamespace::setLock(string varName,long timeoutMillis)

A BBj program may register/unregister to be notified when the value of a NamedVariable within a BBjEnterpriseNamespace has changed through calls to the methods:

BBjEnterpriseNamespace::setCallbackForVariable(string varName,string callback)

BBjEnterpriseNamespace::setCallbackForVariable(string varName, CustomObject customObj, string methodName)

BBjEnterpriseNamespace::setCallbackForVariableChange(string varName, string callback)

BBjEnterpriseNamespace::setCallbackForVariableChange(string varName, CustomObject customObj, string methodName)

BBjEnterpriseNamespace::setCallbackForNamespace(string callback)

BBjEnterpriseNamespace::setCallbackForNamespace(string customObj, string methodName)

BBjEnterpriseNamespace::setCallbackForNamespaceChange(string callback)

BBjEnterpriseNamespace::setCallbackForNamespaceChange(CustomObject customObj, string methodName)

BBjEnterpriseNamespace::removeCallbackForVariable(string varName)

BBjEnterpriseNamespace::removeCallbackForVariableChange(string varName)

BBjEnterpriseNamespace::removeCallbackForNamespace()

BBjEnterpriseNamespace::removeCallbackForNamespaceChange()

Creation

BBjAPI > BBjEnterpriseNamespace

The BBjEnterpriseNamespace object is created through the following BBjAPI object methods:

Return Value

Method

BBjEnterpriseNamespace

getBBjEnterpriseNamespace(string host, int port, string name, string user, string password)

Methods of BBjEnterpriseNamespace

Return Value

Method

void

clear()

java.util.HashMap

cloneMap()

void

enableCallbacks(int enable)

BBjVector

getKeys()

string

getName()

BBjObject

getValue(string name)

BBjObject

getValue(string name, long timeoutMillis)

void

removeCallbackForNamespace()

void

removeCallbackForNamespaceChange()

void

removeCallbackForVariable(string varName)

void

removeCallbackForVariableChange(string varName)

void

removeLock()

void

removeLock(string varName)

void

setCallbackForNamespace(string callback)

void

setCallbackForNamespace(CustomObject custObj, string methodName)

void

setCallbackForNamespaceChange(string callback)

void

setCallbackForNamespaceChange(CustomObject custObj, string methodName)

void

setCallbackForVariable(string varName, string callback)

void

setCallbackForVariable(string varName, CustomObject custObj, string methodName)

void

setCallbackForVariableChange(string varName, string callback)

void

setCallbackForVariableChange(string varName, CustomObject custObj, string methodName)

void

setLock(string name, long timeoutMillis)

void

setValue(string name, object value)

void

setValue(string name, object value, long timeoutMillis)

void

removeValue(string name)

void

removeValue(string name, long timeoutMillis)

Example

Copy
BBjEnterpriseNamespace Example
rem namespace.bbj
 
rem This is exactly the same as the normal namespace example except using a BBjEnterpriseNamespace for a shared namespace.
 
sysgui=unt
open (sysgui)"X0"
api! = BBjAPI()
sysgui!=api!.getSysGui()
 
REM host and login information for the BBjEnterpriseNamespace
host$="server"
port=2552
user$="user"
password$="password"
 
REM retrieve a namespace, get value of count
 
if api!.isInMDI()
sharedNS! = api!.getGroupNamespace()
prefix$ = "basis.eng.test.namespace"
else
if argc < 2
REM run from command line with no namespace name
prefix$ = "basis.eng.test.namespace"
sharedNSName$ = prefix$+".test"
sharedNS! = api!.getBBjEnterpriseNamespace(host$, port, sharedNSName$, user$, password$)
 
else
REM run from command line with a namespace name
prefix$ = argv(1)
sharedNSName$ = prefix$+".test"
sharedNS! = api!.getBBjEnterpriseNamespace(host$, port, sharedNSName$, user$, password$)
endif
endif
 
REM retrieve count from sharedNS! and use it to create our name
count = sharedNS!.getValue("count", err=setCount)
privateNS! = api!.getNewNamespace(prefix$)
privateNS!.setValue("count",0)
name$ = "client-" + privateNS!.getName()
 
REM retrieve position from sharedNS! and increment it
sharedNS!.setLock("x", 500, err = onLocked)
x = sharedNS!.getValue("x", err = setXY)
sharedNS!.setValue("x", x+50)
sharedNS!.removeLock()
 
sharedNS!.setLock("y", 500, err = onLocked)
y = sharedNS!.getValue("y", err = setXY)
sharedNS!.setValue("y", y+50)
sharedNS!.removeLock()
 
REM create window
window! = sysgui!.addWindow(x,y,300,200,name$)
 
REM add some static text fields
window!.addStaticText(101,5,50,290,30,"sharedCount: ")
window!.addStaticText(102,5,70,290,30,"privateCount: ")
 
REM add buttons and callbacks
plus! = window!.addButton(1,5,10,90,30,"Increment")
minus! = window!.addButton(2,105,10,90,30,"Decrement")
break! = window!.addButton(3,5,110,90,30,"Break")
 
sharedCount! = window!.addStaticText(103,200,50,290,15,str(count))
privateCount! = window!.addStaticText(104,200,70,290,15,str(0))
break!.setCallback(break!.ON_BUTTON_PUSH,"onBreak")
 
REM set callback for controls
plus!.setCallback(plus!.ON_BUTTON_PUSH, "onPlus")
minus!.setCallback(plus!.ON_BUTTON_PUSH, "onMinus")
window!.setCallback(window!.ON_ACTIVATE, "onActivate")
 
REM set callback that is to be called when count changes
sharedNS!.setCallbackForVariable("count", "showCount")
privateNS!.setCallbackForVariable("count", "showCount")
 
REM call onActivate to set tell others we have activated
gosub onActivate
 
callback(ON_CLOSE,done,sysgui!.getContext())
 
REM if running in MDI, register a callback for MDI closing
 
if api!.isInMDI()
mdi! = api!.getMDI()
mdi!.registerMDIClosingCallback("mdiClosingCallback")
endif
 
process_events
 
REM our callbacks
onPlus:
sharedNS!.setLock("count",1500,err = onLocked)
sharedNS!.setValue("count", 1 + sharedNS!.getValue("count"))
sharedNS!.removeLock()
 
privateNS!.setLock("count",1500,err = onLocked)
privateNS!.setValue("count", 1 + privateNS!.getValue("count"))
privateNS!.removeLock()
return
 
onMinus:
sharedNS!.setLock("count",1500,err = onLocked)
sharedNS!.setValue("count", -1 + sharedNS!.getValue("count"))
sharedNS!.removeLock()
 
privateNS!.setLock("count",1500,err = onLocked)
privateNS!.setValue("count", -1 + privateNS!.getValue("count"))
privateNS!.removeLock()
return
 
onActivate:
sharedNS!.setValue("activeClientNS", privateNS!.getName())
sharedNS!.setValue("activeClientName",name$)
return
 
showCount:
sharedcount!.setText(str(sharedNS!.getValue("count")))
privatecount!.setText(str(privateNS!.getValue("count")))
return
 
onBreak:
escape
return
 
done:
release
 
setXY:
x = 100
y = 100
sharedNS!.setValue("x", x)
sharedNS!.setValue("y", y)
retry
 
setCount:
count = 0
sharedNS!.setValue("count", count)
retry
 
onLocked:
print "lock error"
escape
retry
m
REM callback to be run when MDI attempts to close
mdiClosingCallback:
print 'EE', 'ask'("MDI is attempting to close",3,"What do you want to do?","Veto close:1","Accept close:2","Release:3")
 
print 'BE'
 
read(0,siz=1,err=askCancelled)response
print "answer is " , response
print 'BE'
 
switch response
case 1
mdi!.vetoMDIClose()
break
case 2
mdi!.approveMDIClose()
break
case 3
gosub done
break
swend
return
 
askCancelled:
print "ask was cancelled or else closeAll() timed out"
mdi!.approveMDIClose(err=*next)
return

See Also

BBjAPI

BBj Object Variables

BBj Object Assignment

BBj Object Error Handling

BBj Object Operators

Accessing Objects From Different Interpreters

BBjNamespaceEvent

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.