This commit is contained in:
Tobias Oberstein
2014-02-11 17:10:14 +01:00
parent a0c7c07f25
commit 94b1c6d963
33 changed files with 694 additions and 341 deletions

View File

@@ -66,110 +66,110 @@ server:
server_with_rpc_timeservice_backend: server_with_rpc_timeservice_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.timeservice.TimeServiceBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.timeservice.backend.Component"
client_rpc_timeservice_frontend: client_rpc_timeservice_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.TimeServiceFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.frontend.Component"
client_rpc_timeservice_backend: client_rpc_timeservice_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.TimeServiceBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.backend.Component"
server_with_rpc_arguments_backend: server_with_rpc_arguments_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.arguments.ArgumentsBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.arguments.backend.Component"
client_rpc_arguments_frontend: client_rpc_arguments_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.ArgumentsFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.frontend.Component"
client_rpc_arguments_backend: client_rpc_arguments_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.ArgumentsBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.backend.Component"
server_with_rpc_options_backend: server_with_rpc_options_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.rpcoptions.RpcOptionsBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.options.backend.Component"
client_rpc_options_frontend: client_rpc_options_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.rpcoptions.RpcOptionsFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.options.frontend.Component"
client_rpc_options_backend: client_rpc_options_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.rpcoptions.RpcOptionsBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.options.backend.Component"
server_with_rpc_errors_backend: server_with_rpc_errors_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.errors.ErrorsTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.errors.backend.Component"
client_rpc_errors_frontend: client_rpc_errors_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.ErrorsTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.frontend.Component"
client_rpc_errors_backend: client_rpc_errors_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.ErrorsTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.backend.Component"
server_with_rpc_complex_backend: server_with_rpc_complex_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.complex.ComplexBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.complex.backend.Component"
client_rpc_complex_frontend: client_rpc_complex_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.ComplexFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.frontend.Component"
client_rpc_complex_backend: client_rpc_complex_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.ComplexBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.backend.Component"
server_with_rpc_progress_backend: server_with_rpc_progress_backend:
PYTHONPATH=../../../../autobahn python server.py --component "rpc.progress.ProgressiveBackend" PYTHONPATH=../../../../autobahn python server.py --component "rpc.progress.backend.Component"
client_rpc_progress_frontend: client_rpc_progress_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.ProgressiveFrontend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.frontend.Component"
client_rpc_progress_backend: client_rpc_progress_backend:
PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.ProgressiveBackend" PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.backend.Component"
server_with_pubsub_basic_backend: server_with_pubsub_basic_backend:
PYTHONPATH=../../../../autobahn python server.py --component "pubsub.pubsub.PubSubTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "pubsub.basic.backend.Component"
client_pubsub_basic_frontend: client_pubsub_basic_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsub.PubSubTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.basic.frontend.Component"
client_pubsub_basic_backend: client_pubsub_basic_backend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsub.PubSubTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.basic.backend.Component"
server_with_pubsub_complex_backend: server_with_pubsub_complex_backend:
PYTHONPATH=../../../../autobahn python server.py --component "pubsub.complexevent.ComplexEventTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "pubsub.complex.backend.Component"
client_pubsub_complex_frontend: client_pubsub_complex_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complexevent.ComplexEventTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complex.frontend.Component"
client_pubsub_complex_backend: client_pubsub_complex_backend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complexevent.ComplexEventTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complex.backend.Component"
server_with_pubsub_options_backend: server_with_pubsub_options_backend:
PYTHONPATH=../../../../autobahn python server.py --component "pubsub.pubsuboptions.PubSubOptionsTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "pubsub.options.backend.Component"
client_pubsub_options_frontend: client_pubsub_options_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsuboptions.PubSubOptionsTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.options.frontend.Component"
client_pubsub_options_backend: client_pubsub_options_backend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsuboptions.PubSubOptionsTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.options.backend.Component"
server_with_pubsub_unsubscribe_backend: server_with_pubsub_unsubscribe_backend:
PYTHONPATH=../../../../autobahn python server.py --component "pubsub.unsubscribe.UnsubscribeTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "pubsub.unsubscribe.backend.Component"
client_pubsub_unsubscribe_frontend: client_pubsub_unsubscribe_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.UnsubscribeTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.frontend.Component"
client_pubsub_unsubscribe_backend: client_pubsub_unsubscribe_backend:
PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.UnsubscribeTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.backend.Component"
server_with_session_series_backend: server_with_session_series_backend:
PYTHONPATH=../../../../autobahn python server.py --component "session.series.SeriesTestBackend" PYTHONPATH=../../../../autobahn python server.py --component "session.series.backend.Component"
client_session_series_frontend: client_session_series_frontend:
PYTHONPATH=../../../../autobahn python client.py --component "session.series.SeriesTestFrontend" PYTHONPATH=../../../../autobahn python client.py --component "session.series.frontend.Component"
client_session_series_backend: client_session_series_backend:
PYTHONPATH=../../../../autobahn python client.py --component "session.series.SeriesTestBackend" PYTHONPATH=../../../../autobahn python client.py --component "session.series.backend.Component"

