Exemple #1
0
        public void RegisterFunction <TArg, TResult>(string functionName, GearmanJobFunction <TArg, TResult> function,
                                                     DataDeserializer <TArg> argumentDeserializer, DataSerializer <TResult> resultSerializer)
            where TArg : class
            where TResult : class
        {
            if (functionName == null)
            {
                throw new ArgumentNullException("functionName");
            }

            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            if (resultSerializer == null)
            {
                throw new ArgumentNullException("resultSerializer");
            }

            if (argumentDeserializer == null)
            {
                throw new ArgumentNullException("argumentDeserializer");
            }

            AddFunction(functionName, function, resultSerializer, argumentDeserializer);

            foreach (var connection in GetAliveConnections())
            {
                RegisterFunction(connection, functionName);
            }
        }
Exemple #2
0
        private void AddFunction <TArg, TResult>(string functionName, GearmanJobFunction <TArg, TResult> function,
                                                 DataSerializer <TResult> resultSerializer, DataDeserializer <TArg> argumentDeserializer)
            where TArg : class
            where TResult : class
        {
            var jobConstructorTypes = new Type[4]
            {
                typeof(GearmanWorkerProtocol),
                typeof(GearmanJobInfo),
                typeof(DataDeserializer <TArg>),
                typeof(DataSerializer <TResult>)
            };

            var jobConstructorInfo = typeof(GearmanJob <TArg, TResult>).GetConstructor(jobConstructorTypes);

            if (jobConstructorInfo == null)
            {
                throw new InvalidOperationException("Failed to locate the constructor for GearmanJob2<T>");
            }

            _functionInformation.Add(functionName, new FunctionInformation
            {
                Function             = function,
                ArgumentType         = typeof(TArg),
                ResultType           = typeof(TResult),
                ArgumentDeserializer = argumentDeserializer,
                ResultSerializer     = resultSerializer,
                JobConstructor       = jobConstructorInfo
            });
        }
Exemple #3
0
 public void RegisterFunction(string functionName, GearmanJobFunction <byte[], byte[]> function)
 {
     RegisterFunction(functionName, function, data => (data), data => (data));
 }