コード例 #1
0
        public IOWorker(
            IDictionary <string, Channel> channels,
            IDictionary <string, Listener> listeners,
            WaterFlowManager incomingFlowManager,
            Options options,
            IncomingMessageDispatchCallback incomingMessageDispatchCallback,
            ConnectionEventCallback connectionEventCallback,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.channels                        = channels;
            this.listeners                       = listeners;
            this.incomingFlowManager             = incomingFlowManager;
            this.options                         = options;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.connectionEventCallback = connectionEventCallback;
            this.logCallback             = logCallback;
            this.logLevel = logLevel;

            listenersForSelection = new Dictionary <Socket, Listener>();
            channelsForSelection  = new Dictionary <Socket, Channel>();

            blockingChannelsReadyForReading = new List <Channel>();
            blockingChannelsReadyForWriting = new List <Channel>();

            stopRequest = false;
        }
コード例 #2
0
        public DispatchManager(
            object sender, // Agent reference for callbacks
            Options options, WaterFlowManager incomingFlowManager, 
            IOWorker ioWorker, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.sender = sender;
            this.incomingFlowManager = incomingFlowManager;
            this.ioWorker = ioWorker;

            this.logCallback = logCallback;
            this.logLevel = logLevel;

            messageQueue = new LinkedList<IncomingMessage>();

            objectMap = new Dictionary<string, IncomingMessageHandler>();
            anyObjectCallback = null;

            int numOfThreads = options.dispatcherThreads;

            dispatchers = new List<Thread>();
            for (int i = 0; i != numOfThreads; ++i)
            {

                Thread th = new Thread((new Dispatcher(this)).run);
                th.Name = "YAMI4 message dispatcher";
                th.IsBackground = true;
                th.Start();
                dispatchers.Add(th);
            }
        }
コード例 #3
0
        public ChannelReader(
            NetworkUtils.TransportChannel connection, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, 
            string target, Options options, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.target = target;
            this.logCallback = logCallback;
            this.logLevel = logLevel;

            incomingFrames = new Dictionary<int, IncomingMessageFrames>();

            if (connection != null)
            {
                if (connection.connectedChannel != null)
                {
                // stream-based connection
                    headerBuffer = new MemoryStream(Frame.FRAME_HEADER_SIZE);
                    setReadingFrameHeaderState();
                }
                else
                {
                // datagram-based connection
                    wholeFrameBuffer = new byte[options.udpFrameSize];
                    state = InputState.READING_WHOLE_FRAMES;
                }
            }

            deliverAsRawBinary = options.deliverAsRawBinary;
        }
コード例 #4
0
        public ChannelReader(
            NetworkUtils.TransportChannel connection,
            IncomingMessageDispatchCallback incomingMessageDispatchCallback,
            string target, Options options,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.target      = target;
            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            incomingFrames = new Dictionary <int, IncomingMessageFrames>();

            if (connection != null)
            {
                if (connection.connectedChannel != null || connection.ssl != null)
                {
                    // stream-based connection
                    headerBuffer = new MemoryStream(Frame.FRAME_HEADER_SIZE);
                    setReadingFrameHeaderState();
                }
                else
                {
                    // datagram-based connection
                    wholeFrameBuffer = new byte[options.udpFrameSize];
                    state            = InputState.READING_WHOLE_FRAMES;
                }
            }

            deliverAsRawBinary = options.deliverAsRawBinary;
        }
コード例 #5
0
        public DispatchManager(
            object sender, // Agent reference for callbacks
            Options options, WaterFlowManager incomingFlowManager,
            IOWorker ioWorker,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.sender = sender;
            this.incomingFlowManager = incomingFlowManager;
            this.ioWorker            = ioWorker;

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            messageQueue = new LinkedList <IncomingMessage>();

            objectMap         = new Dictionary <string, IncomingMessageHandler>();
            anyObjectCallback = null;

            int numOfThreads = options.dispatcherThreads;

            dispatchers = new List <Thread>();
            for (int i = 0; i != numOfThreads; ++i)
            {
                Thread th = new Thread((new Dispatcher(this)).run);
                th.Name         = "YAMI4 message dispatcher";
                th.IsBackground = true;
                th.Start();
                dispatchers.Add(th);
            }
        }
コード例 #6
0
 // Parameter incomingMessageDispatchCallback not used here
 internal UdpListener(
     Socket channel, string resolvedTarget,
     IncomingMessageDispatchCallback incomingMessageDispatchCallback,
     Options options,
     LogCallback logCallback, LogEventArgs.LogLevel logLevel)
     : base(channel, resolvedTarget, logCallback, logLevel)
 {
     this.channel = channel;
     this.options = options;
 }
コード例 #7
0
ファイル: Listener.cs プロジェクト: morambro/TrainProject
        internal Listener(
            Socket channel, string resolvedTarget, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.channel = channel;
            this.resolvedTarget = resolvedTarget;

            this.logCallback = logCallback;
            this.logLevel = logLevel;
        }
コード例 #8
0
ファイル: Listener.cs プロジェクト: cezary12/kokos
        internal Listener(
            Socket channel, string resolvedTarget,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.channel        = channel;
            this.resolvedTarget = resolvedTarget;

            this.logCallback = logCallback;
            this.logLevel    = logLevel;
        }
コード例 #9
0
        internal ChannelWriter(
            NetworkUtils.TransportChannel connection, string target,
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection  = connection;
            this.target      = target;
            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            outgoingFrames = new List <OutgoingFrame>();
        }