View File

@@ -0,0 +1,42 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)

View File

@@ -24,26 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession
class PubSubTestBackend(ApplicationSession): class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)
class PubSubTestFrontend(ApplicationSession):
""" """
An application component that subscribes and receives events, An application component that subscribes and receives events,
and stop after having received 5 events. and stop after having received 5 events.

View File

@@ -0,0 +1,17 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################

View File

@@ -0,0 +1,51 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
import random
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.wamp.types import SubscribeOptions
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component that publishes events with no payload
and with complex payloads every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.heartbeat')
obj = {'counter': counter, 'foo': [1, 2, 3]}
self.publish('com.myapp.topic2', random.randint(0, 100), 23, c = "Hello", d = obj)
counter += 1
yield sleep(1)

View File

@@ -27,32 +27,7 @@ from autobahn.twisted.wamp import ApplicationSession
class ComplexEventTestBackend(ApplicationSession): class Component(ApplicationSession):
"""
An application component that publishes events with no payload
and with complex payloads every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.heartbeat')
obj = {'counter': counter, 'foo': [1, 2, 3]}
self.publish('com.myapp.topic2', random.randint(0, 100), 23, c = "Hello", d = obj)
counter += 1
yield sleep(1)
class ComplexEventTestFrontend(ApplicationSession):
""" """
An application component that subscribes and receives events An application component that subscribes and receives events
of no payload and of complex payload, and stops after 5 seconds. of no payload and of complex payload, and stops after 5 seconds.

View File

@@ -0,0 +1,17 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################

View File

@@ -0,0 +1,45 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.wamp.types import PublishOptions, EventDetails, SubscribeOptions
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
publication = yield self.publish('com.myapp.topic1', counter,
options = PublishOptions(acknowledge = True, discloseMe = True))
print("Event published with publication ID {}".format(publication.id))
counter += 1
yield sleep(1)

View File

@@ -25,28 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession
class PubSubOptionsTestBackend(ApplicationSession): class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
publication = yield self.publish('com.myapp.topic1', counter,
options = PublishOptions(acknowledge = True, discloseMe = True))
print("Event published with publication ID {}".format(publication.id))
counter += 1
yield sleep(1)
class PubSubOptionsTestFrontend(ApplicationSession):
""" """
An application component that subscribes and receives events, An application component that subscribes and receives events,
and stop after having received 5 events. and stop after having received 5 events.

View File

@@ -0,0 +1,17 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################

View File

@@ -0,0 +1,43 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)

View File

@@ -24,27 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession
class UnsubscribeTestBackend(ApplicationSession): class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)
class UnsubscribeTestFrontend(ApplicationSession):
""" """
An application component that subscribes and receives events. An application component that subscribes and receives events.
After receiving 5 events, it unsubscribes, sleeps and then After receiving 5 events, it unsubscribes, sleeps and then

View File

@@ -0,0 +1,57 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component providing procedures with
different kinds of arguments.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def ping():
return
def add2(a, b):
return a + b
def stars(nick = "somebody", stars = 0):
return "{} starred {}x".format(nick, stars)
def orders(product, limit = 5):
return ["Product {}".format(i) for i in range(50)][:limit]
def arglen(*args, **kwargs):
return [len(args), len(kwargs)]
self.register(ping, 'com.arguments.ping')
self.register(add2, 'com.arguments.add2')
self.register(stars, 'com.arguments.stars')
self.register(orders, 'com.arguments.orders')
self.register(arglen, 'com.arguments.arglen')

View File

@@ -23,42 +23,7 @@ from autobahn.twisted.wamp import ApplicationSession
class ArgumentsBackend(ApplicationSession): class Component(ApplicationSession):
"""
An application component providing procedures with
different kinds of arguments.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def ping():
return
def add2(a, b):
return a + b
def stars(nick = "somebody", stars = 0):
return "{} starred {}x".format(nick, stars)
def orders(product, limit = 5):
return ["Product {}".format(i) for i in range(50)][:limit]
def arglen(*args, **kwargs):
return [len(args), len(kwargs)]
self.register(ping, 'com.arguments.ping')
self.register(add2, 'com.arguments.add2')
self.register(stars, 'com.arguments.stars')
self.register(orders, 'com.arguments.orders')
self.register(arglen, 'com.arguments.arglen')
class ArgumentsFrontend(ApplicationSession):
""" """
An application component calling the different backend procedures. An application component calling the different backend procedures.
""" """

