<s> import ufora . native . StringChannel as StringChannelNative <EOL> import ufora . native . SharedState as SharedStateNative <EOL> import threading <EOL> from ufora . distributed . SharedState . Connections . ChannelFactory import ChannelFactory <EOL> class InMemoryChannelFactory ( ChannelFactory ) : <EOL> def __init__ ( self , callbackScheduler , channelManager ) : <EOL> self . callbackScheduler = callbackScheduler <EOL> self . channelManager = channelManager <EOL> self . lock = threading . Lock ( ) <EOL> self . channels = [ ] <EOL> def createChannel ( self , ipEndpoint = None ) : <EOL> assert ipEndpoint is None <EOL> viewChannel , managerChannel = SharedStateNative . InMemoryChannel ( self . callbackScheduler ) <EOL> with self . lock : <EOL> self . channelManager . add ( managerChannel ) <EOL> self . channels . append ( managerChannel ) <EOL> return viewChannel <EOL> def disconnectAllChannels ( self ) : <EOL> with self . lock : <EOL> for c in self . channels : <EOL> c . disconnect ( ) <EOL> self . channels = [ ] <EOL> def teardown ( self ) : <EOL> pass <EOL> class SerializedChannelFactoryBase ( ChannelFactory ) : <EOL> def __init__ ( self , callbackScheduler , channelManager , channelGroup ) : <EOL> self . callbackScheduler = callbackScheduler <EOL> self . channelManager = channelManager <EOL> self . channelGroup = channelGroup <EOL> def createChannel ( self , ipEndpoint = None ) : <EOL> """<STR_LIT>""" <EOL> clientChannel , serverChannel = self . channelType ( self . callbackScheduler ) <EOL> hostId = '<STR_LIT>' <EOL> if ipEndpoint is not None : <EOL> hostId = '<STR_LIT>' % ipEndpoint <EOL> self . channelManager . add ( serverChannel , self . channelGroup , hostId ) <EOL> return clientChannel <EOL> class ViewToSerializedChannelFactory ( SerializedChannelFactoryBase ) : <EOL> def __init__ ( self , callbackScheduler , channelManager , channelGroup ) : <EOL> super ( ViewToSerializedChannelFactory , self ) . __init__ ( callbackScheduler , channelManager , channelGroup ) <EOL> self . channelType = SharedStateNative . ViewToSerializedChannel <EOL> def createChannel ( self , ipEndpoint = None ) : <EOL> clientChannel , serverChannel = self . channelType ( self . callbackScheduler ) <EOL> hostId = '<STR_LIT>' <EOL> if ipEndpoint is not None : <EOL> hostId = '<STR_LIT>' % ipEndpoint <EOL> self . channelManager . add ( serverChannel , self . channelGroup , hostId ) <EOL> return clientChannel <EOL> class SerializedToManagerChannelFactory ( SerializedChannelFactoryBase ) : <EOL> def __init__ ( self , callbackScheduler , channelManager , channelGroup ) : <EOL> super ( SerializedToManagerChannelFactory , self ) . __init__ ( callbackScheduler , channelManager , channelGroup ) <EOL> self . channelType = SharedStateNative . SerializedToManagerChannel <EOL> def createChannel ( self , ipEndpoint = None ) : <EOL> clientChannel , serverChannel = self . channelType ( self . callbackScheduler ) <EOL> self . channelManager . add ( serverChannel ) <EOL> return clientChannel <EOL> class StringChannelFactory ( SerializedChannelFactoryBase ) : <EOL> def __init__ ( self , callbackScheduler , channelManager , channelGroup ) : <EOL> super ( StringChannelFactory , self ) . __init__ ( callbackScheduler , channelManager , channelGroup ) <EOL> self . channelType = StringChannelNative . InMemoryStringChannel </s>
