diff --git a/examples/twisted/wamp/basic/Makefile b/examples/twisted/wamp/basic/Makefile index e086823e..4e62ec83 100644 --- a/examples/twisted/wamp/basic/Makefile +++ b/examples/twisted/wamp/basic/Makefile @@ -66,110 +66,110 @@ server: 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.TimeServiceFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.timeservice.frontend.Component" 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: - PYTHONPATH=../../../../autobahn python server.py --component "rpc.arguments.ArgumentsBackend" + PYTHONPATH=../../../../autobahn python server.py --component "rpc.arguments.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.ArgumentsBackend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.arguments.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.rpcoptions.RpcOptionsFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.options.frontend.Component" 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: - PYTHONPATH=../../../../autobahn python server.py --component "rpc.errors.ErrorsTestBackend" + PYTHONPATH=../../../../autobahn python server.py --component "rpc.errors.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.ErrorsTestBackend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.errors.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.ComplexFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.complex.frontend.Component" 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: - PYTHONPATH=../../../../autobahn python server.py --component "rpc.progress.ProgressiveBackend" + PYTHONPATH=../../../../autobahn python server.py --component "rpc.progress.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.ProgressiveBackend" + PYTHONPATH=../../../../autobahn python client.py --component "rpc.progress.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsub.PubSubTestFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "pubsub.basic.frontend.Component" 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: - PYTHONPATH=../../../../autobahn python server.py --component "pubsub.complexevent.ComplexEventTestBackend" + PYTHONPATH=../../../../autobahn python server.py --component "pubsub.complex.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complexevent.ComplexEventTestBackend" + PYTHONPATH=../../../../autobahn python client.py --component "pubsub.complex.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "pubsub.pubsuboptions.PubSubOptionsTestFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "pubsub.options.frontend.Component" 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: - PYTHONPATH=../../../../autobahn python server.py --component "pubsub.unsubscribe.UnsubscribeTestBackend" + PYTHONPATH=../../../../autobahn python server.py --component "pubsub.unsubscribe.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.UnsubscribeTestBackend" + PYTHONPATH=../../../../autobahn python client.py --component "pubsub.unsubscribe.backend.Component" 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: - PYTHONPATH=../../../../autobahn python client.py --component "session.series.SeriesTestFrontend" + PYTHONPATH=../../../../autobahn python client.py --component "session.series.frontend.Component" client_session_series_backend: - PYTHONPATH=../../../../autobahn python client.py --component "session.series.SeriesTestBackend" + PYTHONPATH=../../../../autobahn python client.py --component "session.series.backend.Component" diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/__init__.py b/examples/twisted/wamp/basic/pubsub/basic/__init__.py similarity index 100% rename from examples/twisted/wamp/basic/rpc/rpcoptions/__init__.py rename to examples/twisted/wamp/basic/pubsub/basic/__init__.py diff --git a/examples/twisted/wamp/basic/pubsub/basic/backend.py b/examples/twisted/wamp/basic/pubsub/basic/backend.py new file mode 100644 index 00000000..d2153005 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/basic/backend.py @@ -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) diff --git a/examples/twisted/wamp/basic/pubsub/pubsub.py b/examples/twisted/wamp/basic/pubsub/basic/frontend.py similarity index 78% rename from examples/twisted/wamp/basic/pubsub/pubsub.py rename to examples/twisted/wamp/basic/pubsub/basic/frontend.py index 209dfb4e..aef82e80 100644 --- a/examples/twisted/wamp/basic/pubsub/pubsub.py +++ b/examples/twisted/wamp/basic/pubsub/basic/frontend.py @@ -24,26 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession -class PubSubTestBackend(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): +class Component(ApplicationSession): """ An application component that subscribes and receives events, and stop after having received 5 events. diff --git a/examples/twisted/wamp/basic/pubsub/complex/__init__.py b/examples/twisted/wamp/basic/pubsub/complex/__init__.py new file mode 100644 index 00000000..7a5ffd2f --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/__init__.py @@ -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. +## +############################################################################### diff --git a/examples/twisted/wamp/basic/pubsub/complex/backend.py b/examples/twisted/wamp/basic/pubsub/complex/backend.py new file mode 100644 index 00000000..c50a8138 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/backend.py @@ -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) diff --git a/examples/twisted/wamp/basic/pubsub/complexevent.py b/examples/twisted/wamp/basic/pubsub/complex/frontend.py similarity index 75% rename from examples/twisted/wamp/basic/pubsub/complexevent.py rename to examples/twisted/wamp/basic/pubsub/complex/frontend.py index f139b9c8..f42e769d 100644 --- a/examples/twisted/wamp/basic/pubsub/complexevent.py +++ b/examples/twisted/wamp/basic/pubsub/complex/frontend.py @@ -27,32 +27,7 @@ from autobahn.twisted.wamp import ApplicationSession -class ComplexEventTestBackend(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): +class Component(ApplicationSession): """ An application component that subscribes and receives events of no payload and of complex payload, and stops after 5 seconds. diff --git a/examples/twisted/wamp/basic/pubsub/options/__init__.py b/examples/twisted/wamp/basic/pubsub/options/__init__.py new file mode 100644 index 00000000..7a5ffd2f --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/__init__.py @@ -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. +## +############################################################################### diff --git a/examples/twisted/wamp/basic/pubsub/options/backend.py b/examples/twisted/wamp/basic/pubsub/options/backend.py new file mode 100644 index 00000000..db3b2747 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/backend.py @@ -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) diff --git a/examples/twisted/wamp/basic/pubsub/pubsuboptions.py b/examples/twisted/wamp/basic/pubsub/options/frontend.py similarity index 74% rename from examples/twisted/wamp/basic/pubsub/pubsuboptions.py rename to examples/twisted/wamp/basic/pubsub/options/frontend.py index 412b4a2f..be6ab1f3 100644 --- a/examples/twisted/wamp/basic/pubsub/pubsuboptions.py +++ b/examples/twisted/wamp/basic/pubsub/options/frontend.py @@ -25,28 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession -class PubSubOptionsTestBackend(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): +class Component(ApplicationSession): """ An application component that subscribes and receives events, and stop after having received 5 events. diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/__init__.py b/examples/twisted/wamp/basic/pubsub/unsubscribe/__init__.py new file mode 100644 index 00000000..7a5ffd2f --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/__init__.py @@ -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. +## +############################################################################### diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py new file mode 100644 index 00000000..df395adc --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py @@ -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) diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe.py b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py similarity index 82% rename from examples/twisted/wamp/basic/pubsub/unsubscribe.py rename to examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py index 65f09133..8b637eae 100644 --- a/examples/twisted/wamp/basic/pubsub/unsubscribe.py +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py @@ -24,27 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession -class UnsubscribeTestBackend(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): +class Component(ApplicationSession): """ An application component that subscribes and receives events. After receiving 5 events, it unsubscribes, sleeps and then diff --git a/examples/twisted/wamp/basic/rpc/arguments/backend.py b/examples/twisted/wamp/basic/rpc/arguments/backend.py new file mode 100644 index 00000000..ef5142d2 --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/arguments/backend.py @@ -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') diff --git a/examples/twisted/wamp/basic/rpc/arguments/arguments.py b/examples/twisted/wamp/basic/rpc/arguments/frontend.py similarity index 74% rename from examples/twisted/wamp/basic/rpc/arguments/arguments.py rename to examples/twisted/wamp/basic/rpc/arguments/frontend.py index 7f706573..9d58485f 100644 --- a/examples/twisted/wamp/basic/rpc/arguments/arguments.py +++ b/examples/twisted/wamp/basic/rpc/arguments/frontend.py @@ -23,42 +23,7 @@ from autobahn.twisted.wamp import ApplicationSession -class ArgumentsBackend(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): +class Component(ApplicationSession): """ An application component calling the different backend procedures. """ diff --git a/examples/twisted/wamp/basic/rpc/complex/backend.py b/examples/twisted/wamp/basic/rpc/complex/backend.py new file mode 100644 index 00000000..71ea4e4b --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/complex/backend.py @@ -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') diff --git a/examples/twisted/wamp/basic/rpc/complex/complex.py b/examples/twisted/wamp/basic/rpc/complex/frontend.py similarity index 72% rename from examples/twisted/wamp/basic/rpc/complex/complex.py rename to examples/twisted/wamp/basic/rpc/complex/frontend.py index 42896411..363d0e2a 100644 --- a/examples/twisted/wamp/basic/rpc/complex/complex.py +++ b/examples/twisted/wamp/basic/rpc/complex/frontend.py @@ -24,32 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession -class ComplexBackend(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): +class Component(ApplicationSession): """ Application component that calls procedures which produce complex results and showing how to access those. diff --git a/examples/twisted/wamp/basic/rpc/errors/errors.py b/examples/twisted/wamp/basic/rpc/errors/backend.py similarity index 65% rename from examples/twisted/wamp/basic/rpc/errors/errors.py rename to examples/twisted/wamp/basic/rpc/errors/backend.py index 1528fe49..66db6d07 100644 --- a/examples/twisted/wamp/basic/rpc/errors/errors.py +++ b/examples/twisted/wamp/basic/rpc/errors/backend.py @@ -36,7 +36,7 @@ class AppError1(Exception): -class ErrorsTestBackend(ApplicationSession): +class Component(ApplicationSession): """ Example WAMP application backend that raised exceptions. """ @@ -85,59 +85,3 @@ class ErrorsTestBackend(ApplicationSession): raise AppError1(b - a) 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() diff --git a/examples/twisted/wamp/basic/rpc/errors/frontend.py b/examples/twisted/wamp/basic/rpc/errors/frontend.py new file mode 100644 index 00000000..bf6af02f --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/errors/frontend.py @@ -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() diff --git a/examples/twisted/wamp/basic/rpc/options/__init__.py b/examples/twisted/wamp/basic/rpc/options/__init__.py new file mode 100644 index 00000000..7a5ffd2f --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/options/__init__.py @@ -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. +## +############################################################################### diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/backend.html b/examples/twisted/wamp/basic/rpc/options/backend.html similarity index 100% rename from examples/twisted/wamp/basic/rpc/rpcoptions/backend.html rename to examples/twisted/wamp/basic/rpc/options/backend.html diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/backend.js b/examples/twisted/wamp/basic/rpc/options/backend.js similarity index 100% rename from examples/twisted/wamp/basic/rpc/rpcoptions/backend.js rename to examples/twisted/wamp/basic/rpc/options/backend.js diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/rpcoptions.py b/examples/twisted/wamp/basic/rpc/options/backend.py similarity index 69% rename from examples/twisted/wamp/basic/rpc/rpcoptions/rpcoptions.py rename to examples/twisted/wamp/basic/rpc/options/backend.py index e558643f..7965fd02 100644 --- a/examples/twisted/wamp/basic/rpc/rpcoptions/rpcoptions.py +++ b/examples/twisted/wamp/basic/rpc/options/backend.py @@ -24,7 +24,7 @@ from autobahn.twisted.wamp import ApplicationSession -class RpcOptionsBackend(ApplicationSession): +class Component(ApplicationSession): """ An application component providing procedures with different kinds of arguments. @@ -50,36 +50,3 @@ class RpcOptionsBackend(ApplicationSession): return val * val 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() diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/frontend.html b/examples/twisted/wamp/basic/rpc/options/frontend.html similarity index 100% rename from examples/twisted/wamp/basic/rpc/rpcoptions/frontend.html rename to examples/twisted/wamp/basic/rpc/options/frontend.html diff --git a/examples/twisted/wamp/basic/rpc/rpcoptions/frontend.js b/examples/twisted/wamp/basic/rpc/options/frontend.js similarity index 100% rename from examples/twisted/wamp/basic/rpc/rpcoptions/frontend.js rename to examples/twisted/wamp/basic/rpc/options/frontend.js diff --git a/examples/twisted/wamp/basic/rpc/options/frontend.py b/examples/twisted/wamp/basic/rpc/options/frontend.py new file mode 100644 index 00000000..65381954 --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/options/frontend.py @@ -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() diff --git a/examples/twisted/wamp/basic/rpc/progress/backend.py b/examples/twisted/wamp/basic/rpc/progress/backend.py new file mode 100644 index 00000000..77713068 --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/progress/backend.py @@ -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')) diff --git a/examples/twisted/wamp/basic/rpc/progress/progress.py b/examples/twisted/wamp/basic/rpc/progress/frontend.py similarity index 71% rename from examples/twisted/wamp/basic/rpc/progress/progress.py rename to examples/twisted/wamp/basic/rpc/progress/frontend.py index af5a9952..e295ad95 100644 --- a/examples/twisted/wamp/basic/rpc/progress/progress.py +++ b/examples/twisted/wamp/basic/rpc/progress/frontend.py @@ -25,32 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession -class ProgressiveBackend(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): +class Component(ApplicationSession): """ Application component that consumes progressive results. """ diff --git a/examples/twisted/wamp/basic/rpc/timeservice/backend.py b/examples/twisted/wamp/basic/rpc/timeservice/backend.py new file mode 100644 index 00000000..0ac113e8 --- /dev/null +++ b/examples/twisted/wamp/basic/rpc/timeservice/backend.py @@ -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') diff --git a/examples/twisted/wamp/basic/rpc/timeservice/timeservice.py b/examples/twisted/wamp/basic/rpc/timeservice/frontend.py similarity index 77% rename from examples/twisted/wamp/basic/rpc/timeservice/timeservice.py rename to examples/twisted/wamp/basic/rpc/timeservice/frontend.py index 71fa7c89..0ed28b0c 100644 --- a/examples/twisted/wamp/basic/rpc/timeservice/timeservice.py +++ b/examples/twisted/wamp/basic/rpc/timeservice/frontend.py @@ -25,26 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession -class TimeServiceBackend(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): +class Component(ApplicationSession): """ An application component using the time service. """ diff --git a/examples/twisted/wamp/basic/session/series/__init__.py b/examples/twisted/wamp/basic/session/series/__init__.py new file mode 100644 index 00000000..7a5ffd2f --- /dev/null +++ b/examples/twisted/wamp/basic/session/series/__init__.py @@ -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. +## +############################################################################### diff --git a/examples/twisted/wamp/basic/session/series/backend.py b/examples/twisted/wamp/basic/session/series/backend.py new file mode 100644 index 00000000..e060c284 --- /dev/null +++ b/examples/twisted/wamp/basic/session/series/backend.py @@ -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') diff --git a/examples/twisted/wamp/basic/session/series.py b/examples/twisted/wamp/basic/session/series/frontend.py similarity index 82% rename from examples/twisted/wamp/basic/session/series.py rename to examples/twisted/wamp/basic/session/series/frontend.py index 354927e1..a42bd3b5 100644 --- a/examples/twisted/wamp/basic/session/series.py +++ b/examples/twisted/wamp/basic/session/series/frontend.py @@ -25,26 +25,7 @@ from autobahn.twisted.wamp import ApplicationSession -class SeriesTestBackend(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): +class Component(ApplicationSession): """ An application component using the time service during 3 subsequent WAMP sessions, while the