Пример #1
0
 /// <inheritdoc/>
 public void Execute(RunnableDelegate runnable) {
   ThreadPool.QueueUserWorkItem(new WaitCallback(
     delegate(object obj)
     {
       (obj as RunnableDelegate)();
     }), runnable);
 }
Пример #2
0
 public void postAction(RunnableDelegate action, object param)
 {
     lock (actions)
     {
         actions.Add(new KeyValuePair<RunnableDelegate, object>(action, param));
     }
 }
Пример #3
0
 /// <inheritdoc/>
 public void Execute(RunnableDelegate runnable)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(
                                      delegate(object obj)
     {
         (obj as RunnableDelegate)();
     }), runnable);
 }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Future{T}"/> class that
        /// will, upon running, execute the given <see cref="RunnableDelegate"/>,
        /// and arrange that <see cref="AbstractFuture{T}.Get()"/> will return the
        /// given result on successful completion.
        /// </summary>
        /// <param name="runnable">
        /// The runnable task
        /// </param>
        /// <param name="state">
        /// An object representing data to be used by the future.
        /// </param>
        /// <param name="result">
        /// The result to return on successful completion. If you don't need a
        /// particular result, consider using constructions of the form:
        /// <para>
        /// <code>
        /// Future{T} f = new Future(runnable, null).
        /// </code>
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="runnable"/> is null.
        /// </exception>
        public Future(RunnableDelegate runnable, T result, object state) : this()
        {
            if (runnable == null)
            {
                throw new ArgumentNullException("runnable");
            }

            callable_ = () => {
                runnable();
                return(result);
            };
        }
Пример #5
0
        /// <summary>
        /// Adds the <see cref="EventHandler{TEventArgs}"/> to the list of
        /// listeners to execute. If execution has already begun, the listener is
        /// executed immediately.
        /// </summary>
        /// <param name="runnable"></param>
        /// <param name="executor"></param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="runnable"/> or <paramref name="executor"/> or are
        /// <c>null</c>.
        /// </exception>
        public void Add(RunnableDelegate runnable, IExecutor executor)
        {
            if (runnable == null || executor == null)
            {
                Thrower.ThrowArgumentNullException(
                    (runnable == null)
          ? ExceptionArgument.runnable
              : ExceptionArgument.executor);
            }

            bool execute_immediate = false;

            // Lock while we check state. We must maitain the lock while adding the
            // new pair so that another thread can't run the list out from under us.
            // We only add to the list if we have not yet started execution.
            lock (runnables_) {
                if (!executed_)
                {
                    SerialExecutorDelegatePair pair =
                        new SerialExecutorDelegatePair(runnable, executor);

                    runnables_.Enqueue(pair);
                }
                else
                {
                    execute_immediate = true;
                }
            }

            // Execute the runnable immediately. Because of scheduling this may end
            // up getting called before some of the previously added runnables, but
            // we're OK with that. If we want to change the contract to guarantee
            // ordering among runnables we'd have to modify the logic here to allow
            // it.
            if (execute_immediate)
            {
                new SerialExecutorDelegatePair(runnable, executor).Execute();
            }
        }
Пример #6
0
 public void AddListener(RunnableDelegate listener, IExecutor executor)
 {
     execution_list_.Add(listener, executor);
 }
Пример #7
0
 /// <inheritdoc/>
 public void Execute(RunnableDelegate runnable)
 {
     runnable();
 }
Пример #8
0
 public SerialExecutorDelegatePair(RunnableDelegate runnable,
                                   IExecutor executor)
 {
     runnable_ = runnable;
     executor_ = executor;
 }