View File

@@ -0,0 +1,48 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.wamp.types import CallResult
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
Application component that provides procedures which
return complex results.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def add_complex(a, ai, b, bi):
return CallResult(c = a + b, ci = ai + bi)
self.register(add_complex, 'com.myapp.add_complex')
def split_name(fullname):
forename, surname = fullname.split()
return CallResult(forename, surname)
self.register(split_name, 'com.myapp.split_name')

View File

@@ -24,32 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession
class ComplexBackend(ApplicationSession): class Component(ApplicationSession):
"""
Application component that provides procedures which
return complex results.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def add_complex(a, ai, b, bi):
return CallResult(c = a + b, ci = ai + bi)
self.register(add_complex, 'com.myapp.add_complex')
def split_name(fullname):
forename, surname = fullname.split()
return CallResult(forename, surname)
self.register(split_name, 'com.myapp.split_name')
class ComplexFrontend(ApplicationSession):
""" """
Application component that calls procedures which Application component that calls procedures which
produce complex results and showing how to access those. produce complex results and showing how to access those.

View File

@@ -36,7 +36,7 @@ class AppError1(Exception):
class ErrorsTestBackend(ApplicationSession): class Component(ApplicationSession):
""" """
Example WAMP application backend that raised exceptions. Example WAMP application backend that raised exceptions.
""" """
@@ -85,59 +85,3 @@ class ErrorsTestBackend(ApplicationSession):
raise AppError1(b - a) raise AppError1(b - a)
self.register(compare, 'com.myapp.compare') self.register(compare, 'com.myapp.compare')
class ErrorsTestFrontend(ApplicationSession):
"""
Example WAMP application frontend that catches exceptions.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
## catching standard exceptions
##
for x in [2, 0, -2]:
try:
res = yield self.call('com.myapp.sqrt', x)
except Exception as e:
print("Error: {} {}".format(e, e.args))
else:
print("Result: {}".format(res))
## catching WAMP application exceptions
##
for name in ['foo', 'a', '*'*11, 'Hello']:
try:
res = yield self.call('com.myapp.checkname', name)
except ApplicationError as e:
print("Error: {} {} {} {}".format(e, e.error, e.args, e.kwargs))
else:
print("Result: {}".format(res))
## defining and automapping WAMP application exceptions
##
self.define(AppError1)
try:
yield self.call('com.myapp.compare', 3, 17)
except AppError1 as e:
print("Compare Error: {}".format(e))
self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self):
reactor.stop()

View File

@@ -0,0 +1,91 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
import math
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn import wamp
from autobahn.wamp.exception import ApplicationError
from autobahn.twisted.wamp import ApplicationSession
@wamp.error("com.myapp.error1")
class AppError1(Exception):
"""
An application specific exception that is decorated with a WAMP URI,
and hence can be automapped by Autobahn.
"""
class Component(ApplicationSession):
"""
Example WAMP application frontend that catches exceptions.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
## catching standard exceptions
##
for x in [2, 0, -2]:
try:
res = yield self.call('com.myapp.sqrt', x)
except Exception as e:
print("Error: {} {}".format(e, e.args))
else:
print("Result: {}".format(res))
## catching WAMP application exceptions
##
for name in ['foo', 'a', '*'*11, 'Hello']:
try:
res = yield self.call('com.myapp.checkname', name)
except ApplicationError as e:
print("Error: {} {} {} {}".format(e, e.error, e.args, e.kwargs))
else:
print("Result: {}".format(res))
## defining and automapping WAMP application exceptions
##
self.define(AppError1)
try:
yield self.call('com.myapp.compare', 3, 17)
except AppError1 as e:
print("Compare Error: {}".format(e))
self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self):
reactor.stop()

View File

@@ -0,0 +1,17 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################

View File

@@ -24,7 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession
class RpcOptionsBackend(ApplicationSession): class Component(ApplicationSession):
""" """
An application component providing procedures with An application component providing procedures with
different kinds of arguments. different kinds of arguments.
@@ -50,36 +50,3 @@ class RpcOptionsBackend(ApplicationSession):
return val * val return val * val
self.register(square, 'com.myapp.square', RegisterOptions(details_arg = 'details')) self.register(square, 'com.myapp.square', RegisterOptions(details_arg = 'details'))
class RpcOptionsFrontend(ApplicationSession):
"""
An application component calling the different backend procedures.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
def on_event(val):
print("Someone requested to square non-positive: {}".format(val))
yield self.subscribe(on_event, 'com.myapp.square_on_nonpositive')
for val in [2, 0, -2]:
res = yield self.call('com.myapp.square', val, options = CallOptions(discloseMe = True))
print("Squared {} = {}".format(val, res))
self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self):
reactor.stop()

