mnjstwins
12/9/2016 - 6:21 PM

remote-proxy-classes.xml

<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2016.4 (Build 555U JAVAINTEG)" ts="2016-07-18 15:27:06">
<Class name="Sample.LoggingProxy">
<Description>
simple sample of a logging proxy object:
each access (via call or property access) will 
be logged to the designated global</Description>
<Super>%RegisteredObject</Super>
<TimeChanged>64116,57644.95789</TimeChanged>
<TimeCreated>64110,60845.71095</TimeCreated>

<Parameter name="LoggingGlobal">
<Description>
log access log to this global</Description>
<Type>%String</Type>
<Default>^Sample.LoggingProxy</Default>
</Parameter>

<Property name="OpenedObject">
<Description>
keep openedobject for the proxy access later</Description>
<Type>%RegisteredObject</Type>
</Property>

<Method name="Log">
<Description>
generic log utility, which save new string as a next global entry</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>Value:%String</FormalSpec>
<Implementation><![CDATA[
    #dim gloRef = ..#LoggingGlobal
    set @gloRef@($increment(@gloRef)) = Value
]]></Implementation>
</Method>

<Method name="LogArgs">
<Description>
more convenient log method for writing prefix (i.e. method name)
and arguments we were called in</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>prefix:%String,args...</FormalSpec>
<Implementation><![CDATA[
    #dim S as %String = $get(prefix) _ ": " _ $get(args(1))
    #dim i as %Integer
    for i=2:1:$get(args) {
        set S = S_","_args(i)
    }
    do ..Log(S)
]]></Implementation>
</Method>

<Method name="%CreateInstance">
<Description>
open instance of a different class using given %ID</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>className:%String,%ID:%String</FormalSpec>
<ReturnType>Sample.LoggingProxy</ReturnType>
<Implementation><![CDATA[
    #dim wrapper = ..%New()
    set wrapper.OpenedObject = $classmethod(className, "%OpenId", %ID)
    return wrapper
]]></Implementation>
</Method>

<Method name="%DispatchMethod">
<Description>
log arguments and then dispatch dynamically method to the proxy object</Description>
<FormalSpec>methodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    do ..LogArgs(methodName, args...)
    return $method(..OpenedObject, methodName, args...)
]]></Implementation>
</Method>

<Method name="%DispatchClassMethod">
<Description>
log arguments and then dispatch dynamically class-method to the proxy object</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>className:%String,methodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    do ..LogArgs(className_"::"_methodName, args...)
    return $classmethod(className, methodName, args...) // FIXME - FRAMESTACK
]]></Implementation>
</Method>

<Method name="%DispatchGetProperty">
<Description>
log arguments and then dispatch dynamically property access to the proxy object</Description>
<FormalSpec>Property:%String</FormalSpec>
<Implementation><![CDATA[
    #dim Value as %String = $property(..OpenedObject, Property)
    do ..LogArgs(Property, Value)
    return Value
]]></Implementation>
</Method>

<Method name="%DispatchSetProperty">
<Description>
log arguments and then dispatch dynamically property access to the proxy object</Description>
<FormalSpec>Property,Value:%String</FormalSpec>
<Implementation><![CDATA[
    do ..LogArgs(Property, Value)
    set $property(..OpenedObject, Property) = Value
]]></Implementation>
</Method>
</Class>


<Class name="Sample.RemoteProxy.Object">
<Description>
sample of a remote proxy using %Net.RemoteConnection</Description>
<Super>%RegisteredObject</Super>
<TimeChanged>64116,9199.418879</TimeChanged>
<TimeCreated>64115,83996.532254</TimeCreated>

<Property name="OpenedObject">
<Description>
keep openedobject for the proxy access later</Description>
<Type>%Binary</Type>
</Property>

<Property name="Owner">
<Type>Sample.RemoteProxy</Type>
<Internal>1</Internal>
</Property>

<Property name="LastStatus">
<Type>%Status</Type>
<Internal>1</Internal>
<InitialExpression>$$$OK</InitialExpression>
</Property>

<Method name="RemoteConnection">
<CodeMode>expression</CodeMode>
<ReturnType>%Net.RemoteConnection</ReturnType>
<Implementation><![CDATA[..Owner.RemoteConnection
]]></Implementation>
</Method>

<Method name="%OnNew">
<FormalSpec>owner:Sample.RemoteProxy</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
    set ..Owner = owner
    
    return $$$OK
]]></Implementation>
</Method>

<Method name="%CreateInstance">
<Description>
open instance of a different class using given %ID</Description>
<FormalSpec>className:%String</FormalSpec>
<ReturnType>Sample.RemoteProxy.Object</ReturnType>
<Implementation><![CDATA[
    #dim pObject As %RegisteredObject = ""
    set ..LastStatus = ..RemoteConnection().CreateInstance(className, .pObject)
    set ..OpenedObject = ""
    if $$$ISOK(..LastStatus) {
        set ..OpenedObject = pObject
    }
    return $this
]]></Implementation>
</Method>

