コード例 #1
0
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="messageClient"></param>
        public void UnregisterMessageClient(IMessageClient messageClient)
        {
            //This operation was possibly initiated by this client
            //if (messageClient.IsDisconnecting)
            //    return;
            if (this.MessageClients != null && this.MessageClients.Contains(messageClient))
            {
                this.MessageClients.Remove(messageClient);
                if (_endpointPushHandlers != null)
                {
                    IEndpointPushHandler handler = _endpointPushHandlers[messageClient.EndpointId] as IEndpointPushHandler;
                    if (handler != null)
                    {
                        handler.UnregisterMessageClient(messageClient);
                    }
                }

                /*
                 * if (this.MessageClients.Count == 0)
                 * {
                 *  Disconnect();
                 * }
                 */
            }
        }
コード例 #2
0
 private void HandleFlexClientStreamingCloseRequest(HttpRequest request, HttpResponse response, IClient flexClient)
 {
     if (flexClient != null)
     {
         if (log.IsDebugEnabled)
         {
             string msg = string.Format("Close streaming for endpoint with id {0} and client with id {1}", this.Id, flexClient.Id);
             log.Debug(msg);
         }
         string streamId = HttpContext.Current.Request.Params[StreamIdParameterName];
         IEndpointPushHandler notifier = flexClient.GetEndpointPushHandler(this.Id);
         if (notifier != null && notifier.Id == streamId)
         {
             notifier.Close();
         }
     }
     else
     {
         if (log.IsDebugEnabled)
         {
             string flexClientId = HttpContext.Current.Request.Params[MessageBase.FlexClientIdHeader];
             string msg          = string.Format("Skip close streaming request for endpoint with id {0} and client with id {1}", this.Id, flexClientId);
             log.Debug(msg);
         }
     }
 }
コード例 #3
0
        public override void Push(IMessage message, MessageClient messageClient)
        {
            if (this.ChannelDefinition.Properties.IsPollingEnabled)
            {
                IEndpointPushHandler handler = messageClient.Client.GetEndpointPushHandler(this.Id);
                if (handler != null)
                {
                    IMessage messageClone = message.Copy() as IMessage;
                    messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
                    messageClone.clientId = messageClient.ClientId;
                    handler.PushMessage(messageClone);
                }

                /*
                 * IMessage messageClone = message.Clone() as IMessage;
                 * messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
                 * messageClone.clientId = messageClient.ClientId;
                 * messageClient.AddMessage(messageClone);
                 */
            }
            else
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("Push request received for the non-polling AMF endpoint '" + this.Id + "'");
                }
            }
        }
