You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by gr...@apache.org on 2010/11/29 15:29:24 UTC
svn commit: r1040122 [2/4] - in /incubator/etch/trunk: ./ binding-go/
binding-go/compiler/ binding-go/compiler/src/ binding-go/compiler/src/main/
binding-go/compiler/src/main/java/ binding-go/compiler/src/main/java/org/
binding-go/compiler/src/main/jav...
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/remote.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/remote.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/remote.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/remote.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,118 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+#set($i = $intf.name())
+#set($vfname = "ValueFactory$i")
+#set($intfname = "$i$suffix")
+#set($clname = "Remote$intfname")
+
+package $helper.getPackageName($intf)
+
+import "etch"
+
+#if($hasBaseClass)
+type $clname struct {
+ Remote$i
+
+#else
+type $clname struct {
+#end
+ vf etch.ValueFactory
+ Dsvc etch.DeliveryService
+}
+
+#if($hasBaseClass)
+func New$clname(dsvc etch.DeliveryService, vf etch.ValueFactory ) *$clname {
+ ret := &$clname{}
+ ret.Dsvc = dsvc
+ ret.vf = vf
+ return ret
+}
+#end
+
+func (remote *$clname) TransportControl(ctrl interface{}, value interface{}) {
+ remote.Dsvc.TransportControl(ctrl, value)
+}
+
+
+#foreach($n in $intf.iterator())
+#if($n.isMsgDir($mc))
+#if(!$n.isHidden())
+#if(!$methodList.contains($n.name().name()))
+#set ( $addMethodListStatus = $methodList.add($n.name().name()))
+#if($n.isOneway())
+#set ($methodName = "func (r *$clname) $helper.capitalize($n.name().toString()) (")
+#set( $sep = "" )
+#foreach( $p in $n.iterator() )
+#set ($methodName = $methodName + "$sep $p.name() $helper.getTypeName( $p.type() ) ")
+#set( $sep = ", " )
+#end
+#set ($methodName = $methodName + ") $helper.getTypeName( $n.type() )")
+$methodName {
+ msg := etch.NewMessage(r.vf.GetTypeByName("$n.fqname()"), r.vf, 1)
+#foreach( $p in $n.iterator() )
+#if ($helper.getTypeName( $p.type() ).startsWith("*"))
+ if $p.name() != nil {
+#end
+ msg.Put(r.vf.(*$vfname).$p.vname( $helper ), $p.name())
+#if ($helper.getTypeName( $p.type() ).startsWith("*"))
+ }
+#end
+#end
+ r.Dsvc.TransportMessage(nil, msg)
+}
+#else
+#set ($methodName = "func (r *$clname) $helper.capitalize($n.name().toString()) (")
+#set( $sep = "" )
+#foreach( $p in $n.iterator() )
+#set ($methodName = $methodName + "$sep $p.name() $helper.getTypeName( $p.type() )")
+#set( $sep = ", " )
+#end
+#set ($methodName = $methodName + ") $helper.getTypeName( $n.type() )")
+$methodName {
+ msg := etch.NewMessage(r.vf.GetTypeByName("$n.fqname()"), r.vf, 1)
+#foreach( $p in $n.iterator() )
+#if ($helper.getTypeName( $p.type() ).startsWith("*"))
+ if $p.name() != nil {
+#end
+ msg.Put(r.vf.(*$vfname).$p.vname( $helper ), $p.name())
+#if ($helper.getTypeName( $p.type() ).startsWith("*"))
+ }
+#end
+#end
+
+#if($n.hasReturn())
+ retVal := r.Dsvc.EndCall(r.Dsvc.BeginCall(msg), r.vf.GetTypeByName("$n.getResultMessage().fqname()"))
+#if ($helper.getTypeName( $n.type() ).startsWith("int"))
+ return etch.To$helper.getTypeName( $n.type() )(retVal)
+#else
+ return retVal.($helper.getTypeName( $n.type() ))
+#end
+#else
+ r.Dsvc.EndCall(r.Dsvc.BeginCall(msg), r.vf.GetTypeByName("$n.getResultMessage().fqname()"))
+#end
+}
+#end
+#end
+#end
+#end
+#end
+
+
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/stub.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/stub.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/stub.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/stub.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,112 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+#set($i = $intf.name())
+
+#set($intfname = "$i$suffix")
+#set($baseclname = "Base$intfname")
+#set($implname = "Impl$intfname")
+
+package $helper.getPackageName($intf)
+
+#set ($hasMethod = false)
+#foreach($n in $intf.iterator())
+#if($n.isMsgDir($mc))
+#if(!$n.isHidden())
+#set ($hasMethod = true)
+#end
+#end
+#end
+
+#if ($hasMethod == true || $hasBaseClass)
+import "etch"
+#end
+
+#if ($hasBaseClass)
+func SetStubHelpers_Stub$i$suffix (dvf etch.ValueFactory) {
+ SetStubHelpers_Stub$i()
+#set( $T = "$i$suffix" )
+#else
+func SetStubHelpers_Stub$i$suffix () {
+#set( $T = "T" )
+#end
+#foreach( $mthd in $intf.iterator() )
+#if ($mthd.isMsgDir($mc))
+#if (!$mthd.isHidden())
+ if dvf.GetTypeByName("$mthd.fqname()").StubHelper == nil {
+ dvf.GetTypeByName("$mthd.fqname()").StubHelper = new($mthd.vname( $helper )Helper)
+ }
+#end
+#end
+#end
+}
+
+#foreach( $mthd in $intf.iterator() )
+#if ($mthd.isMsgDir($mc))
+#if (!$mthd.isHidden())
+
+type $mthd.vname( $helper )Helper struct{}
+
+func (dh *$mthd.vname( $helper )Helper) run(svc etch.DeliveryService, impl interface{}, sender interface{}, msg *etch.Message) {
+#if (!$mthd.isOneway())
+ rmsg := msg.Reply()
+#end
+ di := impl.(*$implname)
+#foreach ($param in $mthd.iterator())
+ $param.name() := msg.Vf.(*ValueFactory$i).$param.vname( $helper ) ;
+#end
+
+#foreach ($param in $mthd.iterator())
+ val_$param.name() := msg.Fields[$param.name()]
+#if ($helper.getTypeName( $param.type() ).startsWith("*"))
+ var $param.name()_param $helper.getTypeName( $param.type() ) = nil
+ if val_$param.name() != nil {
+ $param.name()_param = val_$param.name().($helper.getTypeName( $param.type() ))
+ }
+#elseif ($helper.getTypeName( $param.type() ).startsWith("int"))
+ var $param.name()_param $helper.getTypeName( $param.type() ) = etch.To$helper.getTypeName( $param.type() )(val_$param.name())
+#else
+ var $param.name()_param $helper.getTypeName( $param.type() ) = val_$param.name().($helper.getTypeName( $param.type() ))
+#end
+#end
+
+#set ($returnPrefix = "")
+#if ($mthd.hasReturn())
+#set ($returnPrefix = "ret :=")
+#end
+#set ($callName = "di.$mthd.name()(")
+#set( $sep = "" )
+#foreach ($param in $mthd.iterator())
+#set ($callName = $callName + "${sep}$param.name()_param")
+#set( $sep = ", " )
+#end
+#set ($callName = $callName + ")")
+ $returnPrefix $callName
+#if ($mthd.hasReturn())
+ rmsg.Put(msg.Vf.GetDefaultResponseField(), ret)
+#end
+#if (!$mthd.isOneway())
+ svc.TransportMessage(sender, rmsg)
+#end
+}
+
+#end
+#end
+#end
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/vf.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/vf.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/vf.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/vf.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,202 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+
+package $helper.getPackageName($intf)
+
+import "etch"
+import "reflect"
+
+#set( $vf = "ValueFactory$intf.name()" )
+type ${vf} struct
+{
+ etch.ValueFactory
+## ----------------------------- fields -----------------------------
+#set( $x = $params.clear() )
+## standard params from DefaultValueFactory
+#set( $x = $params.add( "msg" ) )
+#set( $x = $params.add( "result" ) )
+
+#foreach( $n in $intf.iterator() )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
+#foreach( $param in $n.iterator() )
+#if (!$params.contains($param.name().name()))
+#set( $x = $params.add($param.name().name()) )
+ $param.vname( $helper ) *etch.Field
+#end
+#end
+#end
+#end
+}
+
+
+type dummyVal struct{}
+
+func (dv *dummyVal) Validate(value interface{}) bool {
+ return true
+}
+func (dv *dummyVal) ValidateValue(value interface{}) interface{} {
+ return value
+}
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+func NewArray${n.vname( $helper )} (length int32) interface{} {
+ return make([]*$helper.capitalize($n.name().toString()), length)
+}
+#end
+#end
+
+func New${vf}() *$vf {
+
+#set ($initList = " ")
+#set ($sep = " ")
+#set( $x = $params.clear() )
+## standard params from DefaultValueFactory
+#set( $x = $params.add( "msg" ) )
+#set( $x = $params.add( "result" ) )
+#foreach( $n in $intf.iterator() )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
+#foreach( $param in $n.iterator() )
+#if (!$params.contains($param.name().name()))
+#set( $x = $params.add($param.name().name()) )
+#set ($initList = $initList + $sep + "nil")
+#set ($sep = ",")
+#end
+#end
+#end
+#end
+
+ ret := &${vf}{etch.NewDefaultValueFactory(), $initList}
+#foreach ( $n in $intf.iterator() )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExtern() || $n.isExcept() || $n.isMessage())
+ ${n.vname( $helper )} := etch.NewTypeByName("$n.fqname()")
+ ret.AddType(${n.vname( $helper )})
+#end
+#end
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+ ${n.vname( $helper )}.NewArray = NewArray${n.vname( $helper )}
+#end
+#end
+
+#foreach ( $n in $intf.iterator() )
+#set( $x = $params.clear() )
+#set( $x = $params.add( "msg" ) )
+#set( $x = $params.add( "result" ) )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
+#foreach( $param in $n.iterator() )
+#if (!$params.contains($param.name().name()))
+#set( $x = $params.add($param.name().name()) )
+ ret.$param.vname( $helper ) = etch.NewField("$param.name().name()")
+ ret.AddField(ret.$param.vname( $helper ))
+#end
+#end
+#end
+#end
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isMessage())
+#if (!$n.isHidden())
+#if ($n.isQueuedAsyncReceiver())
+ ${n.vname( $helper )}.AsyncMode = etch.QUEUED;
+#elseif ($n.isFreeAsyncReceiver())
+ ${n.vname( $helper )}.AsyncMode = etch.FREE ;
+#else
+ ${n.vname( $helper )}.AsyncMode = etch.MODE_NONE ;
+#end
+#end
+#end
+#end
+
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isMessage())
+#if (!$n.isHidden())
+#if (!$n.isOneway())
+#set( $r = $n.getResultMessage() )
+ ${r.vname( $helper )}.ResponseField = ret.GetDefaultResponseField() ;
+ ${n.vname( $helper )}.RType = $r.vname( $helper )
+#end
+#end
+#end
+ // params for $n.name()
+#if ($n.isStruct() || $n.isExcept())
+#foreach( $param in $n.getAllParameters() )
+ ${n.vname( $helper )}.PutValidator(ret.$param.vname( $helper), new(dummyVal))
+#end
+#else
+#foreach( $param in $n.iterator() )
+#if ($param.vname( $helper).toString().startsWith("_mf_result") != true)
+ ${n.vname( $helper )}.PutValidator(ret.$param.vname( $helper), new(dummyVal))
+#end
+#end
+#end
+#if ($n.isMessage())
+ ${n.vname( $helper )}.PutValidator(ret.GetDefaultMessageIdField(), new(dummyVal))
+#if ($n.isHidden())
+ ${n.vname( $helper )}.PutValidator(ret.GetDefaultInReplyToField(), new(dummyVal))
+ ${n.vname( $helper )}.PutValidator(ret.GetDefaultResponseField(), new(dummyVal))
+#end
+#end
+#end
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+#set( $tname = $n.efqname( $helper ) )
+ (*ret.GetClass2type())[reflect.Typeof(new($helper.capitalize($n.name().toString())))] = ${n.vname( $helper )}
+ ${n.vname( $helper )}.Helper = new(${n.vname( $helper )}ImportExportHelper)
+#end
+#end
+
+ return ret
+}
+
+
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+#set( $tname = $n.efqname( $helper ) )
+type ${n.vname( $helper )}ImportExportHelper struct {
+}
+
+func (h *${n.vname( $helper )}ImportExportHelper) ExportValue(ty *etch.Type, vf etch.ValueFactory, value interface{}) *etch.StructValue {
+ sv := etch.NewStructValue( vf.GetTypeByName("$n.fqname()"), vf, 0 )
+ v := value.(*$helper.capitalize(${n.name().toString()}))
+#foreach( $p in $n.getAllParameters() )
+ sv.Put( vf.GetFieldByName("$p.name().toString()"), v.$helper.capitalize($p.name().toString()) )
+#end
+ return sv;
+}
+
+func (h *${n.vname( $helper )}ImportExportHelper) ImportValue(str *etch.StructValue) interface{} {
+ v := new($helper.capitalize(${n.name().toString()}))
+#foreach ($p in $n.getAllParameters())
+#if ($helper.getTypeName( $p.type() ).startsWith("int"))
+ v.$helper.capitalize($p.name().toString()) = etch.To$helper.getTypeName( $p.type() )(str.Fields[str.Vf.GetFieldByName("$p.name().toString()")])
+#else
+ v.$helper.capitalize($p.name().toString()) = str.Fields[str.Vf.GetFieldByName("$p.name().toString()")].($helper.getTypeName( $p.type() ))
+#end
+#end
+ return v
+}
+
+#end
+#end
Added: incubator/etch/trunk/binding-go/runtime/Makefile
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/Makefile?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/Makefile (added)
+++ incubator/etch/trunk/binding-go/runtime/Makefile Mon Nov 29 14:29:21 2010
@@ -0,0 +1,29 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+.PHONY: test etch
+
+all: etch test
+ ./src/test/go/test
+
+test:
+ @$(MAKE) -C src/test/go -f Makefile all
+
+etch:
+ @$(MAKE) -C src/main/go/etch -f Makefile all
+
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedData.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedData.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedData.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedData.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+import "reflect"
+
+const (
+ VERSION int8 = 3
+)
+
+const (
+ NULL int8 = -128
+ NONE int8 = -127
+ BOOLEAN_FALSE int8 = -126
+ BOOLEAN_TRUE int8 = -125
+ BYTE int8 = -124
+ SHORT int8 = -123
+ INT int8 = -122
+ LONG int8 = -121
+ FLOAT int8 = -120
+ DOUBLE int8 = -119
+ BYTES int8 = -117
+ ARRAY int8 = -111
+ EMPTY_STRING int8 = -110
+ STRING int8 = -109
+ STRUCT int8 = -108
+ CUSTOM int8 = -107
+ ANY int8 = -106
+ MIN_TINY_INT int8 = -64
+ MAX_TINY_INT int8 = 127
+)
+
+type ArrayValue struct {
+ TypeCode int8
+ CustomTy *Type
+ Dim int
+ ArrayVal reflect.ArrayOrSliceValue
+}
+
+func NewArrayValueWith(array interface{}, ty int8, cty *Type) *ArrayValue{
+ ret := &ArrayValue{ty, cty,1,reflect.NewValue(array).(reflect.ArrayOrSliceValue)}
+ return ret
+}
+
+
+func NewArrayValue(array interface{}, vf ValueFactory) *ArrayValue{
+ //only support 1-dimensional, non-empty arrays up to now...
+ //other arrays are likely to crash
+ ret := &ArrayValue{0,nil,1,reflect.NewValue(array).(reflect.ArrayOrSliceValue)}
+ Log("NewArrayValue: " + fmt.Sprint(ret.Get(0)) + "\n")
+ ret.TypeCode = getTypeCode(ret.Get(0))
+ Log("NewArrayValue: getTypeCode said " + fmt.Sprint(ret.TypeCode) + "\n")
+ if ret.TypeCode == CUSTOM {
+ ret.CustomTy = vf.GetCustomStructType(reflect.Typeof(ret.Get(0)))
+ }
+ return ret
+}
+
+func ToArrayValue(o interface{}, vf ValueFactory) *ArrayValue {
+ av := NewArrayValue(o, vf)
+ return av
+}
+
+func FromArrayValue(av *ArrayValue) interface{} {
+ return av.ArrayVal.Interface()
+}
+
+func (ar *ArrayValue) Size() int {
+ return ar.ArrayVal.Len()
+}
+
+func (ar *ArrayValue) Get(i int) interface{} {
+ return ar.ArrayVal.Elem(i).Interface()
+}
+
+func (ar *ArrayValue) Set(i int, value interface{}) {
+ ar.ArrayVal.Elem(i).SetValue(reflect.NewValue(value))
+}
+
+
+func getTypeCode(val interface{}) int8 {
+ if val == nil {
+ return NULL
+ }
+
+ switch a := val.(type) {
+ case []byte:
+ return BYTES
+ }
+
+ if reflect.Typeof(val).Kind() == reflect.Slice {
+ return ARRAY
+ }
+
+ switch a := val.(type) {
+ case int8:
+ return BYTE
+ case int16:
+ return SHORT
+ case int32:
+ return INT
+ case int64:
+ return LONG
+ case float32:
+ return FLOAT
+ case float64:
+ return DOUBLE
+ case string:
+ return STRING
+ default:
+ return CUSTOM
+ }
+ return NONE
+
+}
+
+
+func checkValue(val interface{}) int8 {
+ if val == nil {
+ return NULL
+ }
+ if val == NONE {
+ return NONE
+ }
+
+
+ switch a := val.(type) {
+ case []byte:
+ return BYTES
+ }
+
+ if reflect.Typeof(val).Kind() == reflect.Slice {
+ return ARRAY
+ }
+
+ switch a := val.(type) {
+ case int8:
+ return checkByte(val.(int8))
+ case int16:
+ return checkShort(val.(int16))
+ case int32:
+ return checkInteger(val.(int32))
+ case int64:
+ return checkLong(val.(int64))
+ case float32:
+ return FLOAT
+ case float64:
+ return DOUBLE
+ case string:
+ return STRING
+ default:
+ return CUSTOM
+ }
+ return NONE
+
+}
+
+
+func checkLong(val int64) int8 {
+ if val <= 4294967295 &&
+ val >= -4294967296 {
+ return checkInteger(int32(val))
+ }
+ return LONG
+}
+
+func checkInteger(val int32) int8 {
+ if val <= 65535 &&
+ val >= -65536 {
+ return checkShort(int16(val))
+ }
+ return INT
+}
+
+
+func checkShort(val int16) int8 {
+ if val <= 127 &&
+ val >= -128 {
+ return checkByte(int8(val))
+ }
+ return SHORT
+}
+
+func checkByte(val int8) int8 {
+ if val <= MAX_TINY_INT &&
+ val >= MIN_TINY_INT {
+ return val
+ }
+ return BYTE
+}
+
+func toBytes(val string) []byte {
+ return []byte(val)
+}
+
+func toByte(val interface{}) int8 {
+ switch val.(type) {
+ case int:
+ return int8(val.(int))
+ case int8:
+ return val.(int8)
+ case int16:
+ return int8(val.(int16))
+ case int32:
+ return int8(val.(int32))
+ case int64:
+ return int8(val.(int64))
+ }
+ return 0
+}
+
+func toShort(val interface{}) int16 {
+ switch val.(type) {
+ case int:
+ return int16(val.(int))
+ case int8:
+ return int16(val.(int8))
+ case int16:
+ return int16(val.(int16))
+ case int32:
+ return int16(val.(int32))
+ case int64:
+ return int16(val.(int64))
+ }
+ return 0
+}
+
+func toInteger(val interface{}) int32 {
+ switch val.(type) {
+ case int:
+ return int32(val.(int))
+ case int8:
+ return int32(val.(int8))
+ case int16:
+ return int32(val.(int16))
+ case int32:
+ return int32(val.(int32))
+ case int64:
+ return int32(val.(int64))
+ }
+ return 0
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataInput.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataInput.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataInput.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataInput.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type BinaryTaggedDataInput struct {
+ buf *FlexBuffer
+ vf ValueFactory
+}
+
+
+func NewBinaryTaggedDataInput(vf ValueFactory) *BinaryTaggedDataInput {
+ return &BinaryTaggedDataInput{nil, vf}
+}
+
+func (btdi *BinaryTaggedDataInput) ReadMessage(buf *FlexBuffer) *Message {
+ btdi.buf = buf
+ theMsg := btdi.startMessage()
+ if theMsg == nil { //unknown function
+ return nil
+ }
+ btdi.readKeysAndValues(theMsg)
+
+ btdi.endMessage(theMsg)
+
+ Log("BinaryTaggedDataInput Readmessage: got " + fmt.Sprint(theMsg) + " Fields: ")
+ for k, v := range theMsg.Fields{
+ Log(" " + fmt.Sprint(k) + " = " + fmt.Sprint(v))
+ }
+ Log("\n")
+ return theMsg
+}
+
+func (btdi *BinaryTaggedDataInput) startMessage() *Message {
+ version := btdi.buf.ReadByte()
+ if version != VERSION {
+ return nil
+ }
+
+ ty := btdi.readType()
+ if ty == nil {
+ Log("BinaryTaggedDataInput: startMessage discarding msg because of unknown type\n")
+ //type of msg not known
+ return nil
+ }
+ l := btdi.readLength()
+ return NewMessage(ty, btdi.vf, int(l))
+}
+
+func (btdi *BinaryTaggedDataInput) readType() *Type {
+ obj := btdi.readValue(nil, true)
+ switch obj.(type) {
+ case int32:
+ id := toInteger(obj)
+ t := btdi.vf.GetTypeById(id)
+ return t
+ }
+ return nil
+}
+
+func (btdi *BinaryTaggedDataInput) readLength() int32 {
+ return btdi.readIntegerValue()
+}
+
+func (btdi *BinaryTaggedDataInput) readIntegerValue() int32 {
+ val := btdi.readValue(nil, false)
+ Log("BinaryTaggedDataInput readIntegerValue " + fmt.Sprint(val) + "\n")
+ return toInteger(val)
+}
+
+
+func (btdi *BinaryTaggedDataInput) readValue(val Validator, noneOk bool) interface{} {
+ byTy := btdi.buf.ReadByte()
+
+ Log("BinaryTaggedDataInput readValue: byty = " + fmt.Sprint(byTy) + "\n")
+
+ switch byTy {
+ case NULL:
+ case NONE:
+ if noneOk {
+ return NONE
+ } else {
+ return nil
+ }
+ case BYTE:
+ return btdi.validateValue(val, btdi.buf.ReadByte())
+ case SHORT:
+ return btdi.validateValue(val, btdi.buf.ReadShort())
+ case INT:
+ return btdi.validateValue(val, btdi.buf.ReadInt())
+ case LONG:
+ return btdi.validateValue(val, btdi.buf.ReadLong())
+ case FLOAT:
+ return btdi.validateValue(val, btdi.buf.ReadFloat())
+ case DOUBLE:
+ return btdi.validateValue(val, btdi.buf.ReadDouble())
+ case BYTES:
+ return btdi.validateValue(val, btdi.readBytes())
+ case ARRAY:
+ av := btdi.readArray()
+ if av == nil {
+ return nil
+ }
+ return btdi.validateValue(val, FromArrayValue(av))
+ case EMPTY_STRING:
+ return btdi.validateValue(val, "")
+ case STRING:
+ return btdi.validateValue(val, string(btdi.readBytes()))
+ case CUSTOM:
+ sv := btdi.readStruct()
+ return btdi.validateValue(val, btdi.vf.ImportCustomValue(sv))
+
+ }
+ if byTy >= MIN_TINY_INT && byTy <= MAX_TINY_INT {
+ return int8(byTy)
+ }
+ return nil
+}
+
+func (btdi *BinaryTaggedDataInput) validateValue(vldtr Validator, val interface{}) interface{} {
+ //TODO implement me
+ return val
+}
+
+func (btdi *BinaryTaggedDataInput) startStruct() *StructValue {
+ ty := btdi.readType()
+ if ty == nil {
+ return nil // type not known, what shall we do ?
+ }
+ l := btdi.readLength()
+ return NewStructValue(ty, btdi.vf, int(l))
+}
+
+func (btdi *BinaryTaggedDataInput) endStruct(sv *StructValue) {
+ // nothing to do, readKeysAndValues swallowed the NONE.
+}
+
+func (btdi *BinaryTaggedDataInput) readField(ty *Type) *Field {
+ //this "true" swallows the NONE at the end of a struct
+ obj := btdi.readValue(nil, true)
+ Log("BinaryTaggedDataInput: readField : next Field ID is : " + fmt.Sprint(obj) + "\n")
+ switch obj.(type) {
+ case int32:
+ f := ty.Fields[toInteger(obj)]
+ return f
+ }
+ return nil
+}
+
+func (btdi *BinaryTaggedDataInput) readArray() *ArrayValue {
+ av := btdi.startArray()
+ if av == nil {
+ return nil
+ }
+ btdi.readValues(av)
+ btdi.endArray(av)
+ return av
+}
+
+
+func (btdi *BinaryTaggedDataInput) startArray() *ArrayValue {
+ Log("BinaryTaggedDataInput: startArray\n")
+ typeCode := btdi.buf.ReadByte()
+
+ Log("BinaryTaggedDataInput: startArray: typeCode = " + fmt.Sprint(typeCode) + "\n")
+ var cTy *Type = nil
+ if(typeCode == CUSTOM) {
+ cTy = btdi.readType()
+ }
+
+
+ Log("BinaryTaggedDataInput: startArray: cTy = " + fmt.Sprint(cTy) + "\n")
+
+ Log("BinaryTaggedDataInput: startArray buf = " + fmt.Sprint(btdi.buf) + "\n")
+ Log("BinaryTaggedDataInput: startArray buf = " + fmt.Sprint(btdi.buf.Index) + "\n")
+
+ dim := btdi.readIntegerValue()
+
+ Log("BinaryTaggedDataInput: startArray: dim = " + fmt.Sprint(dim) + "\n")
+ if dim != 1 {
+ //multidimension not yet supported
+ return nil
+ }
+ len := btdi.readIntegerValue()
+ Log("BinaryTaggedDataInput: startArray: len = " + fmt.Sprint(len) + "\n")
+ Log("startArray: NewArrayForType " + fmt.Sprint(typeCode) + " " + fmt.Sprint(cTy) + "\n")
+ array := btdi.vf.NewArrayForType(typeCode, cTy, len)
+
+ Log("BinaryTaggedDataInput: startArray: array = " + fmt.Sprint(array) + "\n")
+ Log("startArray: NewArrayForType " + fmt.Sprint(array) + "\n")
+ return NewArrayValueWith(array, typeCode, cTy)
+}
+
+func (btdi *BinaryTaggedDataInput) endArray(av *ArrayValue) {
+ // nothing to do, readValues swallowed the NONE.
+}
+
+func (btdi *BinaryTaggedDataInput) readValues(av *ArrayValue) {
+ i := 0
+ for true {
+ val := btdi.readValue(nil, true)
+ if val == NONE {
+ break
+ }
+ av.Set(i, val)
+ i++
+ }
+}
+
+
+
+func (btdi *BinaryTaggedDataInput) readStruct() *StructValue {
+ sv := btdi.startStruct()
+ if sv == nil {
+ return nil
+ }
+ btdi.readKeysAndValues(sv)
+ btdi.endStruct(sv)
+ return sv
+}
+
+func (btdi *BinaryTaggedDataInput) readBytes() []uint8 {
+ l := btdi.readLength()
+ bys := make([]uint8, l)
+ btdi.buf.ReadBytes(&bys)
+ return bys
+}
+
+func (btdi *BinaryTaggedDataInput) readKeysAndValues(sv StructValueIntf) {
+ ty := sv.GetType()
+
+ if ty == nil {
+ Log("readKeys TYPE NOT FOUND!\n")
+ return
+ }
+
+ for true {
+ key := btdi.readField(ty)
+ Log("BinaryTaggedDataInput: readKeysAndValues: read field" + fmt.Sprint(key) + "\n")
+ if key == nil {
+ break
+ }
+ vldtr := ty.Validators[key.Id]
+ if vldtr != nil {
+ Log("BinaryTaggedDataInput: readKeysAndValues: I have a validator for" + fmt.Sprint(key) + "\n")
+ val := btdi.readValue(vldtr, false)
+ Log("BinaryTaggedDataInput: readKeysAndValues: Value of " + fmt.Sprint(key) + " is " + fmt.Sprint(val) + "\n")
+ sv.Put(key, val)
+ } else {
+ Log("BinaryTaggedDataInput: readKeysAndValues: I have NO validator for" + fmt.Sprint(key) + "\n")
+ btdi.readValue(nil, false)
+ }
+ }
+}
+
+func (btdi *BinaryTaggedDataInput) endMessage(mes *Message) {
+ // nothing to do, readKeysAndValues swallowed the NONE.
+
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataOutput.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataOutput.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataOutput.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataOutput.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type BinaryTaggedDataOutput struct {
+ buf *FlexBuffer
+ vf ValueFactory
+}
+
+func NewBinaryTaggedDataOutput(vf ValueFactory) *BinaryTaggedDataOutput {
+ return &BinaryTaggedDataOutput{nil, vf}
+}
+
+
+func (btdo *BinaryTaggedDataOutput) WriteMessage(msg *Message, buf *FlexBuffer) {
+ Log("BinaryTaggedDataOutput: writemessage for " + fmt.Sprint(msg) + "\n")
+ btdo.buf = buf
+ btdo.startMessage(msg)
+ btdo.writeKeysAndValues(msg)
+ btdo.endMessage(msg)
+ Log("BinaryTaggedDataOutput: writemessage for " + fmt.Sprint(msg) + "done\n")
+}
+
+func (btdo *BinaryTaggedDataOutput) startMessage(msg *Message) {
+ btdo.buf.PutByte(VERSION)
+ btdo.startStruct(msg)
+}
+
+func (btdo *BinaryTaggedDataOutput) endMessage(msg *Message) {
+ Log("BinaryTaggedDataOutput: endmessage for " + fmt.Sprint(msg) + "\n")
+ btdo.endStruct(msg)
+}
+
+func (btdo *BinaryTaggedDataOutput) writeArray(av *ArrayValue) {
+ btdo.startArray(av)
+ btdo.writeValues(av)
+ btdo.endArray(av)
+}
+
+func (btdo *BinaryTaggedDataOutput) startArray(av *ArrayValue) {
+
+ Log("BinaryTaggedDataOutput startArray 1: " + fmt.Sprint(btdo.buf) + "\n")
+ Log("BinaryTaggedDataOutput startArray typeCode = " + fmt.Sprint(av.TypeCode) + "\n")
+ btdo.buf.Put(toByte(av.TypeCode))
+ Log("BinaryTaggedDataOutput startArray 2: " + fmt.Sprint(btdo.buf) + "\n")
+ if av.TypeCode == CUSTOM {
+ btdo.writeType(av.CustomTy)
+ }
+ Log("BinaryTaggedDataOutput startArray 3: " + fmt.Sprint(btdo.buf) + "\n")
+ btdo.writeValue(nil, int32(av.Dim))
+ Log("BinaryTaggedDataOutput startArray 4: " + fmt.Sprint(btdo.buf) + "\n")
+ btdo.writeValue(nil, int32(av.Size()))
+ Log("BinaryTaggedDataOutput startArray 5: " + fmt.Sprint(btdo.buf) + "\n")
+}
+
+
+func (btdo *BinaryTaggedDataOutput) writeValues(av *ArrayValue) {
+ for i:=0; i < av.Size(); i++ {
+ btdo.writeValue(nil, av.Get(i))
+ }
+}
+
+func (btdo *BinaryTaggedDataOutput) endArray(av *ArrayValue) {
+ btdo.writeValue(nil, NONE)
+}
+
+
+func (btdo *BinaryTaggedDataOutput) writeStruct(sv StructValueIntf) {
+ btdo.startStruct(sv)
+ btdo.writeKeysAndValues(sv)
+ btdo.endStruct(sv)
+}
+
+func (btdo *BinaryTaggedDataOutput) startStruct(msg StructValueIntf) {
+ btdo.writeType(msg.GetType())
+ btdo.writeIntValue(int32(msg.Size()))
+}
+
+
+func (btdo *BinaryTaggedDataOutput) writeType(ty *Type) {
+ btdo.writeIntValue(ty.Id)
+}
+
+func (btdo *BinaryTaggedDataOutput) writeIntValue(i int32) {
+ btdo.writeValue(nil, i)
+}
+
+func (btdo *BinaryTaggedDataOutput) writeValue(val Validator, value interface{}) {
+ if value == nil {
+ Log("BinaryTaggedDataOutput writeValue: skipping nil\n")
+ return
+ }
+
+ if val != nil && !val.Validate(value) {
+ Log("BinaryTaggedDataOutput writeValue: skipping, because validation failed\n")
+ return
+ }
+
+ ty := checkValue(value)
+ btdo.buf.PutByte(ty)
+ switch ty {
+ case BYTE:
+ btdo.buf.Put(toByte(value))
+ case SHORT:
+ btdo.buf.Put(toShort(value))
+ case INT:
+ btdo.buf.Put(toInteger(value))
+ case LONG:
+ btdo.buf.Put(value)
+ case FLOAT:
+ btdo.buf.Put(value)
+ case DOUBLE:
+ btdo.buf.Put(value)
+ case BYTES:
+ btdo.writeIntValue(int32(len(value.([]byte))))
+ btdo.buf.PutBytes(value.([]byte))
+ case STRING:
+ bytes := toBytes(value.(string))
+ btdo.writeIntValue(int32(len(bytes)))
+ btdo.buf.PutBytes(bytes)
+ case ARRAY:
+ btdo.writeArray(ToArrayValue(value.(interface{}), btdo.vf))
+ case CUSTOM:
+ sv := btdo.vf.ExportCustomValue(value)
+ if sv == nil {
+ return
+ }
+ btdo.writeStruct(sv)
+ default:
+ }
+}
+
+
+func (btdo *BinaryTaggedDataOutput) endStruct(msg StructValueIntf) {
+ btdo.writeValue(nil, NONE)
+}
+
+func (btdo *BinaryTaggedDataOutput) writeField(f *Field) {
+ btdo.writeIntValue(f.Id)
+}
+
+func (btdo *BinaryTaggedDataOutput) writeKeysAndValues(sv StructValueIntf) {
+ Log("BinaryTaggedDataOutput: writeKeysAndValues for " + fmt.Sprint(sv) + "\n")
+ for f, val := range *sv.GetFields() {
+ if val != nil {
+ Log("BinaryTaggedDataOutput: writeKeysAndValues for " + fmt.Sprint(f) + " = " + fmt.Sprint(val) +"\n")
+ btdo.writeField(f)
+ btdo.writeValue(nil, val)
+ }
+ }
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ComboValidator.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ComboValidator.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ComboValidator.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ComboValidator.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type ComboValidator struct {
+ a Validator
+ b Validator
+}
+
+func validate(value interface{}) bool {
+ return a.validate(value) || b.validate(value)
+}
+
+func validateValue(value interface{}) interface{} {
+ aret = a.validate(value)
+ if aret == nil {
+ return b.validate(value)
+ }
+ return aret
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultDeliveryService.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultDeliveryService.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultDeliveryService.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultDeliveryService.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type DefaultDeliveryService struct {
+ transport MailboxManager
+ session SessionMessage
+ status chan interface{}
+}
+
+func NewDefaultDeliveryService(transport MailboxManager, session SessionMessage) DeliveryService {
+ return &DefaultDeliveryService{transport, session, make(chan interface{}, 1)}
+}
+
+func (dds *DefaultDeliveryService) BeginCall(msg *Message) Mailbox {
+ return dds.transport.TransportCall(nil, msg)
+}
+
+func (dds *DefaultDeliveryService) handleError() {
+ x := recover()
+ Log("DefaultDeliveryService: Panic below: " + fmt.Sprint(x) + "\n")
+}
+
+func (dds *DefaultDeliveryService) EndCall(mb Mailbox, ty *Type) interface{} {
+ elem := mb.Read()
+ if elem != nil {
+ msg := elem.Msg
+ val := msg.GetFields()
+ return (*val)[ty.ResponseField]
+ }
+ //e.g. timeout
+ return nil
+}
+
+func (dds *DefaultDeliveryService) SessionMessage(sender interface{}, msg *Message) bool {
+ return dds.session.SessionMessage(sender, msg)
+}
+
+func (dds *DefaultDeliveryService) TransportMessage(recipient interface{}, msg *Message) {
+ dds.transport.TransportMessage(recipient, msg)
+}
+
+func (dds *DefaultDeliveryService) SessionQuery(obj interface{}) interface{} {
+ return dds.session.SessionQuery(obj)
+}
+
+func (dds *DefaultDeliveryService) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return dds.session.SessionControl(ctrl, value)
+}
+
+func (dds *DefaultDeliveryService) GetSession() Session {
+ return dds.session
+}
+
+func (dds *DefaultDeliveryService) SetSession(sess Session) {
+ dds.session = sess.(SessionMessage)
+}
+
+func (dds *DefaultDeliveryService) SessionNotify(obj interface{}) {
+
+ defer EtchRecoverAll()
+ if obj.(int) == UP {
+ dds.status <- UP
+ } else if obj.(int) == DOWN {
+ dds.status <- DOWN
+ }
+ dds.session.SessionNotify(obj)
+}
+
+func (dds *DefaultDeliveryService) TransportQuery(obj interface{}) interface{} {
+ return dds.transport.TransportQuery(obj)
+}
+
+func (dds *DefaultDeliveryService) waitUntil(value int, timeout int) {
+ WaitOnChannel(value, timeout, dds.status)
+}
+
+func (dds *DefaultDeliveryService) TransportControl(ctrl interface{}, value interface{}) {
+ Log("DefaultDeliveryService: transportControl: " + fmt.Sprint(ctrl) + "\n")
+ defer EtchRecoverAll()
+ if ctrl.(int) == START_AND_WAIT_UP {
+ Log("DefaultDeliveryService: transportControl: START_AND_WAIT_UP\n")
+ dds.transport.TransportControl(START, nil)
+ Log("DefaultDeliveryService: WAITING FOR UP\n")
+ dds.waitUntil(UP, value.(int))
+ Log("DefaultDeliveryService: UP WAITING DONE\n")
+ } else if ctrl.(int) == STOP_AND_WAIT_DOWN {
+ Log("DefaultDeliveryService: transportControl: START_AND_WAIT_DOWN\n")
+ dds.transport.TransportControl(STOP, nil)
+ Log("DefaultDeliveryService: WAITING FOR DOWN\n")
+ dds.waitUntil(DOWN, value.(int))
+ Log("DefaultDeliveryService: DOWN WAITING DONE\n")
+ } else {
+ dds.transport.TransportControl(ctrl, value)
+ }
+}
+
+func (dds *DefaultDeliveryService) TransportNotify(value interface{}) {
+ dds.transport.TransportNotify(value)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultValueFactory.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultValueFactory.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultValueFactory.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultValueFactory.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+import "reflect"
+
+const (
+ ETCH_RUNTIME_EXCEPTION_TYPE_NAME string = "_Etch_RuntimeException"
+ ETCH_LIST_TYPE_NAME string = "_Etch_List"
+ ETCH_MAP_TYPE_NAME string = "_Etch_Map"
+ ETCH_SET_TYPE_NAME string = "_Etch_Set"
+ ETCH_DATETIME_TYPE_NAME string = "_Etch_Datetime"
+ ETCH_AUTH_EXCEPTION_TYPE_NAME string = "_Etch_AuthException"
+ ETCH_EXCEPTION_MESSAGE_NAME string = "_exception"
+ MSG_FIELD_NAME string = "msg"
+ MESSAGE_ID_FIELD_NAME string = "_messageId"
+ IN_REPLY_TO_FIELD_NAME string = "_inReplyTo"
+ RESULT_FIELD_NAME string = "result"
+)
+
+type DefaultValueFactory struct {
+ Types *TypeMap
+ Class2type *map[reflect.Type]*Type
+ fieldMap map[string]*Field
+ _mf_msg *Field
+ _mf__messageId *Field
+ _mf__inReplyTo *Field
+ _mf_result *Field
+ _mt__Etch_RuntimeException *Type
+ _mt__Etch_List *Type
+ _mt__Etch_Map *Type
+ _mt__Etch_Set *Type
+ _mt__Etch_Datetime *Type
+ _mt__Etch_AuthException *Type
+ _mt__exception *Type
+}
+
+func NewDefaultValueFactory() *DefaultValueFactory {
+ ret := new(DefaultValueFactory)
+ ret.Types = NewTypeMap()
+ ret.Class2type = &(map[reflect.Type]*Type{})
+ ret.fieldMap = map[string]*Field{}
+ ret._mf_msg = NewField(MSG_FIELD_NAME)
+ ret._mf__messageId = NewField(MESSAGE_ID_FIELD_NAME)
+ ret._mf__inReplyTo = NewField(IN_REPLY_TO_FIELD_NAME)
+ ret._mf_result = NewField(RESULT_FIELD_NAME)
+ ret._mt__Etch_RuntimeException = ret.Types.GetByName(ETCH_RUNTIME_EXCEPTION_TYPE_NAME)
+ ret._mt__Etch_List = ret.Types.GetByName(ETCH_LIST_TYPE_NAME)
+ ret._mt__Etch_Map = ret.Types.GetByName(ETCH_MAP_TYPE_NAME)
+ ret._mt__Etch_Set = ret.Types.GetByName(ETCH_SET_TYPE_NAME)
+ ret._mt__Etch_Datetime = ret.Types.GetByName(ETCH_DATETIME_TYPE_NAME)
+ ret._mt__Etch_AuthException = ret.Types.GetByName(ETCH_AUTH_EXCEPTION_TYPE_NAME)
+ ret._mt__exception = ret.Types.GetByName(ETCH_EXCEPTION_MESSAGE_NAME)
+ return ret
+}
+
+func (dvf *DefaultValueFactory) AddField(field *Field) {
+ dvf.fieldMap[field.Name] = field
+}
+
+func (dvf *DefaultValueFactory) GetFieldByName(name string) *Field {
+ return dvf.fieldMap[name]
+}
+
+func (dvf *DefaultValueFactory) GetClass2type() *map[reflect.Type]*Type {
+ return dvf.Class2type
+}
+
+
+func (dvf *DefaultValueFactory) GetDefaultResponseField() *Field {
+ return dvf._mf_result
+}
+
+func (dvf *DefaultValueFactory) GetDefaultInReplyToField() *Field {
+ return dvf._mf__inReplyTo
+}
+
+func (dvf *DefaultValueFactory) GetDefaultMessageIdField() *Field {
+ return dvf._mf__messageId
+}
+
+
+func (dvf *DefaultValueFactory) GetTypeById(id int32) *Type {
+ ty := dvf.Types.GetById(id)
+ return ty
+}
+
+func (dvf *DefaultValueFactory) GetTypeByName(name string) *Type {
+ ty := dvf.Types.GetByName(name)
+ return ty
+}
+
+func (dvf *DefaultValueFactory) AddType(ty *Type) {
+ Log("DefaultValueFactory: adding type " + fmt.Sprint(ty) + "\n")
+ dvf.Types.Add(ty)
+}
+
+func ToLong(val interface{}) int64 {
+ switch val.(type) {
+ case int:
+ return int64(val.(int))
+ case int8:
+ return int64(val.(int8))
+ case int16:
+ return int64(val.(int16))
+ case int32:
+ return int64(val.(int32))
+ case int64:
+ return int64(val.(int64))
+ }
+ return 0
+}
+
+func (dvf *DefaultValueFactory) GetMessageId(theMsg *Message) int64 {
+ return ToLong(theMsg.Fields[dvf._mf__messageId])
+}
+
+func (dvf *DefaultValueFactory) SetMessageId(msg *Message, msgId int64) {
+ Log("DefaultValueFactory SETMESSAGEID " + fmt.Sprint(msgId) + "\n")
+ msg.Fields[dvf._mf__messageId] = msgId
+}
+
+func (dvf *DefaultValueFactory) GetTypes() []*Type {
+ tys := dvf.Types.GetAll()
+ newslice := make([]*Type, len(tys))
+ copy(newslice, tys)
+ return newslice
+}
+
+func (dvf *DefaultValueFactory) GetInReplyTo(msg *Message) int64 {
+ val := msg.Fields[dvf._mf__inReplyTo]
+ Log("DefaultValueFactory GetInReplyTo looking in fields " + fmt.Sprint(msg.Fields) + "/" + fmt.Sprint(&(dvf._mf__inReplyTo)) + "\n")
+ if val == nil {
+ Log("DefaultValueFactory got nil \n")
+ return 0
+ }
+ Log("DefaultValueFactory GetInReplyTo was " + fmt.Sprint(val) + "\n")
+ return ToLong(val)
+}
+
+func (dvf *DefaultValueFactory) SetInReplyTo(msg *Message, msgId int64) {
+ msg.Fields[dvf._mf__inReplyTo] = msgId
+}
+
+func (dvf *DefaultValueFactory) ExportCustomValue(value interface{}) *StructValue {
+ ty := reflect.Typeof(value)
+ etchty := (*dvf.Class2type)[ty]
+ if etchty.Helper != nil {
+ return etchty.Helper.ExportValue(etchty, dvf, value)
+ }
+ return nil
+}
+
+func (dvf *DefaultValueFactory) ImportCustomValue(value *StructValue) interface{} {
+ if value.Ty.Helper != nil {
+ return value.Ty.Helper.ImportValue(value)
+ }
+ return nil
+}
+
+func (dvf *DefaultValueFactory) GetCustomStructType(obj reflect.Type) *Type {
+ return (*dvf.Class2type)[obj]
+}
+
+
+func NewboolArray(length int32) []bool {
+ return make([]bool, length)
+}
+func Newint8Array(length int32) []int8 {
+ return make([]int8, length)
+}
+func Newint16Array(length int32) []int16 {
+ return make([]int16, length)
+}
+func Newint32Array(length int32) []int32 {
+ return make([]int32, length)
+}
+func Newint64Array(length int32) []int64 {
+ return make([]int64, length)
+}
+func Newfloat32Array(length int32) []float32 {
+ return make([]float32, length)
+}
+func Newfloat64Array(length int32) []float64 {
+ return make([]float64, length)
+}
+func NewstringArray(length int32) []interface{} {
+ return make([]interface{}, length)
+}
+func NewInterfaceArray(length int32) []interface{} {
+ return make([]interface{}, length)
+}
+
+func (dvf *DefaultValueFactory)NewArrayForType(typeCode int8, cTy *Type, length int32) interface{}{
+ switch typeCode {
+ case BYTE:
+ return Newint8Array(length)
+ case SHORT:
+ return Newint16Array(length)
+ case INT:
+ return Newint32Array(length)
+ case LONG:
+ return Newint64Array(length)
+ case FLOAT:
+ return Newfloat32Array(length)
+ case DOUBLE:
+ return Newfloat64Array(length)
+ case STRING:
+ return NewstringArray(length)
+ case CUSTOM:
+ return cTy.NewArray(length)
+ }
+ return nil
+}
\ No newline at end of file
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DeliveryService.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DeliveryService.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DeliveryService.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DeliveryService.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+
+const (
+ UP int = iota
+ DOWN
+)
+
+const (
+ START int = iota
+ START_AND_WAIT_UP
+ STOP
+ STOP_AND_WAIT_DOWN
+)
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Direction.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Direction.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Direction.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Direction.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type Direction int
+
+const (
+ BOTH Direction = iota
+ SERVER
+ CLIENT
+)
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/EtchStub.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/EtchStub.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/EtchStub.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/EtchStub.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type StubHelper interface {
+ run(svc DeliveryService, impl interface{}, sender interface{}, msg *Message)
+}
+
+
+type EtchStub struct {
+ svc DeliveryService
+ Impl interface{}
+}
+
+func NewEtchStub(svc DeliveryService, impl interface{}) *EtchStub {
+ return &EtchStub{svc, impl}
+}
+
+func (es *EtchStub) SessionMessage(sender interface{}, theMsg *Message) bool {
+ Log("EtchStub: Server got message\n")
+ ty := theMsg.GetType()
+
+ stubhelper := ty.StubHelper
+ if stubhelper == nil {
+ Log("EtchStub: no handler for " + fmt.Sprint(theMsg) + "\n")
+ return false
+ }
+
+ execution := func() {
+ helper := stubhelper.(StubHelper)
+ helper.run(es.svc, es.Impl, sender, theMsg)
+ }
+
+ if ty.AsyncMode != MODE_NONE {
+ go execution()
+ } else {
+ execution()
+ }
+
+ return true
+}
+
+func (es *EtchStub) SessionQuery(obj interface{}) interface{} {
+ defer EtchRecoverAll()
+ val := es.Impl.(Session)
+ if val != nil {
+ return val.SessionQuery(obj)
+ }
+ return nil
+}
+
+
+func (es *EtchStub) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ defer EtchRecoverAll()
+ val := es.Impl.(Session)
+ if val != nil {
+ return val.SessionControl(ctrl, value)
+ }
+ return nil
+}
+
+func (es *EtchStub) SessionNotify(obj interface{}) {
+ defer EtchRecoverAll()
+ val := es.Impl.(Session)
+ if val != nil {
+ val.SessionNotify(obj)
+ }
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Field.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Field.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Field.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Field.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type Field struct {
+ IdName
+}
+
+func NewField(name string) *Field {
+ return &Field{*NewIdNameByName(name)}
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Flexbuffer.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Flexbuffer.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Flexbuffer.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Flexbuffer.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "encoding/binary"
+import "os"
+import "sync"
+//import "fmt"
+
+type FlexBuffer struct {
+ buf []byte
+ Index int
+ Length int
+ mutex *sync.Mutex
+}
+
+func NewFlexBuffer() *FlexBuffer {
+ return &FlexBuffer{make([]byte, 32), 0, 0, new(sync.Mutex)}
+}
+
+func (fb *FlexBuffer) Write(p []byte) (n int, err os.Error) {
+ fb.mutex.Lock()
+// Log("Flexbuffer: BeginWrite: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " length " + fmt.Sprint(fb.Length) + " index " + fmt.Sprint(fb.Index) + " datalen " + fmt.Sprint(len(p)) + "\n")
+ fb.ensureLength(fb.Index + len(p))
+// Log("Flexbuffer: MiddleWrite: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " length " + fmt.Sprint(fb.Length) + " index " + fmt.Sprint(fb.Index) + " datalen " + fmt.Sprint(len(p)) + "\n")
+ copy(fb.buf[fb.Index:fb.Index + len(p)],p)
+ fb.Index = fb.Index + len(p)
+ fb.fixLength()
+// Log("Flexbuffer: EndWrite: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " length " + fmt.Sprint(fb.Length) + " index " + fmt.Sprint(fb.Index) + " datalen " + fmt.Sprint(len(p)) + "\n")
+// Log("Flexbuffer: EndWrite: " + fmt.Sprint(fb.avail()) + "\n")
+ fb.mutex.Unlock()
+ return len(p), nil
+}
+
+func (fb *FlexBuffer) ensureLength(newLength int) {
+ if newLength < len(fb.buf) {
+ return
+ }
+ fb.enlargeBuffer(newLength)
+}
+
+func (fb *FlexBuffer) enlargeBuffer(desired int) {
+ l := len(fb.buf)
+ for l < desired {
+ l = l * 2
+ }
+// Log("New BUFFER SIZE " + fmt.Sprint(l) + "\n")
+ newBuf := make([]byte, l)
+ copy(newBuf, fb.buf)
+ fb.buf = newBuf
+}
+
+func (fb *FlexBuffer) fixLength() {
+ if(fb.Index > fb.Length) {
+ fb.Length = fb.Index
+ }
+}
+
+func (fb *FlexBuffer) Avail() int {
+ return fb.avail()
+}
+
+func (fb *FlexBuffer) avail() int {
+ return fb.Length - fb.Index
+}
+
+func (fb *FlexBuffer) Read(p []byte) (n int, err os.Error) {
+ fb.mutex.Lock()
+
+// Log("Flexbuffer: BeginRead: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " " + fmt.Sprint(fb.Length) + " " + fmt.Sprint(fb.Index) + " " + fmt.Sprint(len(p)) + "\n")
+
+ toRead := len(p)
+ if fb.avail() < toRead {
+ toRead = fb.avail()
+ }
+
+// Log("Flexbuffer: MiddleRead: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " " + fmt.Sprint(fb.Length) + " " + fmt.Sprint(fb.Index) + " " + fmt.Sprint(toRead) + "\n")
+
+ copy(p, fb.buf[fb.Index:fb.Index+toRead])
+ fb.Index = fb.Index + toRead
+
+// Log("Flexbuffer: EndRead: " + fmt.Sprint(p) + " " + fmt.Sprint(fb.buf) + " " + fmt.Sprint(fb.Length) + " " + fmt.Sprint(fb.Index) + " " + fmt.Sprint(toRead) + "\n")
+ fb.mutex.Unlock()
+ return toRead, nil
+}
+
+func (fb *FlexBuffer) PutFromOtherFull(other *FlexBuffer) {
+// Log("Flexbuffer.PutFromOtherFull " + fmt.Sprint(other.avail()) + "\n")
+ fb.PutFromOther(other, int32(other.avail()))
+}
+
+func (fb *FlexBuffer) PutFromOther(other *FlexBuffer, l int32) {
+// Log("Flexbuffer.PutFromOther " + fmt.Sprint(l) + " " + fmt.Sprint(other) + "\n")
+ buf := make([]byte, l)
+ other.Read(buf)
+ fb.Write(buf)
+}
+
+func (fb *FlexBuffer) Put(val interface{}) {
+ binary.Write(fb, binary.BigEndian, val)
+}
+
+func (fb *FlexBuffer) PutByte(b int8) {
+ binary.Write(fb, binary.BigEndian, b)
+}
+
+func (fb *FlexBuffer) PutInt(i int32) {
+ binary.Write(fb, binary.BigEndian, i)
+}
+
+func (fb *FlexBuffer) PutShort(s int16) {
+ binary.Write(fb, binary.BigEndian, s)
+}
+
+func (fb *FlexBuffer) PutLong(l int64) {
+ binary.Write(fb, binary.BigEndian, l)
+}
+
+func (fb *FlexBuffer) PutFloat(f float32) {
+ binary.Write(fb, binary.BigEndian, f)
+}
+
+func (fb *FlexBuffer) PutDouble(d float64) {
+ binary.Write(fb, binary.BigEndian, d)
+}
+
+func (fb *FlexBuffer) PutBytes(bytes []uint8) {
+ binary.Write(fb, binary.BigEndian, bytes)
+}
+
+func (fb *FlexBuffer) PutSBytes(bytes []int8) {
+ binary.Write(fb, binary.BigEndian, bytes)
+}
+
+func (fb *FlexBuffer) ReadByte() int8 {
+ ret := new(int8)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadInt() int32 {
+ ret := new(int32)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadShort() int16 {
+ ret := new(int16)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadLong() int64 {
+ ret := new(int64)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadFloat() float32 {
+ ret := new(float32)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadDouble() float64 {
+ ret := new(float64)
+ binary.Read(fb, binary.BigEndian, ret)
+ return *ret
+}
+
+func (fb *FlexBuffer) ReadBytes(bytes *[]uint8) {
+ binary.Read(fb, binary.BigEndian, bytes)
+}
+
+func (fb *FlexBuffer) ReadSBytes(bytes *[]int8) {
+ binary.Read(fb, binary.BigEndian, bytes)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdName.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdName.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdName.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdName.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type IdName struct {
+ Id int32
+ Name string
+}
+
+func NewIdName(id int32, name string) *IdName {
+ return &IdName{id, name}
+}
+
+func NewIdNameByName(name string) *IdName {
+ return &IdName{hash(name), name}
+}
+
+
+func hash(val string) int32 {
+ hash := 5381
+ n := len(val)
+ for i := 0; i < n; i++ {
+ c := int(val[i])
+ h6 := hash << 6
+ hash = (h6 << 10) + h6 - hash + c
+ }
+ return int32(hash)
+
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdNameMap.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdNameMap.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdNameMap.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdNameMap.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type IdNameMap interface {
+ MakeNew(name string) *IdName
+ GetById(id int) *IdName
+ GetByName(id int) *IdName
+ Add(value *IdName) (*IdName, string)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ImportExportHelper.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ImportExportHelper.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ImportExportHelper.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ImportExportHelper.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+
+type ImportExportHelper interface {
+ ExportValue(ty *Type, vf ValueFactory, value interface{}) *StructValue
+ ImportValue(str *StructValue) interface{}
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Logger.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Logger.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Logger.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Logger.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+var HasError bool = false
+
+func Log(s string) {
+ //fmt.Printf(s)
+}
+
+func Error(s string) {
+ HasError = true
+ fmt.Printf("****************************************************\n")
+ fmt.Printf(s)
+ fmt.Printf("****************************************************\n")
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Mailbox.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Mailbox.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Mailbox.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Mailbox.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+
+type Element struct {
+ Who interface{}
+ Msg *Message
+}
+
+type Mailbox interface {
+ GetMessageId() int64
+ Message(sender interface{}, msg *Message) bool
+ Read() *Element
+ CloseDelivery() bool
+ CloseRead() bool
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Makefile
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Makefile?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Makefile (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Makefile Mon Nov 29 14:29:21 2010
@@ -0,0 +1,53 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+GOFILES=\
+ Mailbox.go\
+ Flexbuffer.go\
+ Util.go\
+ Logger.go\
+ StructValue.go\
+ Type.go\
+ Message.go\
+ ValueFactory.go\
+ Field.go\
+ Validator.go\
+ ImportExportHelper.go\
+ Direction.go\
+ IdName.go\
+ IdNameMap.go\
+ TypeMap.go\
+ DefaultValueFactory.go\
+ TaggedDataInput.go\
+ TaggedDataOutput.go\
+ BinaryTaggedData.go\
+ BinaryTaggedDataInput.go\
+ BinaryTaggedDataOutput.go\
+ PlainMailBox.go\
+ DeliveryService.go\
+ DefaultDeliveryService.go\
+ Packetizer.go\
+ Messagizer.go\
+ TcpConnection.go\
+ TcpListener.go\
+ SessionTransport.go\
+ PlainMailBoxManager.go\
+ EtchStub.go\
+
+all:
+ 8g -o etch.8 ${GOFILES}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Message.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Message.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Message.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Message.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type Message struct {
+ StructValue
+}
+
+func NewMessage(ty *Type, vf ValueFactory, length int) *Message {
+ return &Message{StructValue{ty, vf, length, map[*Field]interface{}{}}}
+}
+
+func (msg *Message) ReplyWith(rty *Type) *Message {
+ //8 is a magic number from Java Binding, investigate further
+ rmsg := NewMessage(rty, msg.Vf, 8)
+ rmsg.Vf.SetInReplyTo(rmsg, rmsg.Vf.GetMessageId(msg))
+ return rmsg
+}
+
+func (msg *Message) Reply() *Message {
+ return msg.ReplyWith(msg.Ty.RType)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Messagizer.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Messagizer.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Messagizer.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Messagizer.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type Messagizer struct {
+ buf *FlexBuffer
+ transport TransportPacket
+ sess SessionMessage
+ tdi TaggedDataInput
+ tdo TaggedDataOutput
+}
+
+func NewMessagizer(vf ValueFactory, transport TransportPacket) *Messagizer {
+ buf := NewFlexBuffer()
+
+ return &Messagizer{buf, transport, nil, NewBinaryTaggedDataInput(vf), NewBinaryTaggedDataOutput(vf)}
+
+}
+
+func (m *Messagizer) SessionQuery(obj interface{}) interface{} {
+ return m.sess.SessionQuery(obj)
+}
+
+func (m *Messagizer) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return m.sess.SessionControl(ctrl, value)
+}
+
+func (m *Messagizer) SessionNotify(obj interface{}) {
+ m.sess.SessionNotify(obj)
+}
+
+func (m *Messagizer) GetSession() Session {
+ return m.sess
+}
+
+func (m *Messagizer) SetSession(sess Session) {
+ m.sess = sess.(SessionMessage)
+}
+
+func (m *Messagizer) TransportQuery(obj interface{}) interface{} {
+ return m.transport.TransportQuery(obj)
+}
+
+func (m *Messagizer) TransportControl(ctrl interface{}, value interface{}) {
+ Log("Messagizer: transportControl: " + fmt.Sprint(ctrl) + "\n")
+ m.transport.TransportControl(ctrl, value)
+}
+
+func (m *Messagizer) TransportNotify(value interface{}) {
+ m.transport.TransportNotify(value)
+}
+
+func (m *Messagizer) TransportMessage(recipient interface{}, msg *Message) {
+ //leave space for header
+ m.buf.Index = 8
+ m.tdo.WriteMessage(msg, m.buf)
+ m.buf.Index = 0
+ m.transport.TransportPacket(recipient, m.buf)
+}
+
+func (m *Messagizer) SessionPacket(sender interface{}, buf *FlexBuffer) {
+ msg := m.tdi.ReadMessage(buf)
+ m.sess.SessionMessage(sender, msg)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Packetizer.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Packetizer.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Packetizer.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Packetizer.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+const (
+ SIG uint32 = uint32(0xdeadbeef)
+ HEADER_SIZE int = 8
+)
+
+type Packetizer struct {
+ transport TransportData
+ maxPktSize int
+ saveBuf *FlexBuffer
+ nextPacketLen int
+ session SessionPacket
+}
+
+func NewPacketizer(transport TransportData, maxPktSize int) *Packetizer {
+ return &Packetizer{transport, maxPktSize, NewFlexBuffer(), 0, nil}
+}
+
+func (p *Packetizer) SessionData(sender interface{}, buf *FlexBuffer) {
+ Log("Packetizer.SessionPacket: available initially " + fmt.Sprint(p.saveBuf.avail()) + "\n")
+ i := p.saveBuf.Index
+ p.saveBuf.PutFromOtherFull(buf)
+ p.saveBuf.Index = i
+
+ if p.nextPacketLen != 0 {
+ Log("Packetizer.SessionPacket: got new Packet\n")
+ if int(p.saveBuf.avail()) > p.nextPacketLen {
+ p.processPacket(sender)
+ }
+ } else {
+ Log("Packetizer.SessionPacket: looking for header\n")
+ if p.saveBuf.avail() >= HEADER_SIZE {
+ Log("Packetizer.SessionPacket: got new header\n")
+ p.nextPacketLen = p.processHeader()
+ Log("Packetizer.SessionPacket: available after header " + fmt.Sprint(p.saveBuf.avail()) + "\n")
+
+ if p.saveBuf.avail() >= p.nextPacketLen {
+ p.processPacket(sender)
+ }
+ } else {
+ Log("Packetizer.SessionPacket: not yet a header, only "+ fmt.Sprint(p.saveBuf.avail())+" bytes in savebuf\n")
+ }
+ }
+}
+
+func (p *Packetizer) processPacket(sender interface{}) {
+ Log("Packetizer.processPacket\n")
+
+ Log("Packetizer: old Index in processpaket " + fmt.Sprint(p.saveBuf.Index) + "\n")
+
+ packet := make([]uint8, p.nextPacketLen)
+
+ fullLength := p.saveBuf.Length
+ currentPacketLength := p.saveBuf.Index + p.nextPacketLen
+ p.saveBuf.Length = currentPacketLength
+
+ p.saveBuf.ReadBytes(&packet)
+
+ //there might be bytes after our full packet in the buffer
+ p.saveBuf.Length = fullLength
+ p.saveBuf.Index = currentPacketLength
+
+ Log("Packetizer: resetting Index to " + fmt.Sprint(p.saveBuf.Index) + "\n")
+
+ p.nextPacketLen = 0
+
+ packetBuf := NewFlexBuffer()
+ packetBuf.PutBytes(packet)
+ packetBuf.Index = 0
+
+ if p.session != nil {
+ p.session.SessionPacket(sender, packetBuf)
+ }
+}
+
+
+func (p *Packetizer) processHeader() int {
+ //SIG, no check here :)
+ p.saveBuf.ReadInt()
+ //LENGTH
+ l := p.saveBuf.ReadInt()
+ Log("Packetizer.processHeader Header length " + fmt.Sprint(l) + "\n")
+ return int(l)
+}
+
+func (p *Packetizer) SessionQuery(obj interface{}) interface{} {
+ return p.session.SessionQuery(obj)
+}
+
+func (p *Packetizer) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return p.session.SessionControl(ctrl, value)
+}
+
+func (p *Packetizer) SessionNotify(obj interface{}) {
+ p.session.SessionNotify(obj)
+}
+
+func (p *Packetizer) TransportPacket(recipient interface{}, buf *FlexBuffer) {
+ dataSize := buf.avail()
+ pktSize := dataSize
+ if pktSize > p.maxPktSize {
+ return
+ }
+ i := SIG
+ buf.PutInt(int32(i))
+ buf.PutInt(int32(dataSize - HEADER_SIZE))
+ buf.Index = 0
+ p.transport.TransportData(recipient, buf)
+}
+
+func (p *Packetizer) GetSession() Session {
+ return p.session.(Session)
+}
+
+func (p *Packetizer) SetSession(sess Session) {
+ p.session = sess.(SessionPacket)
+}
+
+func (p *Packetizer) TransportQuery(obj interface{}) interface{} {
+ return p.transport.TransportQuery(obj)
+}
+
+func (p *Packetizer) TransportControl(ctrl interface{}, value interface{}) {
+ Log("Packetizer: transportControl: " + fmt.Sprint(ctrl) + "\n")
+ p.transport.TransportControl(ctrl, value)
+}
+
+func (p *Packetizer) TransportNotify(value interface{}) {
+ p.transport.TransportNotify(value)
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBox.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBox.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBox.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBox.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+type PlainMailBox struct {
+ messageId int64
+ queue chan interface{}
+}
+
+
+func NewPlainMailBox(msgId int64) *PlainMailBox {
+ ret := &PlainMailBox{msgId, nil}
+ ret.queue = make(chan interface{}, 1)
+ return ret
+}
+
+func (pmb *PlainMailBox) GetMessageId() int64 {
+ return pmb.messageId
+}
+
+
+func (pmb *PlainMailBox) Message(sender interface{}, msg *Message) bool {
+ pmb.queue <- &Element{sender, msg}
+ return true
+
+}
+
+func (pmb *PlainMailBox) Read() *Element {
+ val := WaitOnChannel(nil, 4000, pmb.queue)
+ if val == nil {
+ return nil
+ }
+ return val.(*Element)
+}
+
+func (pmb *PlainMailBox) CloseDelivery() bool {
+ //this looses all queue contents, TODO
+ close(pmb.queue)
+ return true
+}
+
+func (pmb *PlainMailBox) CloseRead() bool {
+
+ return pmb.CloseDelivery()
+}
Added: incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBoxManager.go
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBoxManager.go?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBoxManager.go (added)
+++ incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBoxManager.go Mon Nov 29 14:29:21 2010
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package etch
+
+import "fmt"
+
+type PlainMailboxManager struct {
+ session SessionMessage
+ transport TransportMessage
+ mailboxes map[int64]Mailbox
+}
+
+func NewPlainMailboxManager(session SessionMessage, transport TransportMessage) MailboxManager {
+ return &PlainMailboxManager{session, transport, make(map[int64]Mailbox)}
+}
+
+var id int64 = int64(42)
+
+func nextId() int64 {
+ id = id + 1
+ return id
+}
+
+func (pmb *PlainMailboxManager) TransportCall(recipient interface{}, msg *Message) Mailbox {
+ msg.Vf.SetMessageId(msg, nextId())
+ mb := NewPlainMailBox(msg.Vf.GetMessageId(msg))
+ pmb.Register(mb)
+ pmb.transport.TransportMessage(recipient, msg)
+ return mb
+}
+
+func (pmb *PlainMailboxManager) TransportMessage(recipient interface{}, msg *Message) {
+ msg.Vf.SetMessageId(msg, nextId())
+ pmb.transport.TransportMessage(recipient, msg)
+}
+
+func (pmb *PlainMailboxManager) Unregister(mb Mailbox) {
+ pmb.mailboxes[mb.GetMessageId()] = nil
+}
+
+func (pmb *PlainMailboxManager) Register(mb Mailbox) {
+ pmb.mailboxes[mb.GetMessageId()] = mb
+}
+
+func (pmb *PlainMailboxManager) Redeliver(sender interface{}, msg *Message) {
+ pmb.session.SessionMessage(sender, msg)
+}
+
+func (pmb *PlainMailboxManager) SessionMessage(sender interface{}, theMsg *Message) bool {
+
+ if theMsg == nil { //e.g. type not known
+ //discard message
+ Log("PlainMailboxManager: discarding message\n")
+ return false
+ }
+
+ Log("PlainMailboxManager: Got Msg with ID " + fmt.Sprint(theMsg.Vf.GetMessageId(theMsg)) + "\n")
+ theMsgid := theMsg.Vf.GetInReplyTo(theMsg)
+ Log("PlainMailboxManager: Msg is reply to " + fmt.Sprint(theMsgid) + "\n")
+
+ if theMsgid != 0 {
+ mb := pmb.mailboxes[theMsgid]
+ if mb != nil {
+ return mb.Message(sender, theMsg)
+ }
+ Log("PlainMailboxManager: did not find a mailbox for " + fmt.Sprint(theMsgid) + "\n")
+ return false
+ }
+ return pmb.session.SessionMessage(sender, theMsg)
+}
+
+
+func (pmb *PlainMailboxManager) GetSession() Session {
+ return pmb.session
+}
+
+func (pmb *PlainMailboxManager) SetSession(sess Session) {
+ pmb.session = sess.(SessionMessage)
+}
+
+func (pmb *PlainMailboxManager) TransportQuery(obj interface{}) interface{} {
+ return pmb.transport.TransportQuery(obj)
+}
+
+func (pmb *PlainMailboxManager) TransportControl(ctrl interface{}, value interface{}) {
+ Log("PlainMailboxManager: transportControl: " + fmt.Sprint(ctrl) + "\n")
+ pmb.transport.TransportControl(ctrl, value)
+}
+
+func (pmb *PlainMailboxManager) TransportNotify(value interface{}) {
+ pmb.transport.TransportNotify(value)
+}
+
+func (pmb *PlainMailboxManager) SessionQuery(obj interface{}) interface{} {
+ return pmb.session.SessionQuery(obj)
+}
+
+func (pmb *PlainMailboxManager) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return pmb.session.SessionControl(ctrl, value)
+}
+
+func (pmb *PlainMailboxManager) SessionNotify(obj interface{}) {
+ pmb.session.SessionNotify(obj)
+}