<Method name="%OpenObjectId">
<Description>
open instance of a different class using given %ID</Description>
<FormalSpec>className:%String,Id:%String</FormalSpec>
<ReturnType>Sample.RemoteProxy.Object</ReturnType>
<Implementation><![CDATA[
    #dim pObject As %RegisteredObject = ""
    set ..LastStatus = ..RemoteConnection().OpenObjectId(className, Id, .pObject)
    set ..OpenedObject = ""
    if $$$ISOK(..LastStatus) {
        set ..OpenedObject = pObject
    }
    return $this
]]></Implementation>
</Method>

<Method name="InvokeMethod">
<Internal>1</Internal>
<FormalSpec>MethodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    #dim returnValue = ""
    #dim i as %Integer
    #dim remoteConnection = ..RemoteConnection()
    do remoteConnection.ResetArguments()
    for i=1:1:$get(args) {
        set ..LastStatus = remoteConnection.AddArgument(args(i), 0)
    }
    set ..LastStatus = remoteConnection.InvokeInstanceMethod(..OpenedObject, MethodName, .returnValue, $quit)
    return returnValue
]]></Implementation>
</Method>

<Method name="%DispatchMethod">
<Description>
log arguments and then dispatch dynamically method to the proxy object</Description>
<FormalSpec>methodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    //do ..LogArgs(methodName, args...)
    return ..InvokeMethod(methodName, args...)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
/* /// log arguments and then dispatch dynamically class-method to the proxy object
ClassMethod %DispatchClassMethod(className As %String, methodName As %String, args...)
{
    //do ..LogArgs(className_"::"_methodName, args...)
    return $classmethod(className, methodName, args...) // FIXME - FRAMESTACK
}
*/
]]></Content>
</UDLText>

<Method name="%DispatchGetProperty">
<Description>
log arguments and then dispatch dynamically property access to the proxy object</Description>
<FormalSpec>Property:%String</FormalSpec>
<Implementation><![CDATA[
    //do ..LogArgs(Property, Value)

    #dim value = ""
    set ..LastStatus = ..RemoteConnection().GetProperty(..OpenedObject, Property, .value)
    return value
]]></Implementation>
</Method>

<Method name="%DispatchSetProperty">
<Description>
log arguments and then dispatch dynamically property access to the proxy object</Description>
<FormalSpec>Property,Value:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
    //do ..LogArgs(Property, Value)
    set ..LastStatus = ..RemoteConnection().SetProperty(..OpenedObject, Property, Value)
    return ..LastStatus
]]></Implementation>
</Method>
</Class>


<Class name="Sample.RemoteProxy">
<Description>
sample of a remote proxy using %Net.RemoteConnection</Description>
<Super>%RegisteredObject</Super>
<TimeChanged>64117,53069.639231</TimeChanged>
<TimeCreated>64112,53523.232695</TimeCreated>

<Property name="Config">
<Type>%Object</Type>
<Internal>1</Internal>
</Property>

<Property name="RemoteConnection">
<Type>%Net.RemoteConnection</Type>
<Internal>1</Internal>
</Property>

<Property name="LastStatus">
<Type>%Status</Type>
<InitialExpression>$$$OK</InitialExpression>
</Property>

<Method name="%OnNew">
<FormalSpec>initval</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
    #dim retValue As %Status = $$$OK
    
    set ..RemoteConnection = ##class(%Net.RemoteConnection).%New()
    
    return retValue
]]></Implementation>
</Method>

<Method name="%CreateInstance">
<Description>
create new instance of a given class name</Description>
<FormalSpec>className:%String</FormalSpec>
<ReturnType>Sample.RemoteProxy.Object</ReturnType>
<Implementation><![CDATA[
    #dim instanceProxy As Sample.RemoteProxy.Object = ##class(Sample.RemoteProxy.Object).%New($this)
    return instanceProxy.%CreateInstance(className)
]]></Implementation>
</Method>

<Method name="%OpenObjectId">
<FormalSpec>className:%String,Id:%String</FormalSpec>
<ReturnType>Sample.RemoteProxy.Object</ReturnType>
<Implementation><![CDATA[
    #dim instanceProxy As Sample.RemoteProxy.Object = ##class(Sample.RemoteProxy.Object).%New($this)
    return instanceProxy.%OpenObjectId(className, Id)
]]></Implementation>
</Method>

<Method name="Debug">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
    set w = ##class(Sample.RemoteProxy).%New().%Connect({"Namespace":"SAMPLES", "Username":"_SYSTEM", "Password":"SYS"})
    //do w."Sample.Person::PrintPersons"(1)
    write w."Cinema.Duration::LogicalToDisplay"(200)
    set p = w.%OpenObjectId("Sample.Person",1)
    write p.Name
    write p.SSN
    write p.Addition(1,2)
]]></Implementation>
</Method>