Пример #9
0
 void OnSend(RunnableDelegate runnable)
 {
     runnable();
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SerialExecutorState{T}"/>
 /// by using the specified executor delegate and its associated state.
 /// </summary>
 /// <param name="runnable"></param>
 /// <param name="state"></param>
 public SerialExecutorState(RunnableDelegate runnable,
                            ExecutorState <T> state) : base(state)
 {
     runnable_ = runnable;
 }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Future{T}"/> class that
 /// will, upon running, execute the given <see cref="RunnableDelegate"/>,
 /// and arrange that <see cref="AbstractFuture{T}.Get()"/> will return the
 /// given result on successful completion.
 /// </summary>
 /// <param name="runnable">
 /// The runnable task
 /// </param>
 /// <param name="result">
 /// The result to return on successful completion. If you don't need a
 /// particular result, consider using constructions of the form:
 /// <para>
 /// <code>
 /// Future{T} f = new Future(runnable, null).
 /// </code>
 /// </para>
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="runnable"/> is null.
 /// </exception>
 public Future(RunnableDelegate runnable, T result)
     : this(runnable, result, null)
 {
 }
Пример #12
0
    public void requestGame(long gameId, BaseGameController controller, RunnableDelegate callback)
    {
        if (state != SystemControllerStates.Default)
            throw new InvalidOperationException("Invalid SystemController state, waiting Default, but have : " + state);

        if (connection.isConnected()) {
            DataMessage message = new DataMessage(Ids.Services.GAME_RESLOVER, Ids.Actions.GameResolver.START_GAME_REQUEST, userInfo.session);
            message.createWriter();
            message.writerLong(gameId).closeWriter();

            state = SystemControllerStates.RequestGame;
            callbacks[SystemCallbacks.RequestGame] = callback;

            currentGame = controller;

            connection.registerDataListener(Ids.Services.GAME_RESLOVER, Ids.Actions.GameResolver.START_GAME_REQUEST, onGameRequestComplete);
            connection.registerDataListener(Ids.Services.GAME_RESLOVER, Ids.Actions.GameResolver.GAME_STARTED, onGameStarted);
            connection.registerDataListener(Ids.Services.GAME_RESLOVER, Ids.Actions.GameResolver.GAME_FINISHED, onGameFinished);
            connection.addMessageToSend(message);
        } else {
            Handler.getInstance().postAction(callback, RequestGameResults.ConnectionError);
        }
    }
Пример #13
0
    public void registerPlayer(RunnableDelegate callback)
    {
        if (state != SystemControllerStates.Default)
            throw new InvalidOperationException("Invalid SystemController state, waiting Default, but have : " + state);

        if (connection.isConnected())
        {
            DataMessage message = new DataMessage(Ids.Services.CLIENTS, Ids.Actions.Clients.REGISTER_NEW, null);
            JSONObject json = JSONBuilder.create()
               .with("type", Ids.Actions.Authorizations.BY_LOGIN_AND_PASSWORD)
               .with("id", userInfo.userLogin)
               .with("password", userInfo.userPassword).getJson();

            message.createWriter().writeJson(json).closeWriter();

            state = SystemControllerStates.RegisterUser;
            callbacks[SystemCallbacks.Registration] = callback;
            connection.registerDataListener(message, onRegistrationComplete);
            connection.addMessageToSend(message);
        }
        else
        {
            Handler.getInstance().postAction(callback, RegistrationResults.ConnectionError);
        }
    }
Пример #14
0
    /// <summary>
    /// Adds the <see cref="EventHandler{TEventArgs}"/> to the list of
    /// listeners to execute. If execution has already begun, the listener is
    /// executed immediately.
    /// </summary>
    /// <param name="runnable"></param>
    /// <param name="executor"></param>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="runnable"/> or <paramref name="executor"/> or are
    /// <c>null</c>.
    /// </exception>
    public void Add(RunnableDelegate runnable, IExecutor executor) {
      if (runnable == null || executor == null) {
        Thrower.ThrowArgumentNullException(
          (runnable == null)    
          ? ExceptionArgument.runnable
              : ExceptionArgument.executor);
      }

      bool execute_immediate = false;

      // Lock while we check state. We must maitain the lock while adding the
      // new pair so that another thread can't run the list out from under us.
      // We only add to the list if we have not yet started execution.
      lock (runnables_) {
        if (!executed_) {
          SerialExecutorDelegatePair pair =
            new SerialExecutorDelegatePair(runnable, executor);

          runnables_.Enqueue(pair);
        } else {
          execute_immediate = true;
        }
      }

      // Execute the runnable immediately. Because of scheduling this may end
      // up getting called before some of the previously added runnables, but
      // we're OK with that. If we want to change the contract to guarantee
      // ordering among runnables we'd have to modify the logic here to allow
      // it.
      if (execute_immediate) {
        new SerialExecutorDelegatePair(runnable, executor).Execute();
      }
    }
Пример #15
0
 public SerialExecutorDelegatePair(RunnableDelegate runnable,
   IExecutor executor) {
   runnable_ = runnable;
   executor_ = executor;
 }
Пример #16
0
 /// <inheritdoc/>
 public void Execute(RunnableDelegate runnable) {
   runnable();
 }