コード例 #4
0
ファイル: Client.cs プロジェクト: hakanaku2009/svn-dump
 /// <summary>
 /// Unregisters an IEndpointPushHandler from the specified endpoint.
 /// </summary>
 /// <param name="handler">The IEndpointPushHandler to unregister.</param>
 /// <param name="endpointId">The endpoint identity to unregister from.</param>
 public void UnregisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId)
 {
     lock (this.SyncRoot) {
         if (_endpointPushHandlers == null)
         {
             return;
         }
         if (_endpointPushHandlers[endpointId] == handler)
         {
             _endpointPushHandlers.Remove(endpointId);
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="messageClient"></param>
 public void RegisterMessageClient(IMessageClient messageClient)
 {
     if (!this.GetMessageClients().Contains(messageClient))
     {
         this.GetMessageClients().Add(messageClient);
         if (_endpointPushHandlers != null)
         {
             IEndpointPushHandler handler = GetEndpointPushHandler(messageClient.EndpointId);
             if (handler != null)
             {
                 handler.RegisterMessageClient(messageClient);
             }
         }
     }
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: hakanaku2009/svn-dump
 /// <summary>
 /// Registers an IEndpointPushHandler for the specified endpoint to handle pushing messages.
 /// </summary>
 /// <param name="handler">The IEndpointPushHandler to register.</param>
 /// <param name="endpointId">The endpoint identity to register for.</param>
 public void RegisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId)
 {
     if (_endpointPushHandlers == null)
     {
         lock (this.SyncRoot) {
             if (_endpointPushHandlers == null)
             {
                 _endpointPushHandlers = new CopyOnWriteDictionary(1);
             }
         }
     }
     if (_endpointPushHandlers.ContainsKey(endpointId))
     {
         MessageException me = new MessageException();
         me.FaultCode = EndpointPushHandlerAlreadyRegistered.ToString();
         throw me;
     }
     _endpointPushHandlers.Add(endpointId, handler);
 }
コード例 #7
0
        public override void Push(IMessage message, MessageClient messageClient)
        {
            IEndpointPushHandler handler = messageClient.Client.GetEndpointPushHandler(this.Id);

            if (handler != null)
            {
                IMessage messageClone = message.Copy() as IMessage;
                messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
                messageClone.clientId = messageClient.ClientId;
                handler.PushMessage(messageClone);
            }

            /*
             * IMessage messageClone = message.Clone() as IMessage;
             * messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
             * messageClone.clientId = messageClient.ClientId;
             * messageClient.AddMessage(messageClone);
             */
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: apakian/fluorinefx
 /// <summary>
 /// Unregisters an IEndpointPushHandler from the specified endpoint.
 /// </summary>
 /// <param name="handler">The IEndpointPushHandler to unregister.</param>
 /// <param name="endpointId">The endpoint identity to unregister from.</param>
 public void UnregisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId)
 {
     lock (this.SyncRoot)
     {
         if (_endpointPushHandlers == null)
             return;
         if (_endpointPushHandlers[endpointId] == handler)
             _endpointPushHandlers.Remove(endpointId);
     }
 }
コード例 #9
0
ファイル: Client.cs プロジェクト: apakian/fluorinefx
 /// <summary>
 /// Registers an IEndpointPushHandler for the specified endpoint to handle pushing messages.
 /// </summary>
 /// <param name="handler">The IEndpointPushHandler to register.</param>
 /// <param name="endpointId">The endpoint identity to register for.</param>
 public void RegisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId)
 {
     if (_endpointPushHandlers == null)
     {
         lock (this.SyncRoot)
         {
             if (_endpointPushHandlers == null)
                 _endpointPushHandlers = new CopyOnWriteDictionary(1);
         }
     }
     if (_endpointPushHandlers.ContainsKey(endpointId))
     {
         MessageException me = new MessageException();
         me.FaultCode = EndpointPushHandlerAlreadyRegistered.ToString();
         throw me;
     }
     _endpointPushHandlers.Add(endpointId, handler);
 }
コード例 #10
0
        public override IMessage ServiceMessage(IMessage message)
        {
            if (FluorineContext.Current.Client != null)
            {
                FluorineContext.Current.Client.Renew();
            }

            if (message is CommandMessage)
            {
                CommandMessage commandMessage = message as CommandMessage;
                switch (commandMessage.operation)
                {
                case CommandMessage.PollOperation:
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_HandleMessage, this.Id, message.ToString()));
                    }

                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }

                    //IMessage[] messages = null;
                    IList messages = null;
                    _waitingPollRequests.Increment();
                    int waitIntervalMillis = this.ChannelDefinition.Properties.WaitIntervalMillis != -1 ? this.ChannelDefinition.Properties.WaitIntervalMillis : 60000;        // int.MaxValue;

                    if (commandMessage.HeaderExists(CommandMessage.FluorineSuppressPollWaitHeader))
                    {
                        waitIntervalMillis = 0;
                    }
                    //If async handling was not set long polling is not supported
                    if (!FluorineConfiguration.Instance.FluorineSettings.Runtime.AsyncHandler)
                    {
                        waitIntervalMillis = 0;
                    }
                    if (this.ChannelDefinition.Properties.MaxWaitingPollRequests <= 0 || _waitingPollRequests.Value >= this.ChannelDefinition.Properties.MaxWaitingPollRequests)
                    {
                        waitIntervalMillis = 0;
                    }

                    if (message.destination != null && message.destination != string.Empty)
                    {
                        string             clientId           = commandMessage.clientId as string;
                        MessageDestination messageDestination = this.GetMessageBroker().GetDestination(message.destination) as MessageDestination;
                        MessageClient      client             = messageDestination.SubscriptionManager.GetSubscriber(clientId);
                        client.Renew();
                        //messages = client.GetPendingMessages();
                    }
                    else
                    {
                        //if (FluorineContext.Current.Client != null)
                        //    messages = FluorineContext.Current.Client.GetPendingMessages(waitIntervalMillis);
                    }

                    if (FluorineContext.Current.Client != null)
                    {
                        IEndpointPushHandler handler = FluorineContext.Current.Client.GetEndpointPushHandler(this.Id);
                        if (handler != null)
                        {
                            messages = handler.GetPendingMessages();
                        }
                        if (messages == null)
                        {
                            lock (handler.SyncRoot)
                            {
                                Monitor.Wait(handler.SyncRoot, waitIntervalMillis);
                            }
                            messages = handler.GetPendingMessages();
                        }
                    }

                    _waitingPollRequests.Decrement();
                    IMessage response = null;
                    if (messages == null || messages.Count == 0)
                    {
                        response = new AcknowledgeMessage();
                    }
                    else
                    {
                        CommandMessage resultMessage = new CommandMessage();
                        resultMessage.operation = CommandMessage.ClientSyncOperation;
                        resultMessage.body      = messages;
                        response = resultMessage;
                    }
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_Response, this.Id, response.ToString()));
                    }
                    return(response);
                }

                case CommandMessage.SubscribeOperation:
                {
                    /*
                     * if (FluorineContext.Current.Client == null)
                     *  FluorineContext.Current.SetCurrentClient(this.GetMessageBroker().ClientRegistry.GetClient(message));
                     * RemotingConnection remotingConnection = null;
                     * foreach (IConnection connection in FluorineContext.Current.Client.Connections)
                     * {
                     *  if (connection is RemotingConnection)
                     *  {
                     *      remotingConnection = connection as RemotingConnection;
                     *      break;
                     *  }
                     * }
                     * if (remotingConnection == null)
                     * {
                     *  remotingConnection = new RemotingConnection(this, null, FluorineContext.Current.Client.Id, null);
                     *  FluorineContext.Current.Client.Renew(this.ClientLeaseTime);
                     *  remotingConnection.Initialize(FluorineContext.Current.Client);
                     * }
                     * FluorineWebContext webContext = FluorineContext.Current as FluorineWebContext;
                     * webContext.SetConnection(remotingConnection);
                     */

                    if (this.ChannelDefinition.Properties.IsPollingEnabled)
                    {
                        //Create and forget, client will close the notifier
                        IEndpointPushHandler handler = FluorineContext.Current.Client.GetEndpointPushHandler(this.Id);
                        if (handler == null)
                        {
                            handler = new EndpointPushNotifier(this, FluorineContext.Current.Client);
                        }

                        /*
                         * lock (_endpointPushHandlers.SyncRoot)
                         * {
                         *  _endpointPushHandlers.Add(notifier.Id, notifier);
                         * }
                         */
                    }
                }
                break;

                case CommandMessage.DisconnectOperation:
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_HandleMessage, this.Id, message.ToString()));
                    }

                    if (FluorineContext.Current.Client != null && FluorineContext.Current.Client.IsValid)
                    {
                        IList messageClients = FluorineContext.Current.Client.MessageClients;
                        if (messageClients != null)
                        {
                            foreach (MessageClient messageClient in messageClients)
                            {
                                messageClient.Invalidate();
                            }
                        }
                        FluorineContext.Current.Client.Invalidate();
                    }
                    if (FluorineContext.Current.Session != null)
                    {
                        FluorineContext.Current.Session.Invalidate();
                    }
                    //Disconnect command is received from a client channel.
                    //The response returned by this method is not guaranteed to get to the client, which is free to terminate its physical connection at any point.
                    IMessage response = new AcknowledgeMessage();

                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_Response, this.Id, response.ToString()));
                    }
                    return(response);
                }
                }
            }
            return(base.ServiceMessage(message));
        }