Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# Example Test Restart before call - Does restarting before a call work?
import time
# Trying to restart the node before the call happens, but need to insert artificial delay to make this happen!
print "___NODERESTART___"
time.sleep(4.0)
s = backend.call("restartBeforeC", "Restart before call").wait(str)
print(s) # Expects a str, like "Restart before call works"
# End Example Test Restart before call
# Example Test Restart after reg - Does restarting after a register work
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# Example Test Restart before call - Does restarting before a call work?
@want(str)
def restartBeforeC(s):
print(s) # Expects a str, like "Restart before call"
return "{} works".format(s)
self.register("restartBeforeC", restartBeforeC)
# End Example Test Restart before call
# Example Test Restart after reg - Does restarting after a register work
import time
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
# Example Reg/Call str str - Basic reg expects string, returns string
s = backend.call("regStrStr", "Hello").wait(str)
print s # Expects a str, like "Hello World"
# End Example Reg/Call str str
# Example Reg/Call str int - Basic reg expects string, returns int
i = backend.call("regStrInt", "Hello").wait(int)
print i # Expects an int, like 42
# End Example Reg/Call str int
def main():
args = parse_args()
ws_url = os.environ.get("WS_URL", "ws://localhost:8000/ws")
domain = os.environ.get("DOMAIN", "xs")
if args['--debug']:
riffle.SetLogLevelDebug()
if not args['--quiet']:
print("Node: {}".format(ws_url))
print("Domain: {}".format(domain))
print("---")
riffle.SetFabric(ws_url)
ExisSession(domain, args).join()
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# Example Tour Pub/Sub Lesson 1 - our first basic example
backend.publish("myFirstSub", "Hello")
# End Example Tour Pub/Sub Lesson 1
######################################################################################
# Example Tour Pub/Sub Lesson 2 Works - type enforcement good
backend.publish("iWantStrings", "Hi")
# End Example Tour Pub/Sub Lesson 2 Works
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
# Example Reg/Call str str - Basic reg expects string, returns string
@want(str)
def regStrStr(s):
print(s) # Expects a str, like "Hello"
return "Hello World"
self.register("regStrStr", regStrStr)
# End Example Reg/Call str str
# Example Reg/Call str int - Basic reg expects string, returns int
@want(str)
def regStrInt(s):
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################
# TODO this would be an advanced setup to show how leave would work
class Logger(riffle.Domain):
@want([str])
def pushLogs(self, l):
self.logs.extend(l)
def pullLogs(self):
return self.logs
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# Example Tour Reg/Call Lesson 1 - our first basic example
@want(str)
def myFirstFunc(s):
print(s) # Expects a str, like "Hello"
return "{} World".format(s)
self.register("myFirstFunc", myFirstFunc)
# End Example Tour Reg/Call Lesson 1
######################################################################################
# Example Tour Reg/Call Lesson 2 Works - type enforcement good
# Template Setup
import riffle
from riffle import want
riffle.SetFabricLocal()
riffle.SetLogLevelDebug()
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# Example Tour Pub/Sub Lesson 1 - our first basic example
@want(str)
def myFirstSub(s):
print(s) # Expects a str, like "Hello"
self.subscribe("myFirstSub", myFirstSub)
# End Example Tour Pub/Sub Lesson 1
######################################################################################
# Example Tour Pub/Sub Lesson 2 Works - type enforcement good
@want(str)