<Method name="%Connect">
<Description>
pass the configuration object { "IP": IP, "Namespace" : Namespace, ... }</Description>
<FormalSpec>Config:%Object</FormalSpec>
<ReturnType>Sample.RemoteProxy</ReturnType>
<Implementation><![CDATA[
    #dim sIP As %String = Config.IP
    #dim sNamespace As %String = Config.Namespace
    #dim sPort As %String = Config.Port
    #dim sUsername As %String = Config.Username
    #dim sPassword As %String = Config.Password
    #dim sClientIP As %String = Config.ClientIP
    #dim sClientPort As %String = Config.ClientPort
    
    if sIP = "" {
        set sIP = "127.0.0.1"
    }
    if sPort = "" {
        set sPort = ^%SYS("SSPort")
    }
    set ..LastStatus = ..RemoteConnection.Connect(sIP, sNamespace, sPort, 
                                                  sUsername, sPassword, 
                                                  sClientIP, sClientPort)
    
    return $this
]]></Implementation>
</Method>

<Method name="ApparentlyClassName">
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<FormalSpec>CompoundName:%String,*ClassName:%String,*MethodName:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
    #dim returnValue As %Boolean = 0
    
    if $length(CompoundName, "::") > 1 {
        set ClassName = $piece(CompoundName, "::", 1)
        set MethodName = $piece(CompoundName, "::", 2, *)

        return 1
    } elseif $length(CompoundName, "'") > 1 {
        set ClassName = $piece(CompoundName, "'", 1)
        set MethodName = $piece(CompoundName, "'", 2, *)

        return 1
    }

    return 0
]]></Implementation>
</Method>

<Method name="%DispatchMethod">
<Description>
log arguments and then dispatch dynamically method to the proxy object</Description>
<FormalSpec>methodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    //do ..LogArgs(methodName, args...)
    #dim className as %String = ""
    
    if ..ApparentlyClassName(methodName, .className, .methodName) {
        return ..InvokeClassMethod(className, methodName, args...)
    }
    return 1 ;$method(..OpenedObject, methodName, args...) // FIXME - no way to get here
]]></Implementation>
</Method>

<Method name="InvokeClassMethod">
<FormalSpec>ClassName:%String,MethodName:%String,args...</FormalSpec>
<Implementation><![CDATA[
    #dim returnValue = ""
    #dim i as %Integer
    do ..RemoteConnection.ResetArguments()
    for i=1:1:$get(args) {
        set ..LastStatus = ..RemoteConnection.AddArgument(args(i), 0)
    }
    set ..LastStatus = ..RemoteConnection.InvokeClassMethod(ClassName, MethodName, .returnValue, $quit)
    return returnValue
]]></Implementation>
</Method>
</Class>


<Class name="Sample.SimplePerson">
<Super>%Persistent,%Populate</Super>
<TimeChanged>64117,55447.475066</TimeChanged>
<TimeCreated>64117,55407.005491</TimeCreated>

<Property name="Name">
<Type>%String</Type>
</Property>

<Property name="Age">
<Type>%Integer</Type>
<Parameter name="MAXVAL" value="100"/>
<Parameter name="MINVAL" value="1"/>
</Property>

<Property name="Contacts">
<Type>%Integer</Type>
<Parameter name="MAXVAL" value="40"/>
<Parameter name="MINVAL" value="0"/>
</Property>

<Storage name="Default">
<Type>%Library.CacheStorage</Type>
<DataLocation>^Sample.SimplePersonD</DataLocation>
<DefaultData>SimplePersonDefaultData</DefaultData>
<IdLocation>^Sample.SimplePersonD</IdLocation>
<IndexLocation>^Sample.SimplePersonI</IndexLocation>
<StreamLocation>^Sample.SimplePersonS</StreamLocation>
<ExtentSize>1000</ExtentSize>
<Data name="SimplePersonDefaultData">
<Structure>listnode</Structure>
<Subscript/>
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
<Value name="3">
<Value>Age</Value>
</Value>
<Value name="4">
<Value>Contacts</Value>
</Value>
</Data>
<Property name="%%CLASSNAME">
<Selectivity>0.1000%</Selectivity>
<OutlierSelectivity>.992632:</OutlierSelectivity>
<AverageFieldSize>1</AverageFieldSize>
</Property>
<Property name="%%ID">
<Selectivity>1</Selectivity>
<AverageFieldSize>2.86</AverageFieldSize>
</Property>
<Property name="Age">
<Selectivity>1.2399%</Selectivity>
<AverageFieldSize>1.86</AverageFieldSize>
</Property>
<Property name="Contacts">
<Selectivity>2.6300%</Selectivity>
<AverageFieldSize>1.74</AverageFieldSize>
</Property>
<Property name="Name">
<Selectivity>0.1000%</Selectivity>
<AverageFieldSize>15.87</AverageFieldSize>
</Property>
<SQLMap name="IDKEY">
<BlockCount>-20</BlockCount>
</SQLMap>
</Storage>
</Class>
</Export>