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
import time
time.sleep(2.0)
class GenericDomain(riffle.Domain):
def onJoin(self):
# End Template Setup
######################################################################################
# E-ample Test Reg/Call Big Ints - should be big
i = backend.call("sendBigInt", 9223372036854775807).wait(int)
print("{:d}".format(int(i))) # Expects a str, like "9223372036854775807"
# End E-ample Test Reg/Call Big Ints
print "___SETUPCOMPLETE___"
# Template Setup
app = riffle.Domain("xs.demo.test") # ARBITER $DOMAIN replaces "xs.demo.test"
client = riffle.Domain("client", superdomain=app)
backend = riffle.Domain("backend", superdomain=app)
GenericDomain("client", superdomain=app).join() # ARBITER $SUBDOMAIN replaces "client"
# End Template Setup
######################################################################################
# E-ample Test Reg/Call Big Ints - should be big
@want(int)
def sendBigInt(i):
print("{:d}".format(int(i))) # Expects a str, like "9223372036854775807"
return i
self.register("sendBigInt", sendBigInt)
# End E-ample Test Reg/Call Big Ints
print "___SETUPCOMPLETE___"
# Template Setup
app = riffle.Domain("xs.demo.test")
client = riffle.Domain("client", superdomain=app)
backend = riffle.Domain("backend", superdomain=app)
GenericDomain("backend", superdomain=app).join()
# End Template Setup
# Example Pub/Sub Basic - This is a basic pub/sub
backend.publish("basicSub", "Hello")
# End Example Pub/Sub Basic
# Example Pub/Sub Objects - This tests sending an object using pub/sub
class Stuff(riffle.ModelObject):
name = "This guy"
s = Stuff()
backend.publish("objectSub", s)
# End Example Pub/Sub Objects
# self.leave()
app = riffle.Domain("xs.demo.test")
if __name__ == '__main__':
Send("example", superdomain=app).join()
exit()
# 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
# Example Reg/Call int str - Basic reg expects int, returns str
s = backend.call("regIntStr", 42).wait(str)
print s # Expects a str, like "Hello World"
# End Example Reg/Call int str
print "___SETUPCOMPLETE___"
# Template Setup
app = riffle.Domain("xs.demo.test") # ARBITER $DOMAIN replaces "xs.demo.test"
client = riffle.Domain("client", superdomain=app)
backend = riffle.Domain("backend", superdomain=app)
GenericDomain("client", superdomain=app).join() # ARBITER $SUBDOMAIN replaces "client"
# End Template Setup
# 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
# Example Tour Pub/Sub Lesson 2 Fails - type enforcement bad
backend.publish("iWantInts", "Hi")
# End Example Tour Pub/Sub Lesson 2 Fails
print "___SETUPCOMPLETE___"
# Template Setup
app = riffle.Domain("xs.demo.test") # ARBITER $DOMAIN replaces "xs.demo.test"
client = riffle.Domain("client", superdomain=app)
backend = riffle.Domain("backend", superdomain=app)
GenericDomain("client", superdomain=app).join() # ARBITER $SUBDOMAIN replaces "client"
# End Template Setup
# Example Reg/Call int str - Basic reg expects int, returns str
@want(int)
def regIntStr(i):
print(i) # Expects an int, like 42
return "Hello World"
self.register("regIntStr", regIntStr)
# End Example Reg/Call int str
print "___SETUPCOMPLETE___"
# Template Setup
app = riffle.Domain("xs.demo.test")
client = riffle.Domain("client", superdomain=app)
backend = riffle.Domain("backend", superdomain=app)
GenericDomain("backend", superdomain=app).join()
# End Template Setup
@want(str)
def subscription(self, name):
print "1: expecting 1\t", name
@want(User)
def model(self, other):
print "Received a publish from", other
other.sayHello()
# Not putting a want allows everything
def none(self, name):
print name + " called me"
if __name__ == '__main__':
app = riffle.Domain("xs.damouse")
alpha = riffle.Domain("alpha", superdomain=app)
Receiver("beta", superdomain=app).join()
# 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):
print(s) # Expects a str, like "Hello"
return 42