View File

@@ -0,0 +1,56 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.wamp.types import CallOptions, RegisterOptions, PublishOptions
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
An application component calling the different backend procedures.
"""
def onConnect(self):
self.join("realm1")
@inlineCallbacks
def onJoin(self, details):
def on_event(val):
print("Someone requested to square non-positive: {}".format(val))
yield self.subscribe(on_event, 'com.myapp.square_on_nonpositive')
for val in [2, 0, -2]:
res = yield self.call('com.myapp.square', val, options = CallOptions(discloseMe = True))
print("Squared {} = {}".format(val, res))
self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self):
reactor.stop()

View File

@@ -0,0 +1,49 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn.wamp.types import CallOptions, RegisterOptions
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
Application component that produces progressive results.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
@inlineCallbacks
def longop(n, details = None):
if details.progress:
for i in range(n):
details.progress(i)
yield sleep(1)
else:
yield sleep(1 * n)
returnValue(n)
self.register(longop, 'com.myapp.longop', RegisterOptions(details_arg = 'details'))

View File

@@ -25,32 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession
class ProgressiveBackend(ApplicationSession): class Component(ApplicationSession):
"""
Application component that produces progressive results.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
@inlineCallbacks
def longop(n, details = None):
if details.progress:
for i in range(n):
details.progress(i)
yield sleep(1)
else:
yield sleep(1 * n)
returnValue(n)
self.register(longop, 'com.myapp.longop', RegisterOptions(details_arg = 'details'))
class ProgressiveFrontend(ApplicationSession):
""" """
Application component that consumes progressive results. Application component that consumes progressive results.
""" """

View File

@@ -0,0 +1,40 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
import datetime
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
A simple time service application component.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def utcnow():
now = datetime.datetime.utcnow()
return now.strftime("%Y-%m-%dT%H:%M:%SZ")
self.register(utcnow, 'com.timeservice.now')

View File

@@ -25,26 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession
class TimeServiceBackend(ApplicationSession): class Component(ApplicationSession):
"""
A simple time service application component.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def utcnow():
now = datetime.datetime.utcnow()
return now.strftime("%Y-%m-%dT%H:%M:%SZ")
self.register(utcnow, 'com.timeservice.now')
class TimeServiceFrontend(ApplicationSession):
""" """
An application component using the time service. An application component using the time service.
""" """

View File

@@ -0,0 +1,17 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################

View File

@@ -0,0 +1,43 @@
###############################################################################
##
## Copyright (C) 2014 Tavendo GmbH
##
## Licensed 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.
##
###############################################################################
import datetime
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
"""
A simple time service application component.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def utcnow():
now = datetime.datetime.utcnow()
return now.strftime("%Y-%m-%dT%H:%M:%SZ")
self.register(utcnow, 'com.timeservice.now')

View File

@@ -25,26 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession
class SeriesTestBackend(ApplicationSession): class Component(ApplicationSession):
"""
A simple time service application component.
"""
def onConnect(self):
self.join("realm1")
def onJoin(self, details):
def utcnow():
now = datetime.datetime.utcnow()
return now.strftime("%Y-%m-%dT%H:%M:%SZ")
self.register(utcnow, 'com.timeservice.now')
class SeriesTestFrontend(ApplicationSession):
""" """
An application component using the time service An application component using the time service
during 3 subsequent WAMP sessions, while the during 3 subsequent WAMP sessions, while the