コード例 #10
0
        internal ChannelWriter(
            NetworkUtils.TransportChannel connection, string target, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.connection = connection;
            this.target = target;
            this.logCallback = logCallback;
            this.logLevel = logLevel;

            outgoingFrames = new List<OutgoingFrame>();
        }
コード例 #11
0
        private static TcpListener prepareTcpServer(string target,
                                                    IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                                                    Options options,
                                                    LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            IpComponents tcpComponents = parseTcp(target);

            string hostName = tcpComponents.hostName;
            int    port     = tcpComponents.port;

            Socket s = CreateTCPSocket();

            IPEndPoint address;
            string     boundHostName;

            if (hostName == "*")
            {
                // bind to the wildcard local address
                // and resolve to the local hostname
                address       = new IPEndPoint(IPAddress.Any, port);
                boundHostName = Dns.GetHostName();
            }
            else
            {
                //TODO: translation for empty result (if possible)
                address = new IPEndPoint(
                    Dns.GetHostAddresses(hostName)[0], port);
                boundHostName = hostName;
            }

            s.SetSocketOption(
                SocketOptionLevel.Socket,
                SocketOptionName.ReuseAddress,
                options.tcpReuseAddress ? 1 : 0);
            s.Blocking = false;

            s.Bind(address); // , options.tcpListenBacklog);
            s.Listen(options.tcpListenBacklog);

            // get the actual address of this server socket

            int boundPort = ((IPEndPoint)s.LocalEndPoint).Port;

            string resolvedTarget =
                formatTcpTarget(boundHostName, boundPort);

            return(new TcpListener(s, resolvedTarget,
                                   incomingMessageDispatchCallback, options,
                                   logCallback, logLevel));
        }
コード例 #12
0
ファイル: Channel.cs プロジェクト: morambro/TrainProject
        internal Channel(string target, Options options, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.target = target;
            this.options = options;

            this.logCallback = logCallback;
            this.logLevel = logLevel;

            connect(incomingMessageDispatchCallback);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                    "Connected to " + target);
            }
        }
コード例 #13
0
ファイル: Channel.cs プロジェクト: cezary12/kokos
        internal Channel(string target, Options options,
                         IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                         IOWorker ioWorker,
                         LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.target  = target;
            this.options = options;

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            connect(incomingMessageDispatchCallback, ioWorker);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                                "Connected to " + target);
            }
        }
コード例 #14
0
 internal static Listener prepareServer(string target,
                                        IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                                        Options options,
                                        LogCallback logCallback, LogEventArgs.LogLevel logLevel)
 {
     if (protocolIsTcp(target))
     {
         return(prepareTcpServer(target,
                                 incomingMessageDispatchCallback, options,
                                 logCallback, logLevel));
     }
     else if (protocolIsUdp(target))
     {
         return(prepareUdpServer(target,
                                 incomingMessageDispatchCallback, options,
                                 logCallback, logLevel));
     }
     else
     {
         throw new BadProtocolException(target);
     }
 }
コード例 #15
0
ファイル: Channel.cs プロジェクト: cezary12/kokos
        // used by listener when accepting new connections
        internal Channel(Socket acceptedChannel, string sourceTarget,
                         IncomingMessageDispatchCallback incomingMessageDispatchCallback,
                         Options options, LogCallback logCallback,
                         LogEventArgs.LogLevel logLevel)
        {
            this.target  = sourceTarget;
            this.options = options;

            this.connection =
                new NetworkUtils.TransportChannel(acceptedChannel);

            this.logCallback = logCallback;
            this.logLevel    = logLevel;

            createReaderWriter(incomingMessageDispatchCallback);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                                "Accepted connection from " + target);
            }
        }
コード例 #16
0
ファイル: Channel.cs プロジェクト: morambro/TrainProject
        // used by listener when accepting new connections
        internal Channel(Socket acceptedChannel, string sourceTarget, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback, 
            Options options, LogCallback logCallback, 
            LogEventArgs.LogLevel logLevel)
        {
            this.target = sourceTarget;
            this.options = options;

            this.connection =
                new NetworkUtils.TransportChannel(acceptedChannel);

            this.logCallback = logCallback;
            this.logLevel = logLevel;

            createReaderWriter(incomingMessageDispatchCallback);

            if (logCallback != null)
            {
                logCallback.Log(LogEventArgs.LogLevel.LOW,
                    "Accepted connection from " + target);
            }
        }
コード例 #17
0
ファイル: IOWorker.cs プロジェクト: morambro/TrainProject
        public IOWorker(
            IDictionary<string, Channel> channels, 
            IDictionary<string, Listener> listeners, 
            WaterFlowManager incomingFlowManager, 
            Options options, 
            IncomingMessageDispatchCallback incomingMessageDispatchCallback,
            ConnectionEventCallback connectionEventCallback, 
            LogCallback logCallback, LogEventArgs.LogLevel logLevel)
        {
            this.channels = channels;
            this.listeners = listeners;
            this.incomingFlowManager = incomingFlowManager;
            this.options = options;
            this.incomingMessageDispatchCallback =
                incomingMessageDispatchCallback;
            this.connectionEventCallback = connectionEventCallback;
            this.logCallback = logCallback;
            this.logLevel = logLevel;

            listenersForSelection = new Dictionary<Socket, Listener>();
            channelsForSelection = new Dictionary<Socket, Channel>();

            stopRequest = false;
        }